| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 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) { | |
|
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(/\$.* $/, '')); | |
| 12 //opera.postError(content); | |
| 13 if(content.match(/\$/)) { //Is a type-specific rule | |
| 14 option = this.options(content.split('$')[1].split(',')); | |
| 15 | |
| 16 if(content.match(/^@@/)) { | |
| 17 if(add) | |
| 18 opera.extension.urlfilter.allow.add(url, option); | |
|
Felix Dahlke
2012/10/05 15:47:16
If we're using urlfilter.allow, filters with "adbl
| |
| 19 else | |
| 20 opera.extension.urlfilter.allow.remove(u rl, option); | |
| 21 } | |
| 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 } | |
| 29 else { | |
| 30 if(content.match(/^@@/)) { | |
| 31 if(add) | |
| 32 opera.extension.urlfilter.allow.add(url) ; | |
|
Felix Dahlke
2012/10/05 15:47:16
See above.
| |
| 33 else | |
| 34 opera.extension.urlfilter.allow.remove(u rl); | |
| 35 } | |
| 36 else { | |
| 37 if(add) | |
| 38 opera.extension.urlfilter.block.add(url) ; | |
| 39 else | |
| 40 opera.extension.urlfilter.block.remove(u rl); | |
| 41 } | |
| 42 } | |
| 43 }, | |
| 44 map: { | |
| 45 'script': opera.extension.urlfilter.RESOURCE_SCRIPT, | |
| 46 'image': opera.extension.urlfilter.RESOURCE_IMAGE, | |
| 47 'stylesheet': opera.extension.urlfilter.RESOURCE_STYLESHEET, | |
| 48 'object': opera.extension.urlfilter.RESOURCE_OBJECT, | |
| 49 'xmlhttprequest': opera.extension.urlfilter.RESOURCE_XMLHTTPREQU EST, | |
| 50 'object-subrequest': opera.extension.urlfilter.RESOURCE_OBJECT_S UBREQUEST, | |
| 51 'subdocument': opera.extension.urlfilter.RESOURCE_SUBDOCUMENT, | |
| 52 'document': opera.extension.urlfilter.RESOURCE_DOCUMENT, | |
| 53 //'refresh': opera.extension.urlfilter.RESOURCE_REFRESH, | |
| 54 //'media': opera.extension.urlfilter.RESOURCE_MEDIA, | |
| 55 //'font': opera.extension.urlfilter.RESOURCE_FONT, | |
| 56 '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 | | |
|
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 | | |
| 59 opera.extension.urlfilter.RESOURCE_REFRESH | opera.exten sion.urlfilter.RESOURCE_MEDIA | opera.extension.urlfilter.RESOURCE_FONT | opera. extension.urlfilter.RESOURCE_OTHER | |
| 60 }, | |
| 61 options: function(special) { | |
| 62 var option = {excludeDomains: [], includeDomains: [], resources: this.map['all']}; | |
| 63 var additive = false; | |
| 64 for(i in special) { | |
| 65 var element = special[i]; | |
| 66 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(',' ); | |
|
Felix Dahlke
2012/10/05 15:47:16
What if there is no "="? The above should match fo
| |
| 68 for(j in domains) { | |
| 69 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]); | |
| 71 else //Apply on this website | |
| 72 option['includeDomains'].push(do mains[j]); | |
| 73 } | |
| 74 } | |
| 75 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)) { | |
|
Felix Dahlke
2012/10/05 15:47:16
Case insensitive matching makes no sense for "~".
| |
| 77 if(!additive) { | |
| 78 additive = true; | |
| 79 option['resources'] = 0; | |
| 80 } | |
| 81 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 } | |
| 83 else if(!additive) | |
| 84 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 } | |
| 86 } | |
| 87 return option; | |
| 88 }, | |
| 89 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 | |
| 91 | |
| 92 if(!url.match(/^\|\|/)) { //Does not starts with || | |
| 93 if(url.match(/^\|/)) //Starts with | | |
| 94 url = url.replace(/^\|/, ''); //Remove the | | |
| 95 else if(!url.match(/^\*/)) //Avoid ** | |
| 96 url = '*' + url; //Add the wildcard | |
| 97 } | |
| 98 if(url.match(/\|$/)) //Ends with | | |
| 99 url = url.replace(/\|$/, ''); //Remove the | | |
| 100 else if(!url.match(/\*$/)) //Avoid ** | |
| 101 url = url + '*'; //Add the wildcard | |
| 102 | |
| 103 return url; | |
| 104 } | |
| 105 }; | |
| OLD | NEW |