Index: files/css.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/files/css.js |
@@ -0,0 +1,53 @@ |
+const css = { |
+ get: function(key) { |
+ return preferences.array(key + '-content'); |
+ }, |
+ personal: function() { |
+ return preferences.array('css-perso-content'); |
+ }, |
+ refresh: function() { |
+ var success = true; |
+ for(key in sources.css) { |
+ 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, false); |
+ } |
+ //opera.extension.postMessage({request: 'ping', type: 'css'}); //Make all webpages update |
+ return success; |
+ }, |
+ time: function(key) { |
+ return preferences.int(key + '-time'); |
+ }, |
+ update: function(key) { |
+ //opera.postError('Update called for ' + key); |
+ var value = download(sources.css[key]).replace(/\/\*(.|\n)*?\*\/(\n)?/gm, '').split('\n'); |
+ //opera.postError(value.join("\n")); |
+ if(value instanceof Array) { |
+ preferences.array(key + '-content', value); |
+ preferences.int(key + '-time', getTime()); |
+ return true; |
+ } |
+ else |
+ return false; |
+ }, |
+ status: function(key) { |
+ return preferences.bool(key); |
+ }, |
+ disable: function(key, ping) { //Disables a source |
+ preferences.remove(key + '-time'); |
+ preferences.remove(key + '-content'); |
+ preferences.bool(key, false); |
+ if(ping) |
+ opera.extension.postMessage({request: 'ping', type: 'css'}); |
+ return true; |
+ }, |
+ enable: function(key, ping) { //Enables a source |
+ this.update(key); |
+ preferences.bool(key, true); |
+ if(ping) |
+ opera.extension.postMessage({request: 'ping', type: 'css'}); |
+ } |
+}; |