javascript 如何在浏览器外编辑 Tampermonkey 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24542151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to edit Tampermonkey scripts outside of the browser
提问by eComEvo
How do I edit Tampermonkey scripts outside of the browser? Would rather be in a good IDE instead of trying to make the edits in the browser.
如何在浏览器之外编辑 Tampermonkey 脚本?宁愿在一个好的 IDE 中,而不是尝试在浏览器中进行编辑。
I used to be able to do this when I developed Greasemonkey scripts in Firefox, but I can't locate the .user.js files with Chrome.
我曾经在 Firefox 中开发 Greasemonkey 脚本时能够做到这一点,但我无法使用 Chrome 找到 .user.js 文件。
回答by Acecool
Go to Extensions > Tampermonkey > Allow access to file urls
转到扩展 > Tampermonkey > 允许访问文件 url
Then, set your script as:
然后,将您的脚本设置为:
// ==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==
I know it is a bit late for this thread author, but this is how I develop...
我知道对于这个线程作者来说有点晚了,但这就是我开发的方式......
Then, the scripts are set up with the exact header as that so the example file I include: video_site_ultimate_tool.js is
然后,脚本使用确切的标题设置,因此我包含的示例文件: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...' );
I set them up identically ( well, I change the @requires in the file-system script to be the http variants, so the functions_lib goes to bitbucket while video_site_ultimate_tool would be deleted and the script put in when copied to my bitbucket repo...
我对它们进行了相同的设置(好吧,我将文件系统脚本中的@requires 更改为 http 变体,因此functions_lib 转到 bitbucket,而 video_site_ultimate_tool 将被删除,并且脚本在复制到我的 bitbucket 存储库时放入...
It really speeds up development to be able to use an external editor and have the changes appear immediately...
能够使用外部编辑器并立即显示更改确实加快了开发速度......
Hopefully this helps the next person..
希望这有助于下一个人..
回答by derjanb
Since Chrome extensions don't really (explanation below) have access to the filesystem Tampermonkey stores the scripts at an internal storage.
由于 Chrome 扩展程序实际上(下面的解释)无法访问文件系统,因此 Tampermonkey 将脚本存储在内部存储中。
What you can do is to allow Tampermonkey to access your local files, copy the header of your script to Tampermonkey and additionally @requirethe full script that is located somewhere at your hard disk.
您可以做的是允许 Tampermonkey 访问您的本地文件,将脚本的标题复制到 Tampermonkey 并另外@require位于硬盘某处的完整脚本。
"don't really" means the LocalFileSystem API allows file access but the names and also the files are not necessarily mapped to the real filesystem. Furthermore LocalFileSystem seems to be deprecated now.
“不是真的”意味着 LocalFileSystem API 允许文件访问,但名称和文件不一定映射到真实的文件系统。此外,现在似乎不推荐使用 LocalFileSystem。