IAd*_*ter 6 javascript alert greasemonkey userscripts tampermonkey
在网站上有类似的代码(其网站上的网站)
<script language="JavaScript" type="text/javascript">
alert("ble");
</script>
Run Code Online (Sandbox Code Playgroud)
我尝试使用GM禁用该警报.我试图这样做
unsafeWindow.alert=function() {};
Run Code Online (Sandbox Code Playgroud)
但我看到警报并得到此错误
Error: uncaught exception: [Exception... "Component is not available" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: file:///C:/Documents%20and%20Settings/arokitnicki/Dane%20aplikacji/Mozilla/Firefox/Profiles/sm4bsods.default/extensions/%7Be4a8a97b-f2ed-450b-b12d-ee082ba24781%7D/components/greasemonkey.js :: anonymous :: line 377" data: no]
Run Code Online (Sandbox Code Playgroud)
如何禁用该警报?
PS这是JavaScript不问题,但Greasemonkey的问题.
编辑:
它的公司的网站,所以我无法粘贴真正的代码
<head>
<script>
dojo.require("dojo.back");
dojo.back.init();
</script>
</head>
<body onload="someMethod()">
<iframe></iframe>
<script>
alert("bla");
</script>
</body>
Run Code Online (Sandbox Code Playgroud)
标题中还有一些脚本和CSS声明.
更新:对于Greasemonkey的现代版本:
您可以alert()在大多数情况下使用拦截@run-at document-start.例如,加载此脚本然后访问测试页面:
// ==UserScript==
// @name _Overwrite Alert
// @match *://output.jsbin.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
var alrtScope;
if (typeof unsafeWindow === "undefined") {
alrtScope = window;
} else {
alrtScope = unsafeWindow;
}
alrtScope.alert = function (str) {
console.log ("Greasemonkey intercepted alert: ", str);
};
Run Code Online (Sandbox Code Playgroud)
如果您的脚本需要GM_函数,则必须设置Inject Mode: Instant除none之外的其他函数.在这种情况下使用Advanced如下:
// ==UserScript==
// @name _Overwrite Alert
// @match *://output.jsbin.com/*
// @grant GM_addStyle
// @run-at document-start
// ==/UserScript==
function myAlert (str) {
console.log ("Greasemonkey intercepted alert: ", str);
}
unsafeWindow.alert = exportFunction (myAlert, unsafeWindow);
Run Code Online (Sandbox Code Playgroud)
Instant 在特定情况下工作正常.
但是,如果这确实是页面上的代码,那么您将无法使用Greasemonkey停止该警报.
这是因为该警报将在页面加载期间和@grant事件之前触发 - 即Greasemonkey被触发时.
加载此GM脚本:
// ==UserScript==
// @name Overwrite Alert
// @description Overwrites alert()
// @include http://jsbin.com/*
// ==/UserScript==
unsafeWindow.alert=function() {};
Run Code Online (Sandbox Code Playgroud)
然后访问:http://jsbin.com/ajeqe4/6.
检查代码(http://jsbin.com/ajeqe4/6/edit),您将看到3个警报.Greasemonkey只能停止exportFunction()(通常)触发的警报.
其他因素可以阻止GM停止警报的能力......页面加载速度太快或者关闭.
在pastebin.com上粘贴该页面的源代码(如果可能的话,未经编辑).您可以做其他事情.也许通过adblock阻止脚本?
否则,您必须编写扩展/附加组件.
| 归档时间: |
|
| 查看次数: |
4587 次 |
| 最近记录: |