Diskusie » Žiadosť o vytvorenie

Rewriting the global alert() function doesn't work in Tampermonkey

§
Pridaný: 23.07.2014

Rewriting the global alert() function doesn't work in Tampermonkey

In Greasemonkey I can rewrite the global alert() function with:

window.alert = function() {}

and it works anywhere.
But, in Tampermonkey (Chrome), it only works on it's own script.

Why? And could I make it work globally?

§
Pridaný: 04.08.2014

Hi,

You must use unsafeWindow.alert = function () {};

Regards
Reek

§
Pridaný: 08.08.2014

Hi

Thanks but that didn't work can you advertise that you can test for open this site

http://fireie.ir/

§
Pridaný: 08.08.2014

Hi,

that contains the alert that you want to replace, and what you want to inject code instead

§
Pridaný: 08.08.2014

try

unsafeWindow.alert = function(){return false};
window.alert = function(){return false};
Window.prototype.alert = function(){return false};

§
Pridaný: 08.08.2014

Thanks but that didn't work

// ==UserScript==
// @name Block
// @namespace
// @description
// @include *
// ==/UserScript==

unsafeWindow.alert = function(){return false};
window.alert = function(){return false};
Window.prototype.alert = function(){return false};

§
Pridaný: 08.08.2014

Sorry I see no other solution :(

§
Pridaný: 08.08.2014

Hi,

Try this


// ==UserScript==
// @name Stop Alert Box
// @namespace stopalertbox
// @version 1.0
// @description Stop Alert Box
// @match http://*/*
// @copyright 2014+, Reek
// @run-at document-start
// ==/UserScript==


unsafeWindow.alert = function(){return false};
window.alert = function(){return false};
Window.prototype.alert = function(){return false};


Regards
Reek

§
Pridaný: 11.08.2014

try with
// @grant unsafeWindow

§
Pridaný: 07.01.2015

Hi there

The code does not work

Please help

sample :
rarepic.ir

woxxomZablokovaný
§
Pridaný: 08.01.2015

Maybe Chrome doesn't allow redefining it.

Jixun.MoeZablokovaný
§
Pridaný: 08.01.2015

If your @grant is none, use window.alert = null, otherwise use unsafeWindow.alert = null;.

// ==UserScript==
// @name         Disable alert
// @namespace    org.gf.860
// @version      0.1
// @description  Disable window.alert 
// @author       You
// @include      *
// @run-at       document-start
// @grant        none
// ==/UserScript==

window.alert = null;

Test case: http://jsfiddle.net/JixunMoe/tvnnuqq5/

§
Pridaný: 27.01.2015

Hi there

But unfortunately did not open

Demo

http://zigzig.ir/book/

Pridať odpoveď

Aby ste mohli pridať odpoveď, prihláste sa.