Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: files/lists.js

Issue 8483154: Adding ABP core modules to ABP/Opera (Closed)
Patch Set: Created Oct. 11, 2012, 9:35 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: files/lists.js
===================================================================
deleted file mode 100644
--- a/files/lists.js
+++ /dev/null
@@ -1,118 +0,0 @@
-const lists = {
- apply: function(key, add) {
- //opera.postError(key + ' will be ' + (add ? 'added' : 'removed'));
- var content = preferences.array(key + '-content');
- switch(sources.style[key]) {
- case 'adblock':
- if(opera.version() >= 12.1) {
- for(pos in content)
- parse.adblock(content[pos], add);
- break;
- }
- else {
- for(pos in content)
- parse.adblockOld(content[pos], add);
- break;
- }
- case 'opera':
- for(pos in content) {
- if(add)
- opera.extension.urlfilter.block.add(content[pos]);
- else
- opera.extension.urlfilter.block.remove(content[pos]);
- }
- break;
- }
- //opera.postError(key + ' was ' + (add ? 'added' : 'removed') + ' with success (' + pos + ' elements)');
- },
- setup: function(key) {
- for(key in sources.all()) {
- if(this.status(key))
- this.apply(key, true);
- }
- },
- whitelist: {
- get: function() {
- return preferences.array('whitelist-content');
- },
- set: function(array) {
- preferences.array('whitelist-content', array);
- },
- apply: function() {
- var content = this.get();
- for(i in content)
- opera.extension.urlfilter.allow.add(content[i]);
- },
- add: function(element, useMessage) {
- var content = this.get();
- if(content.indexOf(element) == -1) {
- content.push(element);
- this.set(content);
- if(useMessage)
- opera.extension.postMessage({request: 'whitelist', type: 'add', rule: element});
- else
- opera.extension.urlfilter.allow.add(rule);
- }
- },
- remove: function(element, useMessage) {
- var content = this.get();
- var position = content.indexOf(element);
- if(position != -1) {
- content.splice(position, 1);
- this.set(content);
- if(useMessage)
- opera.extension.postMessage({request: 'whitelist', type: 'remove', rule: element});
- else
- opera.extension.urlfilter.allow.remove(rule);
- }
- }/*,
- make: function(url) {
- return url.replace(/[a-z]+:\/\//, '||').replace(/\/.*$/, "^*");
- }*/
- },
- refresh: function() {
- var success = true;
- for(key in sources.all()) {
- if(preferences.bool(key)){ //If the list is enabled, update it
- if(!this.update(key)) //In case of error with the update
- success = false;
- }
- else //If the list is disabled, remove it
- this.disable(key);
- }
- return success;
- },
- time: function(key) {
- return preferences.int(key + '-time');
- },
- update: function(key) {
- var value;
- if(sources.style[key] == 'opera')
- value = download(sources.url(key)).replace(/(^|\n);.*?(\n|$)/gm, '$1').split('[exclude]')[1].split('\n'); //Pre-remove comments to save space
- else if(sources.style[key] == 'adblock')
- value = download(sources.url(key)).replace(/^\[adblock.*\n/im, '').replace(/(^|\n)(!|##|#@#).*?(\n|$)/gm, '$1').split('\n'); //Pre-remove comments and unsupported to save space
- //opera.postError(value.join("\n"));
- if(value instanceof Array) {
- preferences.array(key + '-content', value);
- preferences.string(key + '-time', getTime());
- this.apply(key, true);
- return true;
- }
- else
- return false;
- },
- status: function(key) {
- return preferences.bool(key);
- },
- disable: function(key) { //Disables a source
- this.apply(key, false);
- preferences.remove(key + '-time');
- preferences.remove(key + '-content');
- preferences.bool(key, false);
- return true;
- },
- enable: function(key) { //Enables a source
- this.update(key);
- preferences.bool(key, true);
- }
-};

Powered by Google App Engine
This is Rietveld