Left: | ||
Right: |
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)) | |
Felix Dahlke
2012/10/05 15:47:16
In all postMessage invocations, just the reply is
| |
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)) | |
Felix Dahlke
2012/10/05 15:47:16
whitelist.check(event.data.url) should be stored i
| |
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); | |
Felix Dahlke
2012/10/05 15:47:16
See comment in parse.js on urlfilter.allow.
| |
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')) { //New install | |
57 //Enables Russian lists for new installs on Russian computers | |
58 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
| |
59 preferences.bool('fanboy-ru', true); | |
60 preferences.bool('easy-ru-css', true); | |
61 } | |
62 | |
63 //Updates the version | |
64 preferences.string('version', window.widget.version); | |
65 } | |
66 | |
67 function updateAll() { | |
68 //opera.postError('updateAll() called'); | |
69 for(key in sources.css) { | |
70 if(css.status(key) && getTime() - css.time(key) > preferences.in t('interval')) { //If the list is enabled | |
Felix Dahlke
2012/10/05 15:47:16
getTime() and preferences.int('interval') should b
| |
71 css.update(key); | |
72 //opera.postError(key + ' updated'); | |
73 } | |
74 } | |
75 for(key in sources.all()) { | |
76 if(lists.status(key) && getTime() - lists.time(key) > preference s.int('interval')) { //If the list is enabled | |
77 lists.update(key); | |
78 //opera.postError(key + ' updated'); | |
79 } | |
80 } | |
81 window.setTimeout('updateAll()', preferences.int('interval') / 12); //Ve rifies required updates every 1/12 of the update interval | |
Felix Dahlke
2012/10/05 15:47:16
Better use window.setTimeout(updateAll, ...), pass
| |
82 } | |
83 | |
84 lists.setup(); //Enables all lists | |
85 updateAll(); //Sets update intervals | |
OLD | NEW |