Skip to content
ScriptCatScriptCat
首页
使用指南
开发指南
更新日志
关于我们
github icon
  • 开发指南

    • 简介
      • 后台脚本
        • 云端执行
          • 订阅模式
            • 用户配置
              • API 文档
                • CatApi 文档
                  • 描述文档
                    • 主要值
                      • name
                        • namespace
                          • version
                            • description
                              • author
                                • run-at
                                  • storageName 🧪
                                    • background
                                      • crontab
                                        • match
                                          • include
                                            • exclude
                                              • grant
                                                • connect
                                                  • resource
                                                    • require
                                                      • require-css 🧪
                                                        • definition
                                                        • 额外描述值
                                                          • license
                                                            • updateURL
                                                              • downloadURL
                                                                • supportURL
                                                                  • homepage, homepageURL, website
                                                                    • source
                                                                      • icon, iconURL, defaulticon
                                                                        • icon64, icon64URL
                                                                          • 附注
                                                                            • 资源校验

                                                                        描述文档

                                                                        calendar icon2021年5月26日timer icon大约 4 分钟

                                                                        此页内容
                                                                        • 主要值
                                                                          • name
                                                                          • namespace
                                                                          • version
                                                                          • description
                                                                          • author
                                                                          • run-at
                                                                          • storageName 🧪
                                                                          • background
                                                                          • crontab
                                                                          • match
                                                                          • include
                                                                          • exclude
                                                                          • grant
                                                                          • connect
                                                                          • resource
                                                                          • require
                                                                          • require-css 🧪
                                                                          • definition
                                                                        • 额外描述值
                                                                          • license
                                                                          • updateURL
                                                                          • downloadURL
                                                                          • supportURL
                                                                          • homepage, homepageURL, website
                                                                          • source
                                                                          • icon, iconURL, defaulticon
                                                                          • icon64, icon64URL
                                                                          • 附注
                                                                          • 资源校验

                                                                        # 描述文档

                                                                        ==UserScript== 中的内容,用于描述脚本所需要的权限和脚本的信息作用等,在脚本的最开始的位置.

                                                                        // ==UserScript==
                                                                        // @name         New Userscript
                                                                        // @namespace    https://bbs.tampermonkey.net.cn/
                                                                        // @version      0.1.0
                                                                        // @description  try to take over the world!
                                                                        // @author       You
                                                                        // @crontab      * * once * *
                                                                        // ==/UserScript==
                                                                        
                                                                        1
                                                                        2
                                                                        3
                                                                        4
                                                                        5
                                                                        6
                                                                        7
                                                                        8

                                                                        # 主要值

                                                                        # name

                                                                        脚本名称

                                                                        # namespace

                                                                        脚本命名空间.同一namespace空间中的脚本,数据可以共享🧪.(以切换成使用storageName作为共享空间)

                                                                        # version

                                                                        脚本的版本,建议遵循语义化版本规则open in new window,在检测到脚本的版本变化后,会提示用户进行更新等操作.

                                                                        # description

                                                                        对于脚本的详细描述

                                                                        # author

                                                                        脚本作者

                                                                        # run-at

                                                                        脚本的运行时间

                                                                        值运行时支持
                                                                        document-start在前端匹配到网址后,以最快的速度注入脚本到页面中v0.3.0
                                                                        document-endDOM加载完成后注入脚本,此时页面脚本和图像等资源可能仍在加载v0.3.0
                                                                        document-idle所有内容加载完成后注入脚本v0.3.0
                                                                        document-body脚本只会在页面中有body元素时才会注入v0.6.2
                                                                        document-menu在页面右键时会显示一个菜单,点击时运行脚本,脚本名称作为菜单名称v0.3.4

                                                                        对于menu图标可参考:Unicode Symbolsopen in new window和emojiopen in new window

                                                                        # storageName 🧪

                                                                        Value的存储空间,同一storageName下的数据可以共享和通信.这是脚本猫独有的.

                                                                        # background

                                                                        表示本脚本为后台脚本,需要运行在后台环境,具体请看后台脚本

                                                                        # crontab

                                                                        表示脚本为定时脚本,需要有cron表达式值,只能存在一个cron表达式,会在后台环境中定时运行,具体请看定时脚本

                                                                        # match

                                                                        被match的url才会运行脚本,遵循Match patternsopen in new window,match中使用*表示通配,tld表示匹配顶域,域名以*.开头也会匹配xxx.com:

                                                                        值正确案例错误案例
                                                                        http://scriptcat.org/doc/matchhttp://scriptcat.org/doc/matchhttp://scriptcat.org/doc/runAt
                                                                        *://*/param?*https://scriptcat.org/param|http://scriptcat.org/param?search=油猴https://scriptcat.org/test/param
                                                                        *://*/prefix*suffixhttp://scriptcat.org/prefix/suffix|http://scriptcat.org/prefix/mid/suffix|http://scriptcat.org/prefixsuffixhttp://scriptcat.org/prefix/suffix/end
                                                                        http*://scriptcat.org/*https://scriptcat.org/|https://scriptcat.org/doc|http://scriptcat.org/doc/match|http://scriptcat.org/param?search=油猴https://doc.scriptcat.org/
                                                                        http*://scriptcat.org/doc/*https://scriptcat.org/doc|http://scriptcat.org/doc/matchhttp://scriptcat.org/param?search=油猴
                                                                        http*://scriptcat.tld/doc/*https://scriptcat.cn/doc|http://scriptcat.net.cn/doc/matchhttp://google.com/param?search=油猴
                                                                        http*://*.scriptcat.org/doc/*https://scriptcat.cn/doc|http://www.scriptcat.net.cn/doc/matchhttp://google.com/param?search=油猴

                                                                        # include

                                                                        match的别名

                                                                        # exclude

                                                                        不匹配url

                                                                        # grant

                                                                        申请API权限,需要申请了API之后才能调用,api列表请看:API文档和CAT API文档.

                                                                        两个特殊的值:

                                                                        • none: 表示不在沙盒环境中运行,直接存在页面环境中,此环境下无法使用任何的GM API,可以直接访问页面的window对象.
                                                                        • unsafeWindow在沙盒环境中如果需要访问页面的window对象,需要使用unsafeWindow来进行访问.(tm不需要声明这个,为了兼容只能去了,好不规范啊.)

                                                                        # connect

                                                                        获取网站的访问权限,请看GM_cookie和GM_xmlhttpRequest

                                                                        # resource

                                                                        引入资源文件,声明完@resource后,可使用GM_getResourceText/GM_getResourceURL获取信息

                                                                        // @resource icon https://bbs.tampermonkey.net.cn/favicon.ico
                                                                        // @resource html https://bbs.tampermonkey.net.cn/
                                                                        // @resource xml https://bbs.tampermonkey.net.cn/sitemap.xml
                                                                        // 添加资源校验
                                                                        // @resource icon https://bbs.tampermonkey.net.cn/favicon.ico#md5=xxx;sha256=xxx
                                                                        
                                                                        1
                                                                        2
                                                                        3
                                                                        4
                                                                        5

                                                                        # require

                                                                        引入外部js文件,可以进行资源校验

                                                                        # require-css 🧪

                                                                        引入外部css文件,可以进行资源校验

                                                                        # definition

                                                                        一个.d.ts文件的引用地址,能够自动补全编辑器的自动提示

                                                                        # 额外描述值

                                                                        # license

                                                                        当前脚本的开源协议

                                                                        # updateURL

                                                                        检查更新必须要求远程脚本有@version标签才能生效

                                                                        脚本检查更新的链接,不设置默认为链接的user.js=>meta.js,无user.js的默认为当前链接.

                                                                        如果配置了@updateURL必须也得配置@downloadURL才能使@updateURL生效

                                                                        # downloadURL

                                                                        脚本更新的下载地址

                                                                        # supportURL

                                                                        支持站点,bug反馈页面

                                                                        # homepage, homepageURL, website

                                                                        脚本主页

                                                                        # source

                                                                        脚本源码页

                                                                        # icon, iconURL, defaulticon

                                                                        脚本图标

                                                                        # icon64, icon64URL

                                                                        64x64大小的脚本图标

                                                                        # 附注

                                                                        # 资源校验

                                                                        使用md5,sha1,sha224,sha256,sha384,sha512方法对资源进行校验防止篡改,不同的校验方式之间可用;或者,分开,例如:

                                                                        // @require https://cdn.jsdelivr.net/npm/darkmode-js@1.5.7/lib/darkmode-js.min.js#md5=d55836f30c097da753179f82fa6f108f;sha256=a476ab8560837a51938aa6e1720c8be87c2862b6221690e9de7ffac113811a90
                                                                        
                                                                        1
                                                                        edit icon编辑此页open in new window
                                                                        上次编辑于: 2022/4/16 05:35:31
                                                                        贡献者: CodFrm,CodFrm,Hangover1230,Junzhou Liu
                                                                        上一页
                                                                        CatApi 文档
                                                                        Released under the MIT License Copyright © 2021-2022 ScriptCat 脚本猫