There was a task to write a simple extension for all (if possible) popular browsers. Expansion activity is the implementation of javascript ʻa in the body of the document.
The doctor prescribed javascript injections
It would seem that everything is simple, we execute the code in the browser line:
javascript : var s = document. createElement ( 'script' ) ; s. type = 'text/javascript' ; document. body . appendChild ( s ) ; s. src = 'script.js' ; void ( 0 ) ;
javascript : var s = document. createElement ( 'script' ) ; s. type = 'text/javascript' ; document. body . appendChild ( s ) ; s. src = 'script.js' ; void ( 0 ) ;
javascript : var s = document. createElement ( 'script' ) ; s. type = 'text/javascript' ; document. body . appendChild ( s ) ; s. src = 'script.js' ; void ( 0 ) ;
javascript : var s = document. createElement ( 'script' ) ; s. type = 'text/javascript' ; document. body . appendChild ( s ) ; s. src = 'script.js' ; void ( 0 ) ;
javascript : var s = document. createElement ( 'script' ) ; s. type = 'text/javascript' ; document. body . appendChild ( s ) ; s. src = 'script.js' ; void ( 0 ) ;
But what to do if your script has to process all pages of another site. Do not force the user to constantly click on the tab with the injection code after each transition to a new page. Naive searches for a simple solution were not successful:
It was the interception of all links on the page and the addition of its code "javascript:", of course, the code was executed within the framework of the open page and then moved to a new "clean" page through (location.href).
The variant with setTimeout was generally in the order of nonsense ... the execution fell off after the start of loading a new page.
Writing extensions for a lot of browsers scared me the most, but what to do began to recall the most popular ones:
IE 7+ (on 6-ku decided to just score, a lot of costs for a small audience of users - forgive me)
Firefox 1.5+
Chrome 4+
Opera 9+ (in the end it turned out that the extensions can only be written under Opera 11)
Safari 3+
“There’s no problem with Firefox and Chrome,” I thought. ')
Google chrome
In an hour, an extension for Chrome was written - a lot of documentation on the official site, a lot of examples. In general, a paradise for the developer.