舊文件

此處文件僅供參考,請自行考量時效性與適用程度,其他庫藏文件請參考文件頁面
我們亟需您的協助,進行共筆系統搬移、及文件整理工作,詳情請查閱參與我們

使用者:Shyangs/Greasemonkey

出自 MozTW Wiki

< 使用者:Shyangs
於 2009年10月22日 (四) 23:39 由 Shyangs對話 | 貢獻 所做的修訂 GM_xmlhttpRequest
(比較) ←上一修訂 | 查看目前修訂 (比較) | 下一修訂→ (比較)

介紹

API

GM_xmlhttpRequest

GM_xmlhttpRequest(
{
    method: "GET",
    url: "http://shyangs.free.mingyao.net/GM_xmlhttpRequest.txt",
    onload: function(responseDetails) 
    {
        alert(responseDetails.responseText);
    }
});

實例

Override Function

※ 引述《tttp (版主對不起<(_ _)>)》之銘言:
: 比如有一段js,其中一個函數名稱為
: yesher(){
: }
: 聽說可以利用GM把函數override,要如何操作呢@_@
: 謝謝了 <(_ _)>

直接用例子說明

假設有一個簡單的頁面如下

<html><body>
<input id="button" type="button" value="按鈕" onclick="yesher()"/>
<script type="text/javascript"></script>
</body></html>

頁面上有一個按鈕,按下去會彈出一個訊息"Hollow, World!"

我們想讓他跳出不同訊息;目標:覆蓋函數yesher

可以寫一個簡單的腳本

// ==UserScript==
// @author         shyangs
// @namespace      http://wiki.moztw.org/index.php/user:Shyangs
// @description    覆蓋頁面函數yesher
// @include        *
// ==/UserScript==
unsafeWindow.yesher= function() {
       alert("火狐你好");
};


重新整理後,再按一下按鈕就會跳出"火狐你好"


這裡用到一個API : unsafeWindow

用法:

    unsafeWindow.頁面變數 = 新值 ;

    unsafeWindow.頁面函數 = 新函數 ;

網路資料

個人工具