Index: files/parse.js |
=================================================================== |
deleted file mode 100644 |
--- a/files/parse.js |
+++ /dev/null |
@@ -1,106 +0,0 @@ |
-const parse = { |
- adblock: function(content, add) { |
- var url = this.wildcard(content.replace(/^@@/, '').replace(/\$.*$/, '')); |
- var option = undefined; |
- if(content.match(/\$/)) { //Is a type-specific rule |
- option = this.options(content.split('$')[1].split(',')); |
- } |
- |
- if(content.match(/^@@/)) { |
- if(add) |
- opera.extension.urlfilter.allow.add(url, option); |
- else |
- opera.extension.urlfilter.allow.remove(url, option); |
- } |
- else { |
- if(add) |
- opera.extension.urlfilter.block.add(url, option); |
- else |
- opera.extension.urlfilter.block.remove(url, option); |
- } |
- }, |
- adblockOld: function(content, add) { //Parsing of the content for older versions of Opera |
- if(!content.match(/^@@/)) { //Whitelist is not supported |
- var url = this.sepCharacters([this.wildcard(content.replace(/\$.*$/, ''))]); //Removes the special rules as those are not supported on older versions of Opera |
- if(add) |
- for(i in url) |
- opera.extension.urlfilter.block.add(url[i]); |
- else |
- for(i in url) |
- opera.extension.urlfilter.block.remove(url[i]); |
- } |
- }, |
- map: { |
- 'script': opera.extension.urlfilter.RESOURCE_SCRIPT, |
- 'image': opera.extension.urlfilter.RESOURCE_IMAGE, |
- 'stylesheet': opera.extension.urlfilter.RESOURCE_STYLESHEET, |
- 'object': opera.extension.urlfilter.RESOURCE_OBJECT, |
- 'xmlhttprequest': opera.extension.urlfilter.RESOURCE_XMLHTTPREQUEST, |
- 'object-subrequest': opera.extension.urlfilter.RESOURCE_OBJECT_SUBREQUEST, |
- 'subdocument': opera.extension.urlfilter.RESOURCE_SUBDOCUMENT, |
- 'document': opera.extension.urlfilter.RESOURCE_DOCUMENT, |
- //'refresh': opera.extension.urlfilter.RESOURCE_REFRESH, |
- //'media': opera.extension.urlfilter.RESOURCE_MEDIA, |
- //'font': opera.extension.urlfilter.RESOURCE_FONT, |
- 'other': opera.extension.urlfilter.RESOURCE_OTHER, |
- 'all': opera.extension.urlfilter.RESOURCE_SCRIPT | opera.extension.urlfilter.RESOURCE_IMAGE | opera.extension.urlfilter.RESOURCE_STYLESHEET | opera.extension.urlfilter.RESOURCE_OBJECT | |
- opera.extension.urlfilter.RESOURCE_XMLHTTPREQUEST | opera.extension.urlfilter.RESOURCE_OBJECT_SUBREQUEST | opera.extension.urlfilter.RESOURCE_SUBDOCUMENT | opera.extension.urlfilter.RESOURCE_DOCUMENT | |
- opera.extension.urlfilter.RESOURCE_REFRESH | opera.extension.urlfilter.RESOURCE_MEDIA | opera.extension.urlfilter.RESOURCE_FONT | opera.extension.urlfilter.RESOURCE_OTHER |
- }, |
- options: function(special) { |
- var option = {excludeDomains: [], includeDomains: [], resources: this.map['all']}; |
- var additive = false; |
- for(i in special) { |
- var element = special[i]; |
- if(element.match(/^domain/i) == 0) { //TESTED |
- var domains = special[i].split('=')[1].split(','); |
- for(j in domains) { |
- if(domains[j].match(/^~/)) //Don't apply on this website |
- option['excludeDomains'].push(domains[j]); |
- else //Apply on this website |
- option['includeDomains'].push(domains[j]); |
- } |
- } |
- else if(!element.match(/^elemhide/i)) { //No support for ElemHide - TESTED |
- if(!element.match(/^~/i)) { |
- if(!additive) { |
- additive = true; |
- option['resources'] = 0; |
- } |
- option['resources'] += this.map[element]; |
- } |
- else if(!additive) |
- option['resources'] -= this.map[element]; |
- } |
- } |
- return option; |
- }, |
- wildcard: function(url) { //TESTED |
- //| at the beginning or end means no wildcard |
- if(!url.match(/^\|\|/)) { //Does not starts with || |
- if(url.match(/^\|/)) //Starts with | |
- url = url.replace(/^\|/, ''); //Remove the | |
- else if(!url.match(/^\*/)) //Avoid ** |
- url = '*' + url; //Add the wildcard |
- } |
- if(url.match(/\|$/)) //Ends with | |
- url = url.replace(/\|$/, ''); //Remove the | |
- else if(!url.match(/\*$/)) //Avoid ** |
- url = url + '*'; //Add the wildcard |
- |
- return url; |
- }, |
- sepCharacters: function(value) { //Separator charactor not supported in <12.1 |
- //var characters = '(){}[],;:!?/|\\"\'#$&*+<=>@^`~'; //WARNING: Using the longer list WILL freeze the browser in some instances |
- var characters = ':?/#&='; //Shorter string to avoid over-processing |
- var values = new Array(); |
- for(i in value) { |
- for(j in characters) { |
- values.push(value[i].replace(/\^/, characters[j])); |
- } |
- if(values[0].match(/\^/)) |
- return this.sepCharacters(values); |
- } |
- return values; |
- } |
-}; |