Javascript 如何在greasemonkey中更新用户脚本

Javascript 如何在greasemonkey中更新用户脚本,javascript,firefox,greasemonkey,Javascript,Firefox,Greasemonkey,我对Greasemonkey有一个问题,它不会自动更新我的脚本(可能是因为我们不想将它添加到它的UserScripts根目录,在本例中它似乎不会更新它) 无论如何,我在我的脚本中添加了一段代码(主要思想来自)来检查脚本中的脚本版本,并让用户知道是否有新版本可用,并且好像用户想要更新它一样,如果有,它应该为脚本url打开一个新窗口/选项卡(它应该触发Greasemonkey来安装它)。。。这是我的senario,它工作得非常完美,可以打开一个新窗口/选项卡 在这里,您可以看到我正在使用的函数: f

我对Greasemonkey有一个问题,它不会自动更新我的脚本(可能是因为我们不想将它添加到它的UserScripts根目录,在本例中它似乎不会更新它)

无论如何,我在我的脚本中添加了一段代码(主要思想来自)来检查脚本中的脚本版本,并让用户知道是否有新版本可用,并且好像用户想要更新它一样,如果有,它应该为脚本url打开一个新窗口/选项卡(它应该触发Greasemonkey来安装它)。。。这是我的senario,它工作得非常完美,可以打开一个新窗口/选项卡

在这里,您可以看到我正在使用的函数:

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不再支持的参考资料

我尝试了其他解决方案,使用window.open和location.assign。。。它们都不工作,因为它们显示了脚本源代码,而没有触发Greasemonkey来安装它

我不知道是否有办法使用此方法更新脚本。。。 如果您能分享您的知识并帮助我解决问题,我将不胜感激

谢谢你的时间


另外,我的firefox版本是15.0.1,Greasemonkey版本是1.1

别忘了
@grant


如果我错了,请纠正我,但您的脚本不会以js结尾

var插件https://MyWebSiteURL/MonaTest.user.js?“+新日期().getTime()

尝试强制使用.js扩展名。
当我将日期添加到脚本中时,GM停止安装它。
删除结尾处的日期并尝试一下


最后一件事:您的脚本基于2009年的脚本。看看新的,比如2011年的。

@RASG:oops!你是对的!!!谢谢只是它还在显示脚本源代码,你知道吗?@RAGS:check工作正常。。。我的问题是,当它在“新建”选项卡中打开脚本时,它会显示源代码,而不是触发greasemonkey来安装它。。。
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