greasemonkey
If you want to try executing custom local scripts on any page you visit, try Greasemonkey. Here's a 10 seconds tut.
如果要尝试在您访问的任何页面上执行自定义本地脚本,请尝试使用Greasemonkey。 这是10秒的练习题。
The task is to create a custom script and to make sure it's executed every time you leave a page on phpied.com
任务是创建一个自定义脚本,并确保每次您在phpied.com上离开一个页面时都执行该脚本
(prerequisite) Get Firefox!
(前提条件)获取Firefox!
Install Gresemonkey from here
从这里安装Gresemonkey
Create a file phpied.user.js (all your custom scripts must end in .user.js) with the following
使用以下命令创建文件phpied.user.js(所有自定义脚本都必须以.user.js结尾)
var start = new Date(); window.addEventListener("unload", function(e) { var end = new Date(); var diff = Math.floor((end - start) / 1000); alert("Man, I spent " + diff + " of my precious seconds on this guy's page!" + " Now that's called investment!" ); }, false);
- Open phpied.user.js in the browser. You'll see a message from Greasemonkey inviting you to install. 在浏览器中打开phpied.user.js。 您会看到一条来自Greasemonkey的消息,邀请您进行安装。
- Click Install... and you're done. Now this script will execute on every single page you hit. To change it so that it executes only when you visit phpied.com do: 单击安装...,完成。 现在,此脚本将在您点击的每个页面上执行。 要更改它以便仅在您访问phpied.com时执行,请执行以下操作:
- Right-click the monkey icon in the bottom-right of the browser screen. Select Manage User Scripts. 右键单击浏览器屏幕右下角的猴子图标。 选择管理用户脚本。
- Click the * in the Included Pages list, then hit Edit. Type "http://www.phpied.com/*" This means "execute this script on every page on phpied.com". Click OK. 单击“包含的页面”列表中的*,然后单击“编辑”。 键入“ http://www.phpied.com/*”,这意味着“在phpied.com的每个页面上执行此脚本”。 单击确定。
- Reload this page to see the script in action. 重新加载此页面以查看正在运行的脚本。
N.B. To modify a user script, do not modify the original file where you had it initially on your file system, won't work, I tried it 😉 Instead, modify the copy that GM has stored. Right-click the monkey icon -> Manage -> select your script in the listing on the left and click Edit.
注意:要修改用户脚本,请不要修改原始文件在文件系统上的原始位置,否则将无法正常运行,请尝试tried而是修改GM存储的副本。 右键单击猴子图标->管理->在左侧列表中选择脚本,然后单击编辑。
I've read before about the Greasemonkey Firefox extension, but never tried it before yesterday. Never tried probably because of a comment on the sitepoint.com's article about Greasemokey. The comment I found so funny, yet true, was "I just don't like the idea of having to spend time on another person's website when I barely get enough time to spend on my own." Well, sometimes one might like to try custom scripts on his/her own site, for example to test some stuff on the production server without the risk of breaking something.
我之前阅读过有关Greasemonkey Firefox扩展的信息,但从未在昨天之前尝试过。 从未尝试过,可能是因为对sitepoint.com上有关Greasemokey的文章发表了评论。 我觉得很有趣但很真实的评论是:“当我几乎没有时间花在自己的身上时,我就是不喜欢花时间在另一个人的网站上的想法。” 好吧,有时人们可能想在他/她自己的站点上尝试自定义脚本,例如在生产服务器上测试某些东西而不会破坏某些东西。
More resources: - Home page - Tutorial @ sitepoint - Free ebook - User scripts
更多资源:-主页-教程@ sitepoint-免费电子书-用户脚本
Tell your friends about this post on Facebook and Twitter
在Facebook和Twitter上告诉您的朋友有关此帖子的信息
翻译自: https://www.phpied.com/greasemonkey-execute-custom-javascripts-on-any-page/
greasemonkey