1

ヘルプ、誰もがグリースモンキーを使用してjavascript変数を変更する方法を教えてもらえますか?

私はすでにこの質問の答えに従っています: Greasemonkeyを使用してJavaScript変数を変更するにはどうすればよいですか?

また、このリンク: 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;
    }
});
}

助けてくれてありがとう、私はすでにグーグルで検索していますが、それでも変数を変更することはできません。

4

1 に答える 1

1

counter関数内のローカル変数です。グローバル変数を使用するように関数を変更できない限り、その値を変更することはできません。コードにアクセスできない場合は、startTimer関数全体を独自の実装に置き換えてみてください。あなたの例からはわかりませんが、startTimerを置き換えることができるのはグローバルの場合のみです。

于 2012-04-16T15:21:11.583 に答える