Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 const parse = {/* | 1 const parse = { |
2 » opera: function(content, add) { | |
3 » » //if(content.indexOf(';') == 0)//Comment | |
4 » » //» return; | |
5 » » if(add) | |
6 » » » opera.extension.urlfilter.block.add(content); | |
7 » » else | |
8 » » » opera.extension.urlfilter.block.remove(content); | |
9 » },*/ | |
10 adblock: function(content, add) { | 2 adblock: function(content, add) { |
Felix Dahlke
2012/10/05 15:47:16
This function has a lot of code duplication, we sh
| |
11 var url = this.wildcard(content.replace(/^@@/, '').replace(/\$.* $/, '')); | 3 var url = this.wildcard(content.replace(/^@@/, '').replace(/\$.* $/, '')); |
12 » » //opera.postError(content); | 4 » » var option = undefined; |
13 if(content.match(/\$/)) { //Is a type-specific rule | 5 if(content.match(/\$/)) { //Is a type-specific rule |
14 option = this.options(content.split('$')[1].split(',')); | 6 option = this.options(content.split('$')[1].split(',')); |
15 » » » | 7 » » } |
16 » » » if(content.match(/^@@/)) { | 8 » » |
17 » » » » if(add) | 9 » » if(content.match(/^@@/)) { |
18 » » » » » opera.extension.urlfilter.allow.add(url, option); | 10 » » » if(add) |
Felix Dahlke
2012/10/05 15:47:16
If we're using urlfilter.allow, filters with "adbl
| |
19 » » » » else | 11 » » » » opera.extension.urlfilter.allow.add(url, option) ; |
20 » » » » » opera.extension.urlfilter.allow.remove(u rl, option); | 12 » » » else |
21 » » » } | 13 » » » » opera.extension.urlfilter.allow.remove(url, opti on); |
22 » » » else { | |
23 » » » » if(add) | |
24 » » » » » opera.extension.urlfilter.block.add(url, option); | |
25 » » » » else | |
26 » » » » » opera.extension.urlfilter.block.remove(u rl, option); | |
27 » » » } | |
28 } | 14 } |
29 else { | 15 else { |
30 » » » if(content.match(/^@@/)) { | 16 » » » if(add) |
31 » » » » if(add) | 17 » » » » opera.extension.urlfilter.block.add(url, option) ; |
32 » » » » » opera.extension.urlfilter.allow.add(url) ; | 18 » » » else |
Felix Dahlke
2012/10/05 15:47:16
See above.
| |
33 » » » » else | 19 » » » » opera.extension.urlfilter.block.remove(url, opti on); |
34 » » » » » opera.extension.urlfilter.allow.remove(u rl); | 20 » » } |
35 » » » } | 21 » }, |
36 » » » else { | 22 » adblockOld: function(content, add) { //Parsing of the content for older versions of Opera |
37 » » » » if(add) | 23 » » if(!content.match(/^@@/)) { //Whitelist is not supported |
38 » » » » » opera.extension.urlfilter.block.add(url) ; | 24 » » » var url = this.sepCharacters([this.wildcard(content.repl ace(/\$.*$/, ''))]); //Removes the special rules as those are not supported on o lder versions of Opera |
39 » » » » else | 25 » » » if(add) |
40 » » » » » opera.extension.urlfilter.block.remove(u rl); | 26 » » » » for(i in url) |
41 » » » } | 27 » » » » » opera.extension.urlfilter.block.add(url[ i]); |
28 » » » else | |
29 » » » » for(i in url) | |
30 » » » » » opera.extension.urlfilter.block.remove(u rl[i]); | |
42 } | 31 } |
43 }, | 32 }, |
44 map: { | 33 map: { |
45 'script': opera.extension.urlfilter.RESOURCE_SCRIPT, | 34 'script': opera.extension.urlfilter.RESOURCE_SCRIPT, |
46 'image': opera.extension.urlfilter.RESOURCE_IMAGE, | 35 'image': opera.extension.urlfilter.RESOURCE_IMAGE, |
47 'stylesheet': opera.extension.urlfilter.RESOURCE_STYLESHEET, | 36 'stylesheet': opera.extension.urlfilter.RESOURCE_STYLESHEET, |
48 'object': opera.extension.urlfilter.RESOURCE_OBJECT, | 37 'object': opera.extension.urlfilter.RESOURCE_OBJECT, |
49 'xmlhttprequest': opera.extension.urlfilter.RESOURCE_XMLHTTPREQU EST, | 38 'xmlhttprequest': opera.extension.urlfilter.RESOURCE_XMLHTTPREQU EST, |
50 'object-subrequest': opera.extension.urlfilter.RESOURCE_OBJECT_S UBREQUEST, | 39 'object-subrequest': opera.extension.urlfilter.RESOURCE_OBJECT_S UBREQUEST, |
51 'subdocument': opera.extension.urlfilter.RESOURCE_SUBDOCUMENT, | 40 'subdocument': opera.extension.urlfilter.RESOURCE_SUBDOCUMENT, |
52 'document': opera.extension.urlfilter.RESOURCE_DOCUMENT, | 41 'document': opera.extension.urlfilter.RESOURCE_DOCUMENT, |
53 //'refresh': opera.extension.urlfilter.RESOURCE_REFRESH, | 42 //'refresh': opera.extension.urlfilter.RESOURCE_REFRESH, |
54 //'media': opera.extension.urlfilter.RESOURCE_MEDIA, | 43 //'media': opera.extension.urlfilter.RESOURCE_MEDIA, |
55 //'font': opera.extension.urlfilter.RESOURCE_FONT, | 44 //'font': opera.extension.urlfilter.RESOURCE_FONT, |
56 'other': opera.extension.urlfilter.RESOURCE_OTHER, | 45 'other': opera.extension.urlfilter.RESOURCE_OTHER, |
57 'all': opera.extension.urlfilter.RESOURCE_SCRIPT | opera.extensi on.urlfilter.RESOURCE_IMAGE | opera.extension.urlfilter.RESOURCE_STYLESHEET | op era.extension.urlfilter.RESOURCE_OBJECT | | 46 'all': opera.extension.urlfilter.RESOURCE_SCRIPT | opera.extensi on.urlfilter.RESOURCE_IMAGE | opera.extension.urlfilter.RESOURCE_STYLESHEET | op era.extension.urlfilter.RESOURCE_OBJECT | |
Felix Dahlke
2012/10/05 15:47:16
We should generate this 'all' mask from the flags
| |
58 opera.extension.urlfilter.RESOURCE_XMLHTTPREQUEST | oper a.extension.urlfilter.RESOURCE_OBJECT_SUBREQUEST | opera.extension.urlfilter.RES OURCE_SUBDOCUMENT | opera.extension.urlfilter.RESOURCE_DOCUMENT | | 47 opera.extension.urlfilter.RESOURCE_XMLHTTPREQUEST | oper a.extension.urlfilter.RESOURCE_OBJECT_SUBREQUEST | opera.extension.urlfilter.RES OURCE_SUBDOCUMENT | opera.extension.urlfilter.RESOURCE_DOCUMENT | |
59 opera.extension.urlfilter.RESOURCE_REFRESH | opera.exten sion.urlfilter.RESOURCE_MEDIA | opera.extension.urlfilter.RESOURCE_FONT | opera. extension.urlfilter.RESOURCE_OTHER | 48 opera.extension.urlfilter.RESOURCE_REFRESH | opera.exten sion.urlfilter.RESOURCE_MEDIA | opera.extension.urlfilter.RESOURCE_FONT | opera. extension.urlfilter.RESOURCE_OTHER |
60 }, | 49 }, |
61 options: function(special) { | 50 options: function(special) { |
62 var option = {excludeDomains: [], includeDomains: [], resources: this.map['all']}; | 51 var option = {excludeDomains: [], includeDomains: [], resources: this.map['all']}; |
63 var additive = false; | 52 var additive = false; |
64 for(i in special) { | 53 for(i in special) { |
65 var element = special[i]; | 54 var element = special[i]; |
66 if(element.match(/^domain/i) == 0) { //TESTED | 55 if(element.match(/^domain/i) == 0) { //TESTED |
Felix Dahlke
2012/10/05 15:47:16
What is "TESTED" supposed to mean? That this expre
| |
67 var domains = special[i].split('=')[1].split(',' ); | 56 var domains = special[i].split('=')[1].split(',' ); |
Felix Dahlke
2012/10/05 15:47:16
What if there is no "="? The above should match fo
| |
68 for(j in domains) { | 57 for(j in domains) { |
69 if(domains[j].match(/^~/)) //Don't apply on this website | 58 if(domains[j].match(/^~/)) //Don't apply on this website |
Felix Dahlke
2012/10/05 15:47:16
This could be made more succinct by setting the op
| |
70 option['excludeDomains'].push(do mains[j]); | 59 option['excludeDomains'].push(do mains[j]); |
71 else //Apply on this website | 60 else //Apply on this website |
72 option['includeDomains'].push(do mains[j]); | 61 option['includeDomains'].push(do mains[j]); |
73 } | 62 } |
74 } | 63 } |
75 else if(!element.match(/^elemhide/i)) { //No support for ElemHide - TESTED | 64 else if(!element.match(/^elemhide/i)) { //No support for ElemHide - TESTED |
Felix Dahlke
2012/10/05 15:47:16
"TESTED" again? What about bogus or unsupported op
| |
76 if(!element.match(/^~/i)) { | 65 if(!element.match(/^~/i)) { |
Felix Dahlke
2012/10/05 15:47:16
Case insensitive matching makes no sense for "~".
| |
77 if(!additive) { | 66 if(!additive) { |
78 additive = true; | 67 additive = true; |
79 option['resources'] = 0; | 68 option['resources'] = 0; |
80 } | 69 } |
81 option['resources'] += this.map[element] ; | 70 option['resources'] += this.map[element] ; |
Felix Dahlke
2012/10/05 15:47:16
That's not how a bit flag is added to a mask ("|="
| |
82 } | 71 } |
83 else if(!additive) | 72 else if(!additive) |
84 option['resources'] -= this.map[element] ; | 73 option['resources'] -= this.map[element] ; |
Felix Dahlke
2012/10/05 15:47:16
That's not how a bit flag is removed from a bit ma
| |
85 } | 74 } |
86 } | 75 } |
87 return option; | 76 return option; |
88 }, | 77 }, |
89 wildcard: function(url) { //TESTED | 78 wildcard: function(url) { //TESTED |
Felix Dahlke
2012/10/05 15:47:16
"TESTED" again?
There's a bit of duplication here
| |
90 //| at the beginning or end means no wildcard | 79 //| at the beginning or end means no wildcard |
91 | |
92 if(!url.match(/^\|\|/)) { //Does not starts with || | 80 if(!url.match(/^\|\|/)) { //Does not starts with || |
93 if(url.match(/^\|/)) //Starts with | | 81 if(url.match(/^\|/)) //Starts with | |
94 url = url.replace(/^\|/, ''); //Remove the | | 82 url = url.replace(/^\|/, ''); //Remove the | |
95 else if(!url.match(/^\*/)) //Avoid ** | 83 else if(!url.match(/^\*/)) //Avoid ** |
96 url = '*' + url; //Add the wildcard | 84 url = '*' + url; //Add the wildcard |
97 } | 85 } |
98 if(url.match(/\|$/)) //Ends with | | 86 if(url.match(/\|$/)) //Ends with | |
99 url = url.replace(/\|$/, ''); //Remove the | | 87 url = url.replace(/\|$/, ''); //Remove the | |
100 else if(!url.match(/\*$/)) //Avoid ** | 88 else if(!url.match(/\*$/)) //Avoid ** |
101 url = url + '*'; //Add the wildcard | 89 url = url + '*'; //Add the wildcard |
102 | 90 |
103 return url; | 91 return url; |
92 }, | |
93 sepCharacters: function(value) { //Separator charactor not supported in <12.1 | |
94 //var characters = '(){}[],;:!?/|\\"\'#$&*+<=>@^`~'; //WARNING: Using the longer list WILL freeze the browser in some instances | |
95 var characters = ':?/#&='; //Shorter string to avoid over-proces sing | |
96 var values = new Array(); | |
97 for(i in value) { | |
98 for(j in characters) { | |
99 values.push(value[i].replace(/\^/, characters[j] )); | |
100 } | |
101 if(values[0].match(/\^/)) | |
102 return this.sepCharacters(values); | |
103 } | |
104 return values; | |
104 } | 105 } |
105 }; | 106 }; |
LEFT | RIGHT |