🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

检查更新

检查脚本是否有新版本并提示更新

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

Author
xuexim
Daily installs
0
Total installs
1
Ratings
0 0 0
Version
1.0
Created
2025-03-26
Updated
2025-03-26
Size
2.17 KB
License
MIT
Applies to

这个函数用于检查 Greasyfork 上的脚本版本,并提示用户更新

代码说明:

  1. 头部元数据
  • @name:脚本名称,设为“检查更新”。
  • @version:版本号,这里设为 1.0。
  • @description:描述脚本功能。
  • @match:匹配的域名,与原脚本一致。
  • @grant:需要的权限,包括 GM_xmlhttpRequest 和 GM_info。
  • @license:使用 MIT 许可证。
  • @run-at:脚本在页面加载完成时运行。
  1. 核心功能
  • getUpdate 函数通过 GM_xmlhttpRequest 请求 Greasyfork 脚本页面,解析 HTML 获取最新版本号。
  • 使用 GM_info.script.version 获取当前脚本的版本号。
  • 通过 XPath (//*[@id="script-stats"]/dd[5]/span) 定位最新版本号。
  • 如果检测到新版本,弹出确认框提示用户更新,确认后跳转到脚本主页。
  1. 错误处理

添加了 onerror 回调,打印错误信息到控制台。

  1. 立即执行

使用 IIFE(立即执行函数表达式)包裹代码,并在最后调用 getUpdate() 以启动检查。

使用方法:

  • 将此代码保存为 .user.js 文件(例如 check-update.user.js)。
  • 在支持用户脚本的浏览器插件(如 Tampermonkey)中安装。
  • 确保脚本运行环境支持 GM_xmlhttpRequest 和 GM_info。

注意事项: