OLD | NEW |
(Empty) | |
| 1 /*opera.extension.windows.addEventListener( "focus", function(){ |
| 2 opera.postError('Focus: ' + opera.extension.tabs.getSelected().url); |
| 3 }); |
| 4 opera.extension.windows.addEventListener( "change", function(){ |
| 5 opera.postError('Change: ' + opera.extension.tabs.getSelected()); |
| 6 }); |
| 7 opera.extension.windows.addEventListener( "create", function(){ |
| 8 opera.postError('Create: ' + opera.extension.tabs.getSelected()); |
| 9 }); |
| 10 opera.extension.windows.addEventListener( "update", function(){ |
| 11 opera.postError('Update: ' + opera.extension.tabs.getSelected()); |
| 12 });*/ |
| 13 |
| 14 opera.extension.onmessage = function (event) { |
| 15 button.update(); |
| 16 //opera.postError('BACKGROUND: got a ' + event.data.request + ' request'
); |
| 17 switch(event.data.request) { |
| 18 case 'css': |
| 19 //opera.postError('BACKGROUND: got reply from ' + event.
data.url); |
| 20 if(whitelist.check(event.data.url)) |
| 21 event.source.postMessage({request: event.data.re
quest, reply: css.personal().join("\n"), id: 'OAB_Perso'}); |
| 22 else |
| 23 event.source.postMessage({request: event.data.re
quest, reply: '', id: 'OAB_Perso'}); |
| 24 |
| 25 for(key in sources.css) { //Sends them one by one to avo
id contamination in cases where one is corrupted |
| 26 if(css.status(key) && whitelist.check(event.data
.url)) |
| 27 event.source.postMessage({request: event
.data.request, reply: css.get(key).join("\n"), id: 'OAB_' + key}); |
| 28 else |
| 29 event.source.postMessage({request: event
.data.request, reply: '', id: 'OAB_' + key}); |
| 30 } |
| 31 break; |
| 32 case 'ping': |
| 33 //opera.postError('BACKGROUND: ping received'); |
| 34 opera.extension.broadcastMessage({request: 'ping', type:
event.data.type}); |
| 35 break; |
| 36 case 'list': |
| 37 if(event.data.enable) |
| 38 lists.enable(event.data.key); |
| 39 else |
| 40 lists.disable(event.data.key); |
| 41 break; |
| 42 case 'whitelist': //request: whitelist // type: add | remove //
rule: RULE |
| 43 if(event.data.type == 'add') |
| 44 opera.extension.urlfilter.allow.add(event.data.r
ule); |
| 45 else if(event.data.type == 'remove') |
| 46 opera.extension.urlfilter.allow.remove(event.dat
a.rule); |
| 47 break; |
| 48 /*case 'button': |
| 49 if(event.data.enable) |
| 50 button.enable(); |
| 51 else |
| 52 button.disable();*/ |
| 53 } |
| 54 } |
| 55 |
| 56 if(window.widget.version != preferences.string('version')) { |
| 57 if(!preferences.exist('version')) { // New install |
| 58 lists.enable('easy'); |
| 59 } |
| 60 else { //Update from previous versions |
| 61 if(preferences.float('version') < 0.60) { //Updating from versi
ons before Next, only enabled lists are ported |
| 62 var enabledLists = new Array(); |
| 63 for(key in sources.all()) { //Notes all enabled lists |
| 64 if(preferences.bool(key)) |
| 65 enabledLists.push(key); |
| 66 } |
| 67 var enabledCss = new Array(); |
| 68 for(key in sources.css) { //Notes all enabled lists |
| 69 if(preferences.bool(key)) |
| 70 enabledCss.push(key); |
| 71 } |
| 72 var whitelist = lists.whitelist.get(); |
| 73 |
| 74 widget.preferences.clear(); //Removes all old preference
s |
| 75 |
| 76 for(i in enabledLists) { //Enable all previously enabled
lists |
| 77 lists.enable(enabledLists[i]); |
| 78 } |
| 79 for(i in enabledCss) { //Enable all previously enabled l
ists |
| 80 css.enable(enabledCss[i], false); |
| 81 } |
| 82 lists.whitelist.set(whitelist); |
| 83 } |
| 84 else if(preferences.float('version') <= 0.71) { //Updating from
versions before lists merge and change |
| 85 widget.preferences.clear(); //Removes all old preference
s |
| 86 // As no stable version exist between 0.52 and 0.71, the
settings are not ported and simply removed from the extension |
| 87 } |
| 88 |
| 89 } |
| 90 //Updates the version |
| 91 preferences.string('version', window.widget.version); |
| 92 } |
| 93 |
| 94 function updateAll() { |
| 95 //opera.postError('updateAll() called'); |
| 96 for(key in sources.css) { |
| 97 if(css.status(key) && getTime() - css.time(key) > preferences.in
t('interval')) { //If the list is enabled |
| 98 css.update(key); |
| 99 //opera.postError(key + ' updated'); |
| 100 } |
| 101 } |
| 102 for(key in sources.all()) { |
| 103 if(lists.status(key) && getTime() - lists.time(key) > preference
s.int('interval')) { //If the list is enabled |
| 104 lists.update(key); |
| 105 //opera.postError(key + ' updated'); |
| 106 } |
| 107 } |
| 108 window.setTimeout('updateAll()', preferences.int('interval') / 12); //Ve
rifies required updates every 1/12 of the update interval |
| 109 } |
| 110 |
| 111 lists.setup(); //Enables all lists |
| 112 updateAll(); //Sets update intervals |
OLD | NEW |