📜 ⬆️ ⬇️

We write cross-browser UserJS. Example # 2: redefine alert ()

Start: Example # 1: we change the Yandex logo

Last time I was asked: " Does UserJS have access to variable pages? "

The answer is yes.
')
I will show an example with the alert () function. alert - page variable, window method. Instead, alert can be any other variable.


Opera and Safari GreaseKit


  window.alert = function () {...} 


Firefox


window.wrappedJSObject.alert = function(){ ... }

Remember window.wrappedJSObject from the previous article? Not? Then goto " Example number 1: we change the Yandex logo ."

Option working in Opera, Firefox and Safari GreaseKit:

  var w = window.wrappedJSObject ||  window;
 w.alert = function () {...} 

Nice alert , the script I did, uses exactly this code.

Google chrome


In Google Chrome 3, you could access the window of the page via contentWindow. Chrome 4 removed this for security reasons . They say write so:

  location.href = "javascript: window.alert = function () {...} 

Note: I do not see any reason to write UserJS for Chrome. You need to write .CRX extensions , they can be updated. This is the same UserJS, but in the archive (plus a trifle like manifest.json). Therefore, I will not write about Chrome yet.

Continued: Example number 3: TwitPic thumbnails

Source: https://habr.com/ru/post/73928/


All Articles