如何编写greasemonkey脚本来删除确认对话框?
我想写一个非常简单的油脂猴子脚本,因为我讨厌“你确定吗?”我经常使用的网站上的 javascript 确认。我只是将其用于个人用途,不会发布或任何其他用途。经过一番谷歌搜索后,我发现 http://wiki.greasespot.net/UnsafeWindow 解释了我似乎认为的内容想做。
我想要的页面的源代码是这样的
var message = "Are you sure?";
function confirmIt(message) {
var result = confirm(message);
return result;
}
我想用 return true 替换confirmIt(message);
所以我制作了一个脚本
var oldFunction = unsafeWindow.confirmIt(message);
unsafeWindow.confirmIt(message) = function() {
return true;
};
,但出现错误“消息未定义”。
我不确定我的做法是否正确(我想不是),但我很感谢在 Greasemonkey 方面有更多经验的人提供有关如何替换页面上的 Javascript 函数的指导。
I wanted to write a very simple greasemonkey script because I hate the "are you sure?" javascript confirmation on a site I use a lot. I'm just going to use it for personal use, not going to publish it or anything. After some Googling I found http://wiki.greasespot.net/UnsafeWindow explaining what it seems that I want to do.
The source code for the page I want is like this
var message = "Are you sure?";
function confirmIt(message) {
var result = confirm(message);
return result;
}
I want to replace confirmIt(message) with just return true;
So I made a script
var oldFunction = unsafeWindow.confirmIt(message);
unsafeWindow.confirmIt(message) = function() {
return true;
};
I get the error "message is not defined."
I'm not sure if I'm going about this right (I'm thinking not), but I'd appreciate some guidance from someone with more experience in Greasemonkey, about how to replace a Javascript function on a page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了函数之外,您还需要将 unsafeWindow.confirmIt 视为变量(确实如此)。因此,在代码中尝试执行的操作的方法是:
尝试一下。
You need to think of unsafeWindow.confirmIt as a variable in addition to a function (which it is). So, the way to do what you're attempting in your code would be:
Try that.