Index: files/background.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/files/background.js |
@@ -0,0 +1,112 @@ |
+/*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)) |
+ 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)) |
+ 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); |
+ 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')) { |
+ if(!preferences.exist('version')) { // New install |
+ lists.enable('easy'); |
+ } |
+ else { //Update from previous versions |
+ if(preferences.float('version') < 0.60) { //Updating from versions before Next, only enabled lists are ported |
+ var enabledLists = new Array(); |
+ for(key in sources.all()) { //Notes all enabled lists |
+ if(preferences.bool(key)) |
+ enabledLists.push(key); |
+ } |
+ var enabledCss = new Array(); |
+ for(key in sources.css) { //Notes all enabled lists |
+ if(preferences.bool(key)) |
+ enabledCss.push(key); |
+ } |
+ var whitelist = lists.whitelist.get(); |
+ |
+ widget.preferences.clear(); //Removes all old preferences |
+ |
+ for(i in enabledLists) { //Enable all previously enabled lists |
+ lists.enable(enabledLists[i]); |
+ } |
+ for(i in enabledCss) { //Enable all previously enabled lists |
+ css.enable(enabledCss[i], false); |
+ } |
+ lists.whitelist.set(whitelist); |
+ } |
+ else if(preferences.float('version') <= 0.71) { //Updating from versions before lists merge and change |
+ widget.preferences.clear(); //Removes all old preferences |
+ // As no stable version exist between 0.52 and 0.71, the settings are not ported and simply removed from the extension |
+ } |
+ |
+ } |
+ //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 |
+ 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 |
+} |
+ |
+lists.setup(); //Enables all lists |
+updateAll(); //Sets update intervals |