如何在浏览器外编辑Tampermonkey脚本

How to edit Tampermonkey scripts outside of the browser

本文关键字:编辑 Tampermonkey 脚本 浏览器      更新时间:2023-09-26

如何在浏览器外编辑Tampermonkey脚本?我宁愿在一个好的IDE中,而不是在浏览器中进行编辑。

当我在Firefox中开发Greasemonkey脚本时,我曾经能够做到这一点,但我无法在Chrome中找到。user.js文件。

进入扩展> Tampermonkey>允许访问文件url

然后,将脚本设置为:

// ==UserScript==
// @name            Acecool - Video Site - Ultimate Video Site Management, Ad Removal, Redirection, Direct-Linking and more!
// @author          Acecool
// @namespace       Acecool
// @version         0.0.1
// @description     Replaces encoded-links with decoded direct-links on episode finder sites.
// @description     Automatically click the "continue" button, and attempt to skip the countdown if any, on video watching sites.
// @description     Remove ad panels on video watching sites.
// @match           http://*/*
// @require         http://code.jquery.com/jquery-latest.js
// @require         file:///C:/AcecoolGit/acecooldev_userscripts/libraries/acecool_functions_lib.js
// @require         file:///C:/AcecoolGit/acecooldev_userscripts/video_sites/video_site_ultimate_tool.js
// @grant           GM_xmlhttpRequest
// ==/UserScript==

我知道这对这个线程作者来说有点晚了,但这就是我如何开发…

然后,脚本设置了确切的头,因此我包含的示例文件:video_site_ultimate_tool.js是

// ==UserScript==
// @name            Acecool - Video Site - Ultimate Video Site Management, Ad Removal, Redirection, Direct-Linking and more!
// @author          Acecool
// @namespace       Acecool
// @version         0.0.1
// @description     Replaces encoded-links with decoded direct-links on episode finder sites.
// @description     Automatically click the "continue" button, and attempt to skip the countdown if any, on video watching sites.
// @description     Remove ad panels on video watching sites.
// @match           http://*/*
// @require         http://code.jquery.com/jquery-latest.js
// @require         file:///C:/AcecoolGit/acecooldev_userscripts/libraries/acecool_functions_lib.js
// @require         file:///C:/AcecoolGit/acecooldev_userscripts/video_sites/video_site_ultimate_tool.js
// @grant           GM_xmlhttpRequest
// ==/UserScript==
alert( 'test script is running from the file system instead of from TM...' );

我将它们设置为相同的(好吧,我将文件系统脚本中的@require更改为http变体,因此functions_lib将转到bitbucket,而video_site_ultimate_tool将被删除,并且脚本将在复制到我的bitbucket repo时放入…

能够使用外部编辑器并让更改立即显示,这确实加快了开发速度…

希望这对下一个人有帮助。

由于Chrome扩展并没有真正访问文件系统(解释如下),Tampermonkey将脚本存储在内部存储器中。

你能做的是允许Tampermonkey访问你的本地文件,复制你的脚本头到Tampermonkey,另外,@require完整的脚本位于你硬盘的某个地方。

"don't really"意味着LocalFileSystem API允许文件访问,但名称和文件不一定映射到真正的文件系统。此外,LocalFileSystem现在似乎已被弃用。