admin管理员组文章数量:1357121
Is it possible to have Greasemonkey scripts run before anything else on the page?
I'm aware of @run-at document-start
, but this appears to run immediately after the <HTML>
tag. Normally this isn't a problem, but if the page is misformatted as in the example below, there doesn't seem to be anything I can do.
I'd appreciate any suggestions or ideas. Thanks!
<script>alert('This is an annoying message.');</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
...etc...
Is it possible to have Greasemonkey scripts run before anything else on the page?
I'm aware of @run-at document-start
, but this appears to run immediately after the <HTML>
tag. Normally this isn't a problem, but if the page is misformatted as in the example below, there doesn't seem to be anything I can do.
I'd appreciate any suggestions or ideas. Thanks!
<script>alert('This is an annoying message.');</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
...etc...
Share
Improve this question
asked Apr 2, 2009 at 3:07
anschauunganschauung
3,7683 gold badges27 silver badges35 bronze badges
3 Answers
Reset to default 4Actually, @run-at document-start
does pretty much run the GM script before anything from the page.
In your case, the following code will work in conjunction with @run-at document-start
:
_oldAlert = alert;
unsafeWindow.alert = function () {};
/*-- Optionally, wait for the DOM, then set an onload handler to restore
alert().
*/
It's not possible, because HTML requres that scripts are executed during parsing or not at all, e.g. this is allowed:
<script> document.write('<!'+'--'); </script>
If browser goes past this script without executing it, it will see pletely different document, therefore you can't analyze DOM of HTML document before scripts run.
Opera solves this problem in UserJS by firing BeforeScript
events, allowing UserJS to change/remove scripts at the very last moment.
Have you tried:
(function() {
var yourFunction = function()
{
// ...
}
window.addEventListener("load", yourFunction, false);
})();
本文标签: javascriptHow does one have Greasemonkey run before *anything* else in the pageStack Overflow
版权声明:本文标题:javascript - How does one have Greasemonkey run before *anything* else in the page? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743986102a2571295.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论