怎样写一个grossmonkey脚本来删除一个confim对话框? [英] How to write a greasemonkey script to remove a confim dialog?
问题描述
我想写一个非常简单的lublessmonkey脚本,因为我讨厌你确定吗?"我经常使用的网站上的javascript确认.我只是将其用于个人用途,而不是发布它或任何东西.经过一番谷歌搜索后,我发现 http://wiki.greasespot.net/UnsafeWindow 解释了我的情况想做.
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;
}
我想用只需返回true来替换confirmIt(message);
I want to replace confirmIt(message) with just return true;
所以我做了一个剧本
var oldFunction = unsafeWindow.confirmIt(message);
unsafeWindow.confirmIt(message) = function() {
return true;
};
我收到错误消息未定义消息."
I get the error "message is not defined."
我不确定我是否要解决这个问题(我认为不是),但是我很感谢一些在Greasemonkey方面有丰富经验的人提供的有关如何替换页面上Javascript函数的指导.
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.
推荐答案
您需要将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:
var oldFunction = unsafeWindow.confirmIt;
unsafeWindow.confirmIt = function(message) {
return true;
};
尝试一下.
这篇关于怎样写一个grossmonkey脚本来删除一个confim对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!