如何在页面内容显示之前运行greasemonkey脚本? [英] how to run greasemonkey script before the page content is displayed?

查看:174
本文介绍了如何在页面内容显示之前运行greasemonkey脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Firefox编写一个插件,并使用greasemonkey脚本来做到这一点(我使用这个工具编译用户脚本 http://arantius.com/misc/greasemonkey/script-compiler )。

问题是脚本在页面完全加载后运行。这意味着用户会以原始形式看到所查看的页面,然后脚本将应用我所做的更改。我的问题是有没有办法在页面的内容显示给用户之前运行用户脚本,所以用户只会最终版本的网站?

解决方案

编辑:这个帖子是在Greasemonkey中执行 @ run-at 键之前创建的 - 正如Blaise指出的,来自Greasemonkey 0.9.8你现在可以在页面开始加载后立即执行脚本。

@ run-at document-start 在wiki中描述如下:


Start是0.9.8版本中的新增功能。这个脚本将在任何
文档开始加载之前运行,因此在任何脚本运行或者图像加载之前。

请注意,这意味着让脚本在创建DOM之前运行(可能),并可能导致一些不一致/不寻常的行为。您需要(一点)不仅仅是这一行的入门。



在Greasemonkey维基上有更多的细节:
< a href =http://wiki.greasespot.net/Metadata_Block#.40run-at =noreferrer> http://wiki.greasespot.net/Metadata_Block#.40run-at



附注:我必须手动输入的信息与浏览器中的Greasemonkey具体相关。我不确定是否 @ run-at document-start 对于脚本编译器来说效果很好 - 我建议生活得很危险..测试一下,找出来! ;]









可以在加载页面之前运行用户脚本。



要停止使用当前版本的Greasemonkey的闪烁,风格添加到您的Firefox配置文件(然后使用该脚本进行撤消),如 Greasemonkey wiki 所述,但这样会也要求你的每一个用户都这样做,从中受益。

b
$ b

长期以来,通过Greasemonkey的Github网站 issue#1103 ,一个工作原型似乎已经作出了(但没有时间表这个被添加到发布版本afaik)。


I am writing a plug-in for Firefox and using greasemonkey script to do that (I compile the user script using this tool http://arantius.com/misc/greasemonkey/script-compiler).

The issue is that the script is run after the page is fully loaded. Meaning the user would see the viewed page in its original form and then the script will apply the changes that I made. My question is there a way to run the user script before the contents of the page is displayed to the user, so the user would only the final version of the website?

解决方案

EDIT: This post was created prior to the implementation of the @run-at key in Greasemonkey - as noted by Blaise, from Greasemonkey 0.9.8 you may now have the script executed as soon as the page begins to load.

@run-at document-start is described in the wiki as follows:

Start is new as of version 0.9.8. The script will run before any document begins loading, thus before any scripts run or images load.

Note that this means having the script run (potentially) prior to the creation of the DOM and may lead to some inconsistent/unusual behaviour. You will need (a little) more than just this one-line drop-in.

There are a few more details over at the Greasemonkey Wiki: http://wiki.greasespot.net/Metadata_Block#.40run-at

Side-note: The information I have to hand is specifically related to Greasemonkey in the browser. I am unsure whether @run-at document-start works well with the script compiler - I suggest living dangerously.. Test it and find out! ;]



It is not currently possible to run a user script before the page loads.

To stop the flicker using current versions of Greasemonkey, you could try adding a user-style to your Firefox profile (which is then undone using the script) as described at the Greasemonkey wiki but this would also require each of your users to do the same to benefit from this.

It is something that has been desired for a long time and looking through issue #1103 on Greasemonkey's Github site, a working prototype appears to have been made (but there is no timescale for this to be added to a release version afaik).

这篇关于如何在页面内容显示之前运行greasemonkey脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆