Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: includes/cssFilter.js

Issue 8493027: Acquired Opera AdBlock code (Closed)
Patch Set: Created Oct. 2, 2012, 1:15 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« files/sources.js ('K') | « images/secure.png ('k') | index.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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});
« files/sources.js ('K') | « images/secure.png ('k') | index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld