OLD | NEW |
| (Empty) |
1 // ==UserScript== | |
2 // @include * | |
3 // ==/UserScript== | |
4 | |
5 opera.extension.onmessage = function (event) { | |
6 //opera.postError('INJECTED: got a ' + event.data.request + ' request fo
r ' + document.location.href); | |
7 if(event.data.request == 'css') {//Ensure the received message is for th
e right URL | |
8 var css = document.getElementById(event.data.id); | |
9 if(!css) { | |
10 css = document.createElement('style'); | |
11 css.setAttribute('type', 'text/css'); | |
12 css.setAttribute('id', event.data.id); | |
13 css.setAttribute('class', 'OAB'); //To allow easy remova
l by the user to view the original source code | |
14 css.appendChild(document.createTextNode(event.data.reply
)); | |
15 try { | |
16 document.getElementsByTagName('html')[0].getElem
entsByTagName('head')[0].appendChild(css); //Only append if the file is an HTML
file | |
17 //opera.postError('INJECTED: CSS added - ' + eve
nt.data.id); | |
18 } | |
19 catch(e) {} | |
20 } | |
21 else { | |
22 css.innerHTML = event.data.reply; | |
23 //opera.postError('INJECTED: CSS updated - ' + event.dat
a.id); | |
24 } | |
25 } | |
26 else if(event.data.request == 'ping') { | |
27 if(event.data.type == 'css') | |
28 event.source.postMessage({request: 'css', url: document.
location.href}); | |
29 } | |
30 }; | |
31 | |
32 opera.extension.postMessage({request: 'css', url: document.location.href}); | |
OLD | NEW |