我使用 HTML、CSS 和 JS 创建了一个工具。我希望可以通过 TamperMonkey 访问该工具。我发现了一个 TamperMonkey 脚本,其中创建者没有将其代码直接添加到脚本中,而是利用 @require 行来链接他的 Web 托管代码文件。
我正在尝试重现此内容,但我不想添加 https 链接,而是想从本地文件开始。
这是他的代码(匿名):
// ==UserScript==
// @name name
// @version version
// @author author
// @description description
// @match URL where the tool will be used
// @require https://hiscodelink1.js?raw=1
// @require https://hiscodelink2.js?raw=1
// @require https://hiscodelink3.class.js?raw=1
// ==/UserScript==
// See https://hiscodelink1.js?raw=1
Run Code Online (Sandbox Code Playgroud)
这是我的(匿名):
// ==UserScript==
// @name name
// @version version
// @author author
// @description description
// @match URL where the tool will be used (using the same to test)
// @require /Users/myname/Desktop/Tools/mycode1.js
// @require /Users/myname/Desktop/Tools/mycode2.js
// @require /Users/myname/Desktop/Tools/mycode3.class.js
// ==/UserScript==
// See /Users/myname/Desktop/Tools/mycode1.js
Run Code Online (Sandbox Code Playgroud)
由于它不适用于我自己的代码,因此我首先尝试让他自己的工具与我的本地链接一起工作。尽管使用相同的@match URL和相同的代码内容,但它仍然不起作用。请注意,我不断更新各处所有文件的路径。
我尝试以这种方式编写本地 URL:/Users/myname/Desktop/Tools/mycode1.js
这样: file:///Users/myname/Desktop/Tools/mycode1.js
我已将本地文件的访问权限授予 TamperMonkey。
我究竟做错了什么?
多谢
小智 2
对本地文件的要求应该类似于:
// @require file://C:\path\to\userscript.user.js
对于苹果电脑
// @require file:///path/to/userscript.user.js
如果您无法使本地文件正常工作,您可以从其他网站而不是本地托管您的代码吗?我发现版本控制更容易,因此不必占用我的计算机文件空间。
例如,您可以使用 github 或 Pastebin 之类的东西。
为此,//@require您可以执行以下操作(github):
// @require https://cdn.jsdelivr.net/gh/name/repo-name@latest/codefilename.min.js
虽然我认为你可以这样做:
// @require https://raw.githubusercontent.com/name/repo/main/filename
或者
// @require https://github.com/name/repo/main/filename
对于巴斯德宾:
// @require https://pastebin.com/raw/thepartofthelink
对于来自不同网站的托管选项,如果您不想使用,// @require and all that stuff可以执行类似的操作// @grant GM_xmlhttpRequest
GM_xmlhttpRequest({ method : "GET",
url : "https://cdn.jsdelivr.net/gh/name/repo-name@latest/codefilename.min.js",
onload : (ev) => { let e = document.createElement('script');e.innerText = ev.responseText;document.head.appendChild(e); }});
| 归档时间: |
|
| 查看次数: |
11031 次 |
| 最近记录: |