Index: includes/cssFilter.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/includes/cssFilter.js |
@@ -0,0 +1,32 @@ |
+// ==UserScript== |
+// @include * |
+// ==/UserScript== |
+ |
+opera.extension.onmessage = function (event) { |
+ //opera.postError('INJECTED: got a ' + event.data.request + ' request for ' + document.location.href); |
+ if(event.data.request == 'css') {//Ensure the received message is for the right URL |
+ var css = document.getElementById(event.data.id); |
+ if(!css) { |
+ css = document.createElement('style'); |
+ css.setAttribute('type', 'text/css'); |
+ css.setAttribute('id', event.data.id); |
+ css.setAttribute('class', 'OAB'); //To allow easy removal by the user to view the original source code |
+ css.appendChild(document.createTextNode(event.data.reply)); |
+ try { |
+ document.getElementsByTagName('html')[0].getElementsByTagName('head')[0].appendChild(css); //Only append if the file is an HTML file |
+ //opera.postError('INJECTED: CSS added - ' + event.data.id); |
+ } |
+ catch(e) {} |
+ } |
+ else { |
+ css.innerHTML = event.data.reply; |
+ //opera.postError('INJECTED: CSS updated - ' + event.data.id); |
+ } |
+ } |
+ else if(event.data.request == 'ping') { |
+ if(event.data.type == 'css') |
+ event.source.postMessage({request: 'css', url: document.location.href}); |
+ } |
+}; |
+ |
+opera.extension.postMessage({request: 'css', url: document.location.href}); |