「使用者:Shyangs/Greasemonkey」修訂間的差異
出自 MozTW Wiki
(→GM_xmlhttpRequest) |
|||
| 行 1: | 行 1: | ||
==介紹== | ==介紹== | ||
*[http://zh.wikipedia.org/wiki/GreaseMonkey GreaseMonkey - 維基百科] | *[http://zh.wikipedia.org/wiki/GreaseMonkey GreaseMonkey - 維基百科] | ||
| + | ==API== | ||
| + | ===GM_xmlhttpRequest=== | ||
| + | GM_xmlhttpRequest( | ||
| + | { | ||
| + | method: "GET", | ||
| + | url: "http://shyangs.free.mingyao.net/GM_xmlhttpRequest.txt", | ||
| + | onload: function(responseDetails) | ||
| + | { | ||
| + | alert(responseDetails.responseText); | ||
| + | } | ||
| + | }); | ||
| + | |||
==實例== | ==實例== | ||
===Override Function=== | ===Override Function=== | ||
於 2009年10月22日 (四) 23:39 的最新修訂
介紹
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.頁面函數 = 新函數 ;
