3

Greasemonkeyに問題があり、スクリプトが自動的に更新されません(おそらく、UserScriptsルートにスクリプトを追加したくないため、この場合は更新されないようです)...

とにかく、私はスクリプトにコード(ここからの主なアイデア)を追加して、スクリプト内のスクリプトバージョンを確認し、新しいバージョンが利用可能かどうかをユーザーに知らせ、ユーザーがそれを更新したい場合はそれを更新したいと思っていました。スクリプトURLの新しいウィンドウ/タブを開く必要があります(Greasemonkeyをトリガーしてインストールする必要があります)...これは私のシナリオであり、新しいウィンドウ/タブを開く必要があるまでは完全に機能します...

ここで私が使用している関数を見ることができます:

function checkForUpdate(in_vid){

    var plugin_url = 'https://MyWebSiteURL/MonaTest.user.js?'+new Date().getTime();

    if ((parseInt(GM_getValue('SUC_last_update', '0')) + 86400000 <= (new Date().getTime()))){
        try {
            GM_xmlhttpRequest( {
                method: 'GET',
                url: plugin_url,
                headers: {'Cache-Control': 'no-cache'},
                onload: function(resp){
                    var local_version, remote_version, rt, script_name;

                    rt=resp.responseText;
                    GM_setValue('SUC_last_update', new Date().getTime()+'');
                    remote_version = parseFloat(/@version\s*(.*?)\s*$/m.exec(rt)[1]);
                    local_version = parseFloat(GM_getValue('SUC_current_version', '-1'));

                    if(local_version!=-1){
                        script_name = (/@name\s*(.*?)\s*$/m.exec(rt))[1];
                        GM_setValue('SUC_target_script_name', script_name);

                        if (remote_version > local_version){

                            if(confirm('There is an update available for the Greasemonkey script "'+script_name+'."\nWould you like to install it now?')){
                    ------->    GM_openInTab(plugin_url);
                                //window.open(plugin_url,'_blank')
                                //location.assign(plugin_url);
                                GM_setValue('SUC_current_version', remote_version);
                            }
                        }
                        else{
                            GM_log('No update is available for "'+script_name+'"');
                        }
                    }
                    else{
                        GM_setValue('SUC_current_version', remote_version+'');
                    }
                }
            });
        }
        catch (err){
            GM_log('An error occurred while checking for updates:\n'+err);
        }
    }
}

GM_openInTabを使用しようとしましたが、コンソールに次のエラーが返されます。

Timestamp: 9/27/12 9:55:33 AM
Error: ReferenceError: GM_openInTab is not defined
Source File: file:///Users/Mona/Library/Application%20Support/Firefox/Profiles/tonwb5lg.default/gm_scripts/MonaTest/MonaTest.user.js
Line: 97

GM_openInTabがサポートされなくなったことを示す参照が見つかりませんでした。

window.openとlocation.assignを使用して他の解決策を試しました...Greasemonkeyをトリガーせずにスクリプトのソースコードを表示するため、どちらも機能しません...

この方法を使用してスクリプトを更新する方法があるかどうかはわかりません...知識を共有して私の問題を解決していただければ幸いです。

御時間ありがとうございます!

PS私のFirefoxのバージョンは15.0.1、Greasemonkeyのバージョンは1.1です

4

1 に答える 1

1

することを忘れないでください@grant


私が間違っている場合は私を訂正してください、しかしあなたのスクリプトはjsで終わっていません。

var plugin_url = 'https://MyWebSiteURL/MonaTest.user.js?'+new Date().getTime();

.js拡張子を強制してみてください。
スクリプトに日付を追加すると、GMはそのインストールを停止しました。
最後の日付を削除して、試してみてください。

最後にもう1つ、スクリプトは2009年のスクリプトに基づいています。2011年のこのような新しいスクリプトを見てください。

于 2012-09-27T18:04:19.440 に答える