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

Delta Between Two Patch Sets: files/lists.js

Issue 8493027: Acquired Opera AdBlock code (Closed)
Left Patch Set: Created Oct. 2, 2012, 1:15 p.m.
Right Patch Set: Created Oct. 8, 2012, 5:58 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « files/download.js ('k') | files/parse.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 const lists = { 1 const lists = {
2 apply: function(key, add) { 2 apply: function(key, add) {
3 //opera.postError(key + ' will be ' + (add ? 'added' : 'removed' )); 3 //opera.postError(key + ' will be ' + (add ? 'added' : 'removed' ));
4 var content = preferences.array(key + '-content'); 4 var content = preferences.array(key + '-content');
5 switch(sources.style[key]) { 5 switch(sources.style[key]) {
6 case 'adblock': 6 case 'adblock':
7 » » » » for(pos in content) 7 » » » » if(opera.version() >= 12.1) {
8 » » » » » parse.adblock(content[pos], add); 8 » » » » » for(pos in content)
9 » » » » break; 9 » » » » » » parse.adblock(content[pos], add) ;
10 » » » » » break;
11 » » » » }
12 » » » » else {
13 » » » » » for(pos in content)
14 » » » » » » parse.adblockOld(content[pos], a dd);
15 » » » » » break;
16 » » » » }
10 case 'opera': 17 case 'opera':
11 for(pos in content) { 18 for(pos in content) {
12 if(add) 19 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]); 20 opera.extension.urlfilter.block. add(content[pos]);
14 else 21 else
15 opera.extension.urlfilter.block. remove(content[pos]); 22 opera.extension.urlfilter.block. remove(content[pos]);
16 } 23 }
17 break; 24 break;
18 } 25 }
19 //opera.postError(key + ' was ' + (add ? 'added' : 'removed') + ' with success (' + pos + ' elements)'); 26 //opera.postError(key + ' was ' + (add ? 'added' : 'removed') + ' with success (' + pos + ' elements)');
20 }, 27 },
21 setup: function(key) { 28 setup: function(key) {
22 for(key in sources.all()) { 29 for(key in sources.all()) {
23 if(this.status(key)) 30 if(this.status(key))
24 this.apply(key, true); 31 this.apply(key, true);
25 } 32 }
26 }, 33 },
27 whitelist: { 34 whitelist: {
28 get: function() { 35 get: function() {
29 return preferences.array('whitelist-content'); 36 return preferences.array('whitelist-content');
30 }, 37 },
31 set: function(array) { 38 set: function(array) {
32 preferences.array('whitelist-content', array); 39 preferences.array('whitelist-content', array);
33 }, 40 },
34 apply: function() { 41 apply: function() {
35 var content = this.get(); 42 var content = this.get();
36 for(i in content) 43 for(i in content)
37 opera.extension.urlfilter.allow.add(content[i]); 44 opera.extension.urlfilter.allow.add(content[i]);
Felix Dahlke 2012/10/05 15:47:16 See comment in parse.js on urlfilter.allow.
38 }, 45 },
39 add: function(element, useMessage) { 46 add: function(element, useMessage) {
40 var content = this.get(); 47 var content = this.get();
41 if(content.indexOf(element) == -1) { 48 if(content.indexOf(element) == -1) {
42 content.push(element); 49 content.push(element);
43 this.set(content); 50 this.set(content);
44 if(useMessage) 51 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}); 52 opera.extension.postMessage({request: 'w hitelist', type: 'add', rule: element});
46 else 53 else
47 opera.extension.urlfilter.allow.add(rule ); 54 opera.extension.urlfilter.allow.add(rule );
48 } 55 }
49 }, 56 },
50 remove: function(element, useMessage) { 57 remove: function(element, useMessage) {
51 var content = this.get(); 58 var content = this.get();
52 var position = content.indexOf(element); 59 var position = content.indexOf(element);
53 if(position != -1) { 60 if(position != -1) {
54 content.splice(position, 1); 61 content.splice(position, 1);
55 this.set(content); 62 this.set(content);
56 if(useMessage) 63 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}); 64 opera.extension.postMessage({request: 'w hitelist', type: 'remove', rule: element});
58 else 65 else
59 opera.extension.urlfilter.allow.remove(r ule); 66 opera.extension.urlfilter.allow.remove(r ule);
60 } 67 }
61 }/*, 68 }/*,
62 make: function(url) { 69 make: function(url) {
63 return url.replace(/[a-z]+:\/\//, '||').replace(/\/.*$/, "^*"); 70 return url.replace(/[a-z]+:\/\//, '||').replace(/\/.*$/, "^*");
64 }*/ 71 }*/
65 }, 72 },
66 refresh: function() { 73 refresh: function() {
67 var success = true; 74 var success = true;
68 for(key in sources.all()) { 75 for(key in sources.all()) {
69 if(preferences.bool(key)){ //If the list is enabled, upd ate it 76 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 77 if(!this.update(key)) //In case of error with th e update
71 success = false; 78 success = false;
Felix Dahlke 2012/10/05 15:47:16 We can just return false here, avoiding the succes
72 } 79 }
73 else //If the list is disabled, remove it 80 else //If the list is disabled, remove it
74 this.disable(key); 81 this.disable(key);
75 } 82 }
76 return success; 83 return success;
77 }, 84 },
78 time: function(key) { 85 time: function(key) {
79 return preferences.int(key + '-time'); 86 return preferences.int(key + '-time');
80 }, 87 },
81 update: function(key) { 88 update: function(key) {
82 var value; 89 var value;
83 if(sources.style[key] == 'opera') 90 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 91 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') 92 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 93 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")); 94 //opera.postError(value.join("\n"));
88 if(value instanceof Array) { 95 if(value instanceof Array) {
89 preferences.array(key + '-content', value); 96 preferences.array(key + '-content', value);
90 preferences.string(key + '-time', getTime()); 97 preferences.string(key + '-time', getTime());
91 this.apply(key, true); 98 this.apply(key, true);
92 return true; 99 return true;
93 } 100 }
94 else 101 else
Felix Dahlke 2012/10/05 15:47:16 else is not necessary here. In fact, the return va
95 return false; 102 return false;
96 }, 103 },
97 status: function(key) { 104 status: function(key) {
Felix Dahlke 2012/10/05 15:47:16 How about "enabled" instead of "status"? Status i
98 return preferences.bool(key); 105 return preferences.bool(key);
99 }, 106 },
100 disable: function(key) { //Disables a source 107 disable: function(key) { //Disables a source
101 this.apply(key, false); 108 this.apply(key, false);
102 preferences.remove(key + '-time'); 109 preferences.remove(key + '-time');
103 preferences.remove(key + '-content'); 110 preferences.remove(key + '-content');
104 preferences.bool(key, false); 111 preferences.bool(key, false);
105 return true; 112 return true;
Felix Dahlke 2012/10/05 15:47:16 The function will always return true no matter wha
106 }, 113 },
107 enable: function(key) { //Enables a source 114 enable: function(key) { //Enables a source
108 this.update(key); 115 this.update(key);
109 preferences.bool(key, true); 116 preferences.bool(key, true);
110 } 117 }
111 }; 118 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld