OLD | NEW |
(Empty) | |
| 1 const parse = { |
| 2 adblock: function(content, add) { |
| 3 var url = this.wildcard(content.replace(/^@@/, '').replace(/\$.*
$/, '')); |
| 4 var option = undefined; |
| 5 if(content.match(/\$/)) { //Is a type-specific rule |
| 6 option = this.options(content.split('$')[1].split(',')); |
| 7 } |
| 8 |
| 9 if(content.match(/^@@/)) { |
| 10 if(add) |
| 11 opera.extension.urlfilter.allow.add(url, option)
; |
| 12 else |
| 13 opera.extension.urlfilter.allow.remove(url, opti
on); |
| 14 } |
| 15 else { |
| 16 if(add) |
| 17 opera.extension.urlfilter.block.add(url, option)
; |
| 18 else |
| 19 opera.extension.urlfilter.block.remove(url, opti
on); |
| 20 } |
| 21 }, |
| 22 adblockOld: function(content, add) { //Parsing of the content for older
versions of Opera |
| 23 if(!content.match(/^@@/)) { //Whitelist is not supported |
| 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 |
| 25 if(add) |
| 26 for(i in url) |
| 27 opera.extension.urlfilter.block.add(url[
i]); |
| 28 else |
| 29 for(i in url) |
| 30 opera.extension.urlfilter.block.remove(u
rl[i]); |
| 31 } |
| 32 }, |
| 33 map: { |
| 34 'script': opera.extension.urlfilter.RESOURCE_SCRIPT, |
| 35 'image': opera.extension.urlfilter.RESOURCE_IMAGE, |
| 36 'stylesheet': opera.extension.urlfilter.RESOURCE_STYLESHEET, |
| 37 'object': opera.extension.urlfilter.RESOURCE_OBJECT, |
| 38 'xmlhttprequest': opera.extension.urlfilter.RESOURCE_XMLHTTPREQU
EST, |
| 39 'object-subrequest': opera.extension.urlfilter.RESOURCE_OBJECT_S
UBREQUEST, |
| 40 'subdocument': opera.extension.urlfilter.RESOURCE_SUBDOCUMENT, |
| 41 'document': opera.extension.urlfilter.RESOURCE_DOCUMENT, |
| 42 //'refresh': opera.extension.urlfilter.RESOURCE_REFRESH, |
| 43 //'media': opera.extension.urlfilter.RESOURCE_MEDIA, |
| 44 //'font': opera.extension.urlfilter.RESOURCE_FONT, |
| 45 'other': opera.extension.urlfilter.RESOURCE_OTHER, |
| 46 'all': opera.extension.urlfilter.RESOURCE_SCRIPT | opera.extensi
on.urlfilter.RESOURCE_IMAGE | opera.extension.urlfilter.RESOURCE_STYLESHEET | op
era.extension.urlfilter.RESOURCE_OBJECT | |
| 47 opera.extension.urlfilter.RESOURCE_XMLHTTPREQUEST | oper
a.extension.urlfilter.RESOURCE_OBJECT_SUBREQUEST | opera.extension.urlfilter.RES
OURCE_SUBDOCUMENT | opera.extension.urlfilter.RESOURCE_DOCUMENT | |
| 48 opera.extension.urlfilter.RESOURCE_REFRESH | opera.exten
sion.urlfilter.RESOURCE_MEDIA | opera.extension.urlfilter.RESOURCE_FONT | opera.
extension.urlfilter.RESOURCE_OTHER |
| 49 }, |
| 50 options: function(special) { |
| 51 var option = {excludeDomains: [], includeDomains: [], resources:
this.map['all']}; |
| 52 var additive = false; |
| 53 for(i in special) { |
| 54 var element = special[i]; |
| 55 if(element.match(/^domain/i) == 0) { //TESTED |
| 56 var domains = special[i].split('=')[1].split(','
); |
| 57 for(j in domains) { |
| 58 if(domains[j].match(/^~/)) //Don't apply
on this website |
| 59 option['excludeDomains'].push(do
mains[j]); |
| 60 else //Apply on this website |
| 61 option['includeDomains'].push(do
mains[j]); |
| 62 } |
| 63 } |
| 64 else if(!element.match(/^elemhide/i)) { //No support for
ElemHide - TESTED |
| 65 if(!element.match(/^~/i)) { |
| 66 if(!additive) { |
| 67 additive = true; |
| 68 option['resources'] = 0; |
| 69 } |
| 70 option['resources'] += this.map[element]
; |
| 71 } |
| 72 else if(!additive) |
| 73 option['resources'] -= this.map[element]
; |
| 74 } |
| 75 } |
| 76 return option; |
| 77 }, |
| 78 wildcard: function(url) { //TESTED |
| 79 //| at the beginning or end means no wildcard |
| 80 if(!url.match(/^\|\|/)) { //Does not starts with || |
| 81 if(url.match(/^\|/)) //Starts with | |
| 82 url = url.replace(/^\|/, ''); //Remove the | |
| 83 else if(!url.match(/^\*/)) //Avoid ** |
| 84 url = '*' + url; //Add the wildcard |
| 85 } |
| 86 if(url.match(/\|$/)) //Ends with | |
| 87 url = url.replace(/\|$/, ''); //Remove the | |
| 88 else if(!url.match(/\*$/)) //Avoid ** |
| 89 url = url + '*'; //Add the wildcard |
| 90 |
| 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; |
| 105 } |
| 106 }; |
OLD | NEW |