Index: files/parse.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/files/parse.js |
@@ -0,0 +1,105 @@ |
+const parse = {/* |
+ opera: function(content, add) { |
+ //if(content.indexOf(';') == 0)//Comment |
+ // return; |
+ if(add) |
+ opera.extension.urlfilter.block.add(content); |
+ else |
+ opera.extension.urlfilter.block.remove(content); |
+ },*/ |
+ adblock: function(content, add) { |
Felix Dahlke
2012/10/05 15:47:16
This function has a lot of code duplication, we sh
|
+ var url = this.wildcard(content.replace(/^@@/, '').replace(/\$.*$/, '')); |
+ //opera.postError(content); |
+ 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); |
Felix Dahlke
2012/10/05 15:47:16
If we're using urlfilter.allow, filters with "adbl
|
+ 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); |
+ } |
+ } |
+ else { |
+ if(content.match(/^@@/)) { |
+ if(add) |
+ opera.extension.urlfilter.allow.add(url); |
Felix Dahlke
2012/10/05 15:47:16
See above.
|
+ else |
+ opera.extension.urlfilter.allow.remove(url); |
+ } |
+ else { |
+ if(add) |
+ opera.extension.urlfilter.block.add(url); |
+ else |
+ opera.extension.urlfilter.block.remove(url); |
+ } |
+ } |
+ }, |
+ 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 | |
Felix Dahlke
2012/10/05 15:47:16
We should generate this 'all' mask from the flags
|
+ 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 |
Felix Dahlke
2012/10/05 15:47:16
What is "TESTED" supposed to mean? That this expre
|
+ 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
|
+ for(j in domains) { |
+ 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
|
+ 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 |
Felix Dahlke
2012/10/05 15:47:16
"TESTED" again? What about bogus or unsupported op
|
+ if(!element.match(/^~/i)) { |
Felix Dahlke
2012/10/05 15:47:16
Case insensitive matching makes no sense for "~".
|
+ if(!additive) { |
+ additive = true; |
+ option['resources'] = 0; |
+ } |
+ 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 ("|="
|
+ } |
+ else if(!additive) |
+ 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
|
+ } |
+ } |
+ return option; |
+ }, |
+ wildcard: function(url) { //TESTED |
Felix Dahlke
2012/10/05 15:47:16
"TESTED" again?
There's a bit of duplication here
|
+ //| 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; |
+ } |
+}; |