Re: [-Fx-] 利用GreaseMonkey把js的某個函數override

看板Browsers (瀏覽器)作者 (欲翔)時間17年前 (2009/06/19 11:26), 編輯推噓3(300)
留言3則, 2人參與, 最新討論串3/3 (看更多)
※ 引述《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)

06/19 12:11, , 1F
推一下,簡明的教學
06/19 12:11, 1F

06/19 19:55, , 2F
推推推^^
06/19 19:55, 2F

06/19 21:49, , 3F
原po大好人!! 技術也很強大^^
06/19 21:49, 3F
文章代碼(AID): #1AEmLm3l (Browsers)
文章代碼(AID): #1AEmLm3l (Browsers)