Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 const lists = { | |
2 apply: function(key, add) { | |
3 //opera.postError(key + ' will be ' + (add ? 'added' : 'removed' )); | |
4 var content = preferences.array(key + '-content'); | |
5 switch(sources.style[key]) { | |
6 case 'adblock': | |
7 for(pos in content) | |
8 parse.adblock(content[pos], add); | |
9 break; | |
10 case 'opera': | |
11 for(pos in content) { | |
12 if(add) | |
Felix Dahlke
2012/10/05 15:47:16
Shouldn't this use parse.opera()? It has the very
| |
13 opera.extension.urlfilter.block. add(content[pos]); | |
14 else | |
15 opera.extension.urlfilter.block. remove(content[pos]); | |
16 } | |
17 break; | |
18 } | |
19 //opera.postError(key + ' was ' + (add ? 'added' : 'removed') + ' with success (' + pos + ' elements)'); | |
20 }, | |
21 setup: function(key) { | |
22 for(key in sources.all()) { | |
23 if(this.status(key)) | |
24 this.apply(key, true); | |
25 } | |
26 }, | |
27 whitelist: { | |
28 get: function() { | |
29 return preferences.array('whitelist-content'); | |
30 }, | |
31 set: function(array) { | |
32 preferences.array('whitelist-content', array); | |
33 }, | |
34 apply: function() { | |
35 var content = this.get(); | |
36 for(i in content) | |
37 opera.extension.urlfilter.allow.add(content[i]); | |
Felix Dahlke
2012/10/05 15:47:16
See comment in parse.js on urlfilter.allow.
| |
38 }, | |
39 add: function(element, useMessage) { | |
40 var content = this.get(); | |
41 if(content.indexOf(element) == -1) { | |
42 content.push(element); | |
43 this.set(content); | |
44 if(useMessage) | |
Felix Dahlke
2012/10/05 15:47:16
From what I've seen, useMessage is always true. Wh
| |
45 opera.extension.postMessage({request: 'w hitelist', type: 'add', rule: element}); | |
46 else | |
47 opera.extension.urlfilter.allow.add(rule ); | |
48 } | |
49 }, | |
50 remove: function(element, useMessage) { | |
51 var content = this.get(); | |
52 var position = content.indexOf(element); | |
53 if(position != -1) { | |
54 content.splice(position, 1); | |
55 this.set(content); | |
56 if(useMessage) | |
Felix Dahlke
2012/10/05 15:47:16
As in add, seems to always be true.
| |
57 opera.extension.postMessage({request: 'w hitelist', type: 'remove', rule: element}); | |
58 else | |
59 opera.extension.urlfilter.allow.remove(r ule); | |
60 } | |
61 }/*, | |
62 make: function(url) { | |
63 return url.replace(/[a-z]+:\/\//, '||').replace(/\/.*$/, "^*"); | |
64 }*/ | |
65 }, | |
66 refresh: function() { | |
67 var success = true; | |
68 for(key in sources.all()) { | |
69 if(preferences.bool(key)){ //If the list is enabled, upd ate it | |
70 if(!this.update(key)) //In case of error with th e update | |
71 success = false; | |
Felix Dahlke
2012/10/05 15:47:16
We can just return false here, avoiding the succes
| |
72 } | |
73 else //If the list is disabled, remove it | |
74 this.disable(key); | |
75 } | |
76 return success; | |
77 }, | |
78 time: function(key) { | |
79 return preferences.int(key + '-time'); | |
80 }, | |
81 update: function(key) { | |
82 var value; | |
83 if(sources.style[key] == 'opera') | |
84 value = download(sources.url(key)).replace(/(^|\n);.*?(\ n|$)/gm, '$1').split('[exclude]')[1].split('\n'); //Pre-remove comments to save space | |
Felix Dahlke
2012/10/05 15:47:16
This line definitely deserves its own function, wi
| |
85 else if(sources.style[key] == 'adblock') | |
86 value = download(sources.url(key)).replace(/^\[adblock.* \n/im, '').replace(/(^|\n)(!|##|#@#).*?(\n|$)/gm, '$1').split('\n'); //Pre-remov e comments and unsupported to save space | |
Felix Dahlke
2012/10/05 15:47:16
As above, this deserves its own function and multi
| |
87 //opera.postError(value.join("\n")); | |
88 if(value instanceof Array) { | |
89 preferences.array(key + '-content', value); | |
90 preferences.string(key + '-time', getTime()); | |
91 this.apply(key, true); | |
92 return true; | |
93 } | |
94 else | |
Felix Dahlke
2012/10/05 15:47:16
else is not necessary here. In fact, the return va
| |
95 return false; | |
96 }, | |
97 status: function(key) { | |
Felix Dahlke
2012/10/05 15:47:16
How about "enabled" instead of "status"? Status i
| |
98 return preferences.bool(key); | |
99 }, | |
100 disable: function(key) { //Disables a source | |
101 this.apply(key, false); | |
102 preferences.remove(key + '-time'); | |
103 preferences.remove(key + '-content'); | |
104 preferences.bool(key, false); | |
105 return true; | |
Felix Dahlke
2012/10/05 15:47:16
The function will always return true no matter wha
| |
106 }, | |
107 enable: function(key) { //Enables a source | |
108 this.update(key); | |
109 preferences.bool(key, true); | |
110 } | |
111 }; | |
OLD | NEW |