是否可以检查 Chrome 用户脚本中的更新?

发布于 2024-10-31 12:51:03 字数 176 浏览 4 评论 0原文

需要明确的是:我不打算进行自动更新。我只是想让用户知道有一个更新的脚本,并给他们一个可以获取最新版本的链接。

在 Firefox 中有几种方法可以做到这一点,但它们似乎都使用 Chrome 不支持的 Greasemonkey 特定功能。

我今天花了 4 个小时研究这个问题,现在我正在 SO 社区寻求帮助。

Just to be clear: I am not looking to do an auto update. I would just simply like to let the user know that there is an updated script and give them a link where they can go and get the latest version.

There a few ways of doing this in Firefox but they all seem to use Greasemonkey specific features that are not supported in Chrome.

I have spent a good 4 hours today researching this and now I am looking at the SO community for help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自由范儿 2024-11-07 12:51:03

感谢 Yi Jiang 在评论中发布了这个链接。以防万一该脚本消失,我将在此处发布内容:

// ==UserScript==
// @name           SelfUpdatingScript
// @version        1.0.0
// @namespace      Benjol (http://stackoverflow.com/users/11410/benjol)
// @description    Template script for a self-updating script
// @credits        Kudos to http://stackoverflow.com/users/115866/balpha
// @include        https://gist.github.com/*
// ==/UserScript==

function with_jquery(f) {
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.textContent = "(" + f.toString() + ")(jQuery)";
  document.body.appendChild(script);
};

with_jquery(function ($) {
  $(function () {
    //how does this work?
    // 1. The installed script loads first, and sets the local VERSION variable with the currently installed version number
    // 2. window["selfUpdaterCallback:" + URL] is not defined, so this is skipped
    // 3. When updateCheck() is called, it defines window["selfUpdaterCallback:" + URL], which retains the installed version number in VERSION (closure)
    // 4. updateCheck() then loads the external version of the script into the page header
    // 5. when the external version of the script loads, it defines its own local VERSION with the external (potentially new) version number
    // 6. window["selfUpdaterCallback:" + URL] is now defined, so it is invoked, and the external version number is passed in
    // 7. if the external version number (ver) is greater than the installed version (VERSION), the notification is invoked
    var VERSION = 1.0;                                                         // than 1.13; if you mean 1.02, say so!)
    var URL = "https://gist.github.com/raw/874058/selfupdatingscript.user.js"; // VERSION)
          notifier(ver, VERSION, URL);
      }

      // make that a script tag. SO will not allow me to have a greater sign infront.
      /*$(' script />').attr("src", URL).appendTo("head");*/
    }

    // INSERT YOUR CUSTOM SCRIPT AFTER THIS COMMENT
    //Customize this code in the following ways
    //  - modify the callback to show your own custom notification
    //  - You could decide to check for updates less frequently that on every page load
    updateCheck(function (newver, oldver, url) {
      alert("A new version (" + newver + ", your current version is " + oldver + ") of the SelfUpdatingScript is available for download here: " + url);
    });
  });
});

Thank you to Yi Jiang who posted this link in a comment. Just in case that script goes away I will post the contents here:

// ==UserScript==
// @name           SelfUpdatingScript
// @version        1.0.0
// @namespace      Benjol (http://stackoverflow.com/users/11410/benjol)
// @description    Template script for a self-updating script
// @credits        Kudos to http://stackoverflow.com/users/115866/balpha
// @include        https://gist.github.com/*
// ==/UserScript==

function with_jquery(f) {
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.textContent = "(" + f.toString() + ")(jQuery)";
  document.body.appendChild(script);
};

with_jquery(function ($) {
  $(function () {
    //how does this work?
    // 1. The installed script loads first, and sets the local VERSION variable with the currently installed version number
    // 2. window["selfUpdaterCallback:" + URL] is not defined, so this is skipped
    // 3. When updateCheck() is called, it defines window["selfUpdaterCallback:" + URL], which retains the installed version number in VERSION (closure)
    // 4. updateCheck() then loads the external version of the script into the page header
    // 5. when the external version of the script loads, it defines its own local VERSION with the external (potentially new) version number
    // 6. window["selfUpdaterCallback:" + URL] is now defined, so it is invoked, and the external version number is passed in
    // 7. if the external version number (ver) is greater than the installed version (VERSION), the notification is invoked
    var VERSION = 1.0;                                                         // than 1.13; if you mean 1.02, say so!)
    var URL = "https://gist.github.com/raw/874058/selfupdatingscript.user.js"; // VERSION)
          notifier(ver, VERSION, URL);
      }

      // make that a script tag. SO will not allow me to have a greater sign infront.
      /*$(' script />').attr("src", URL).appendTo("head");*/
    }

    // INSERT YOUR CUSTOM SCRIPT AFTER THIS COMMENT
    //Customize this code in the following ways
    //  - modify the callback to show your own custom notification
    //  - You could decide to check for updates less frequently that on every page load
    updateCheck(function (newver, oldver, url) {
      alert("A new version (" + newver + ", your current version is " + oldver + ") of the SelfUpdatingScript is available for download here: " + url);
    });
  });
});
纵性 2024-11-07 12:51:03

我刚刚找到了一个在 Chrome 上运行的 Greasefire 的更新程序脚本。不知道是否有帮助。
http://code.google.com/p /greasefire/source/browse/chrome/updater.js?r=55

I just found an updater script for greasefire running on chrome. Dont know if it'd help.
http://code.google.com/p/greasefire/source/browse/chrome/updater.js?r=55

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文