javascript – 无论如何都要检查Chrome用户脚本中的更新?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 无论如何都要检查Chrome用户脚本中的更新?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2541字,纯文字阅读大概需要4分钟。
内容图文
![javascript – 无论如何都要检查Chrome用户脚本中的更新?](/upload/InfoBanner/zyjiaocheng/719/4ba347ac51094cb08c98a36e3da3b71a.jpg)
需要明确的是:我不打算进行自动更新.我只是想让用户知道有一个更新的脚本,并给他们一个链接,他们可以去获取最新版本.
有几种方法可以在Firefox中执行此操作,但它们似乎都使用Chrome不支持的Greasemonkey特定功能.
今天我花了4个小时研究这个,现在我正在寻找SO社区的帮助.
解决方法:
感谢Yi Jiang在评论中发表了这篇link.如果脚本消失,我会在这里发布内容:
// ==UserScript== // @name SelfUpdatingScript // @version 1.0.0 // @namespace Benjol (https://stackoverflow.com/users/11410/benjol) // @description Template script for a self-updating script // @credits Kudos to https://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); }); }); });
内容总结
以上是互联网集市为您收集整理的javascript – 无论如何都要检查Chrome用户脚本中的更新?全部内容,希望文章能够帮你解决javascript – 无论如何都要检查Chrome用户脚本中的更新?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。