在加载特定网站时自动运行 JavaScript 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22707808/
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
Automatically run JavaScript code upon loading a specific website
提问by
I've written scripts to filter out threads and posts in a programming forum by author.
我编写了脚本来过滤作者在编程论坛中的主题和帖子。
But you need to post the code into the web console for each page individually.
但是您需要将代码分别发布到每个页面的 Web 控制台中。
I was wondering if it were possible and if so how (using either firefox or chrome), to set your browser up to run a specific script upon loading a specific site? Is it possible as an extension or plugin?
我想知道是否有可能,如果有,如何(使用 firefox 或 chrome)将浏览器设置为在加载特定站点时运行特定脚本?是否可以作为扩展或插件?
采纳答案by Samuel Liew
You can use Tampermonkeyfor Google Chrome
您可以将Tampermonkey用于 Google Chrome
Tampermonkey is the most popular userscript manager for Google Chrome.
Tampermonkey 是最流行的 Google Chrome 用户脚本管理器。
Greasemonkeyfor Firefox:
适用于 Firefox 的Greasemonkey:
Allows you to customize the way a web page displays or behaves, by using small bits of JavaScript.
允许您使用少量 JavaScript 自定义网页的显示或行为方式。
回答by Aliou
You can use dotjs.
您可以使用dotjs。
dotjs is a Google Chrome extension that executes JavaScript files in
~/.js
based on their filename.If you navigate to
http://www.google.com/
, dotjs will execute~/.js/google.com.js
.This makes it super easy to spruce up your favorite pages using JavaScript.
dotjs 是一个 Google Chrome 扩展,它根据文件名执行 JavaScript 文件
~/.js
。如果您导航到
http://www.google.com/
,dotjs 将执行~/.js/google.com.js
。这使得使用 JavaScript 修饰您最喜欢的页面变得非常容易。