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

Unified Diff: files/background.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
« no previous file with comments | « design/notify.css ('k') | files/button.js » ('j') | files/lists.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: files/background.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/files/background.js
@@ -0,0 +1,85 @@
+/*opera.extension.windows.addEventListener( "focus", function(){
+ opera.postError('Focus: ' + opera.extension.tabs.getSelected().url);
+});
+opera.extension.windows.addEventListener( "change", function(){
+ opera.postError('Change: ' + opera.extension.tabs.getSelected());
+});
+opera.extension.windows.addEventListener( "create", function(){
+ opera.postError('Create: ' + opera.extension.tabs.getSelected());
+});
+opera.extension.windows.addEventListener( "update", function(){
+ opera.postError('Update: ' + opera.extension.tabs.getSelected());
+});*/
+
+opera.extension.onmessage = function (event) {
+ button.update();
+ //opera.postError('BACKGROUND: got a ' + event.data.request + ' request');
+ switch(event.data.request) {
+ case 'css':
+ //opera.postError('BACKGROUND: got reply from ' + event.data.url);
+ if(whitelist.check(event.data.url))
Felix Dahlke 2012/10/05 15:47:16 In all postMessage invocations, just the reply is
+ event.source.postMessage({request: event.data.request, reply: css.personal().join("\n"), id: 'OAB_Perso'});
+ else
+ event.source.postMessage({request: event.data.request, reply: '', id: 'OAB_Perso'});
+
+ for(key in sources.css) { //Sends them one by one to avoid contamination in cases where one is corrupted
+ if(css.status(key) && whitelist.check(event.data.url))
Felix Dahlke 2012/10/05 15:47:16 whitelist.check(event.data.url) should be stored i
+ event.source.postMessage({request: event.data.request, reply: css.get(key).join("\n"), id: 'OAB_' + key});
+ else
+ event.source.postMessage({request: event.data.request, reply: '', id: 'OAB_' + key});
+ }
+ break;
+ case 'ping':
+ //opera.postError('BACKGROUND: ping received');
+ opera.extension.broadcastMessage({request: 'ping', type: event.data.type});
+ break;
+ case 'list':
+ if(event.data.enable)
+ lists.enable(event.data.key);
+ else
+ lists.disable(event.data.key);
+ break;
+ case 'whitelist': //request: whitelist // type: add | remove // rule: RULE
+ if(event.data.type == 'add')
+ opera.extension.urlfilter.allow.add(event.data.rule);
Felix Dahlke 2012/10/05 15:47:16 See comment in parse.js on urlfilter.allow.
+ else if(event.data.type == 'remove')
+ opera.extension.urlfilter.allow.remove(event.data.rule);
+ break;
+ case 'button':
+ if(event.data.enable)
+ button.enable();
+ else
+ button.disable();
+ }
+}
+
+if(window.widget.version != preferences.string('version')) { //New install
+ //Enables Russian lists for new installs on Russian computers
+ if(window.navigator.language.substring(0,2).toLowerCase() == 'ru') {
Felix Dahlke 2012/10/05 15:47:16 This is something we'll want to do for all locales
+ preferences.bool('fanboy-ru', true);
+ preferences.bool('easy-ru-css', true);
+ }
+
+ //Updates the version
+ preferences.string('version', window.widget.version);
+}
+
+function updateAll() {
+ //opera.postError('updateAll() called');
+ for(key in sources.css) {
+ if(css.status(key) && getTime() - css.time(key) > preferences.int('interval')) { //If the list is enabled
Felix Dahlke 2012/10/05 15:47:16 getTime() and preferences.int('interval') should b
+ css.update(key);
+ //opera.postError(key + ' updated');
+ }
+ }
+ for(key in sources.all()) {
+ if(lists.status(key) && getTime() - lists.time(key) > preferences.int('interval')) { //If the list is enabled
+ lists.update(key);
+ //opera.postError(key + ' updated');
+ }
+ }
+ window.setTimeout('updateAll()', preferences.int('interval') / 12); //Verifies required updates every 1/12 of the update interval
Felix Dahlke 2012/10/05 15:47:16 Better use window.setTimeout(updateAll, ...), pass
+}
+
+lists.setup(); //Enables all lists
+updateAll(); //Sets update intervals
« no previous file with comments | « design/notify.css ('k') | files/button.js » ('j') | files/lists.js » ('J')

Powered by Google App Engine
This is Rietveld