File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,22 @@ npm install
4747
4848在项目根目录下的` userscript-headers.js ` 文件中存放的是默认的油猴头文件,在` webpack ` 编译的时候会把这个文件放到编译后的文件的头部作为油猴的插件声明:
4949
50+ ``` js
51+ // ==UserScript==
52+ // @name ${name}
53+ // @namespace ${repository}
54+ // @version ${version}
55+ // @description ${description}
56+ // @document ${document}
57+ // @author ${author}
58+ // @match *://*/*
59+ // @run-at document-start
60+ // ==/UserScript==
5061```
62+
63+ ` ${name} ` 、` ${version} ` 这种是支持的一些变量,在编译的时候会从` package.json ` 中获取对应的值替换掉,这样对于这些可能会重复或者一直变的内容我们就可以从一个源引用使用而不用重复设置或者反复修改了,如果默认的配置不能满足你的要求,你可以直接修改这个头文件,比如为其增加权限:
64+
65+ ``` js
5166// ==UserScript==
5267// @name ${name}
5368// @namespace ${repository}
@@ -57,12 +72,20 @@ npm install
5772// @author ${author}
5873// @match *://*/*
5974// @run-at document-start
75+ // @grant GM_getValue
76+ // @grant GM_setValue
77+ // @grant GM_registerMenuCommand
78+ // @grant GM.getValue
79+ // @grant GM.setValuex
80+ // @grant GM.registerMenuCommand
6081// ==/UserScript==
6182```
6283
63- ` ${name} ` 、` ${version} ` 这种是支持的一些变量,在编译的时候会从` package.json ` 中获取对应的值替换掉,这样对于这些可能会重复或者一直变的内容我们就可以从一个源引用使用而不用重复设置或者反复修改了。
84+ 除了变量替换其他内容都会被原样保留,这是编译后的样子:
85+
86+ ![ image-20230817004653299] ( README.assets/image-20230817004653299.png )
6487
65- 然后就可以开心的写代码了,在编写代码的时候你可以使用npm命令为项目添加依赖 ,对于一个稍微复杂点的脚本而言很可能会引用外部的依赖:
88+ 然后就可以开心的写代码了,在编写代码的时候你可以使用 ` npm ` 命令为项目添加依赖 ,对于一个稍微复杂点的脚本而言很可能会引用外部的依赖:
6689
6790``` bash
6891npm add xxx
You can’t perform that action at this time.
0 commit comments