作者shyangs (欲翔)
看板Browsers
標題Re: [-Fx-] 利用GreaseMonkey把js的某個函數override
時間Fri Jun 19 11:26:37 2009
※ 引述《tttp (版主對不起<(_ _)>)》之銘言:
: 比如有一段js,其中一個函數名稱為
: yesher(){
: }
: 聽說可以利用GM把函數override,要如何操作呢@_@
: 謝謝了 <(_ _)>
直接用例子說明
假設有一個簡單的頁面如下
<html><body>
<input id="button" type="button" value="按鈕" onclick="yesher()"/>
<script type="text/javascript">
<!--
function yesher()
{
alert("Hello, World!");
}
//--></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.頁面函數 = 新函數 ;
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.122.206.87
※ 編輯: shyangs 來自: 140.122.206.87 (06/19 11:28)
※ 編輯: shyangs 來自: 140.122.206.87 (06/19 11:29)
推 bobchao:推一下,簡明的教學 06/19 12:11
推 tttp:推推推^^ 06/19 19:55
推 tttp:原po大好人!! 技術也很強大^^ 06/19 21:49