2012-04-16 101 views
1

帮助,任何人都可以帮助我如何使用greasemonkey更改JavaScript变量?修改JavaScript变量使用Greasemonkey

我已经关注这个问题的答案: How can I change a JavaScript variable using Greasemonkey?

而且此链接: http://webdeveloper.com/forum/showthread.php?t=166658

,但我不能与此脚本修改的功能计数器变量值

// ==UserScript== 
// @name  My Fancy New Userscript 
// @namespace http://use.i.E.your.homepage/ 
// @version 0.1 
// @description enter something useful 
// @match  https://welcome.telkomhotspot.info/telkomhs/freemax/ 
// @copyright 2012+, You 
// ==/UserScript== 

unsafeWindow.counter = 1; 

这里是我想改变功能:

function startTimer(){ 
var counter = 20; 
var wait = 0; 
var displayCounter = true; 
var startCounting = false; 
$("#timerTransition").html(getLoadingCounter()) 
.everyTime(1000,function(i){ 
    if(wait==0){ 
     if(displayCounter){ 
      $("#loadingCounter").fadeOut(500,function(){ 
       $("#timerTransition").html(getTimerContainer(counter)); 
       $("#timerContainer").fadeIn(500,function(){ 
        startCounting = true; 
       }); 
      }); 
     } 
     displayCounter = false; 
     if(startCounting){ 
      counter = counter - 1; 
      $("#counter").html(counter); 
      if(counter == 0) { 

       if(foundCookies){ 
        $("#timerTransition").stopTime().html(getAuthCookiesLogin()); 
       } 
       else{ 
        $("#timerTransition").stopTime().html(getAuthButton()); 
        $("#authBtnContainer").fadeIn(0).click(function(){ 
         $(this).fadeOut(0); 
         closeAds(); 
         openAuthForm(); 
        }); 
       } 
      } 
     } 
    } 
    else{ 
     wait = wait-1; 
    } 
}); 
} 

感谢您的帮助,我已经在谷歌搜索,但仍然无法修改变量。

+1

如果您定义'unsafeWindow.counter',您还应该阅读'unsafeWindow.counter',以便在每个地方都用'unsafeWindow.counter'替换'counter'。 – noob 2012-04-16 14:30:03

+0

你是不是要用'unsafeWindow.counter'替换所有'counter'?但是我没有访问该文件的权限。我想使用Greasemonkey在'counter = 20;''counter = 1;'在某个网站上修改计数器变量**值**,所以我可以更快地跳过**计时器**。你能告诉我如何? – yudayyy 2012-04-16 15:13:39

回答

1

counter是函数内的局部变量。除非您可以修改函数以使用全局变量,否则您将无法更改其值。如果您无法访问代码,则可以尝试用您自己的实现替换整个startTimer函数。我不能从你的例子中看出来,但是如果它是全局的,你只能替换startTimer。

+0

谢谢@mikerobi,我试图用本新网站上的新简单脚本替换函数:[链接](http://www.squakmt.com/replacing_javascript/index.htm)。但是'idconnect.js'文件上的'startTimer'函数仍然被页面调用。 嗯,我必须说我还是Greasemonkey的新手。 – yudayyy 2012-04-16 16:04:49

+0

@yudayyy,我忘了提及,如果它是全局的,那么您只能替换startTimer。 – mikerobi 2012-04-16 17:56:50

+0

所以,这意味着我不能重写'idconnect.js'右边的功能? – yudayyy 2012-04-16 19:32:26