OLD | NEW |
(Empty) | |
| 1 const lists = { |
| 2 apply: function(key, add) { |
| 3 //opera.postError(key + ' will be ' + (add ? 'added' : 'removed'
)); |
| 4 var content = preferences.array(key + '-content'); |
| 5 switch(sources.style[key]) { |
| 6 case 'adblock': |
| 7 if(opera.version() >= 12.1) { |
| 8 for(pos in content) |
| 9 parse.adblock(content[pos], add)
; |
| 10 break; |
| 11 } |
| 12 else { |
| 13 for(pos in content) |
| 14 parse.adblockOld(content[pos], a
dd); |
| 15 break; |
| 16 } |
| 17 case 'opera': |
| 18 for(pos in content) { |
| 19 if(add) |
| 20 opera.extension.urlfilter.block.
add(content[pos]); |
| 21 else |
| 22 opera.extension.urlfilter.block.
remove(content[pos]); |
| 23 } |
| 24 break; |
| 25 } |
| 26 //opera.postError(key + ' was ' + (add ? 'added' : 'removed') +
' with success (' + pos + ' elements)'); |
| 27 }, |
| 28 setup: function(key) { |
| 29 for(key in sources.all()) { |
| 30 if(this.status(key)) |
| 31 this.apply(key, true); |
| 32 } |
| 33 }, |
| 34 whitelist: { |
| 35 get: function() { |
| 36 return preferences.array('whitelist-content'); |
| 37 }, |
| 38 set: function(array) { |
| 39 preferences.array('whitelist-content', array); |
| 40 }, |
| 41 apply: function() { |
| 42 var content = this.get(); |
| 43 for(i in content) |
| 44 opera.extension.urlfilter.allow.add(content[i]); |
| 45 }, |
| 46 add: function(element, useMessage) { |
| 47 var content = this.get(); |
| 48 if(content.indexOf(element) == -1) { |
| 49 content.push(element); |
| 50 this.set(content); |
| 51 if(useMessage) |
| 52 opera.extension.postMessage({request: 'w
hitelist', type: 'add', rule: element}); |
| 53 else |
| 54 opera.extension.urlfilter.allow.add(rule
); |
| 55 } |
| 56 }, |
| 57 remove: function(element, useMessage) { |
| 58 var content = this.get(); |
| 59 var position = content.indexOf(element); |
| 60 if(position != -1) { |
| 61 content.splice(position, 1); |
| 62 this.set(content); |
| 63 if(useMessage) |
| 64 opera.extension.postMessage({request: 'w
hitelist', type: 'remove', rule: element}); |
| 65 else |
| 66 opera.extension.urlfilter.allow.remove(r
ule); |
| 67 } |
| 68 }/*, |
| 69 make: function(url) { |
| 70 return url.replace(/[a-z]+:\/\//, '||').replace(/\/.*$/,
"^*"); |
| 71 }*/ |
| 72 }, |
| 73 refresh: function() { |
| 74 var success = true; |
| 75 for(key in sources.all()) { |
| 76 if(preferences.bool(key)){ //If the list is enabled, upd
ate it |
| 77 if(!this.update(key)) //In case of error with th
e update |
| 78 success = false; |
| 79 } |
| 80 else //If the list is disabled, remove it |
| 81 this.disable(key); |
| 82 } |
| 83 return success; |
| 84 }, |
| 85 time: function(key) { |
| 86 return preferences.int(key + '-time'); |
| 87 }, |
| 88 update: function(key) { |
| 89 var value; |
| 90 if(sources.style[key] == 'opera') |
| 91 value = download(sources.url(key)).replace(/(^|\n);.*?(\
n|$)/gm, '$1').split('[exclude]')[1].split('\n'); //Pre-remove comments to save
space |
| 92 else if(sources.style[key] == 'adblock') |
| 93 value = download(sources.url(key)).replace(/^\[adblock.*
\n/im, '').replace(/(^|\n)(!|##|#@#).*?(\n|$)/gm, '$1').split('\n'); //Pre-remov
e comments and unsupported to save space |
| 94 //opera.postError(value.join("\n")); |
| 95 if(value instanceof Array) { |
| 96 preferences.array(key + '-content', value); |
| 97 preferences.string(key + '-time', getTime()); |
| 98 this.apply(key, true); |
| 99 return true; |
| 100 } |
| 101 else |
| 102 return false; |
| 103 }, |
| 104 status: function(key) { |
| 105 return preferences.bool(key); |
| 106 }, |
| 107 disable: function(key) { //Disables a source |
| 108 this.apply(key, false); |
| 109 preferences.remove(key + '-time'); |
| 110 preferences.remove(key + '-content'); |
| 111 preferences.bool(key, false); |
| 112 return true; |
| 113 }, |
| 114 enable: function(key) { //Enables a source |
| 115 this.update(key); |
| 116 preferences.bool(key, true); |
| 117 } |
| 118 }; |
OLD | NEW |