为什么我的Greasemonkey脚本没有更新?

20

我有一个针对Firefox的Greasemonkey脚本。这个脚本包括了一个meta-block和一些代码行。

我想要在服务器上更新我的脚本,然后自动更新浏览器的脚本。选项requireSecureUpdates已关闭。
我做错了什么?

我的1.meta.js文件:

// ==UserScript== 
// @name     Ibood autosubmit 
// @include  https://*.ibood.com/* 
// @include  http://*.ibood.com/* 
// @include  * 
// @version  1.1 
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js 
// @grant    GM_addStyle 
// @downloadURL http://www.tipsvoorbesparen.nl/1.user.js
// @updateURL http://www.tipsvoorbesparen.nl/1.meta.js
// ==/UserScript== 
2个回答

23

两个问题:

  1. Currently, your 1.meta.js is:

        // ==UserScript== 
        // @name     Ibood autosubmit 
        // @include  https://*.ibood.com/* 
        // @include  http://*.ibood.com/* 
        // @include  * 
        // @version  1.7
        // @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js 
        // @grant    GM_addStyle 
        // @downloadURL http://www.tipsvoorbesparen.nl/1.user.js
        // @updateURL http://www.tipsvoorbesparen.nl/1.meta.js
        // ==/UserScript== 
    

    Note the leading spaces?

    Greasemonkey cannot handle leading spaces for its Metadata Block due to a design limitation1.

  2. The current script version seems to be 1.8, but the meta file has version 1.7.

对于那些托管在自己网站上的小脚本,甚至不必考虑@updateURL设置。这主要是为了节省带宽,特别是在userscripts.org等网站上。

如果没有@updateURL设置,Greasemonkey将使用/检查由@downloadURL设置的任何内容。这样可以节省额外的维护工作(以及可能出现的SNAFU问题)。

最后,与此无关的一点,请不要使用@include *
使用@include *

  1. 会减慢您的浏览器速度
  2. 可能会导致意外的副作用
  3. 会导致有良心的用户拒绝安装您的脚本。





1. 具体来说,是在GM源文件parseScript.js中的这一部分:

var gAllMetaRegexp = new RegExp(
    '^// ==UserScript==([\\s\\S]*?)^// ==/UserScript==', 'm');

当你说不要使用include时,你没有说要使用什么。你是不是想用match代替include? - m3nda
@erm3nda,我说过不要使用@include *。那个星号会有很大的影响。是的,最好使用@match,或者你可以使用类似于@include http://YOUR_SERVER.COM/YOUR_PATH/*的东西。 - Brock Adams
哦,你说 @include * 就直接这么用?你是对的,那真的是错误的方式。 - m3nda

1

仅当检查了“要求安全更新”选项时才需要HTPS。(是的,在新的Greasemonkey安装中,默认情况下已经检查了它。)还请注意,在“*.meta.js”文件中,元数据块*确实存在故障。因此,本答案的这部分是错误的。 - Brock Adams

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接