How to write a greasemonkey script to remove a confim dialog?

 ̄綄美尐妖づ 提交于 2019-12-06 06:38:01

问题


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.


回答1:


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;
};

Try that.



来源:https://stackoverflow.com/questions/3340337/how-to-write-a-greasemonkey-script-to-remove-a-confim-dialog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!