Index: files/button.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/files/button.js |
@@ -0,0 +1,50 @@ |
+const button = { |
+ update: function(url) { |
+ var url = opera.extension.tabs.getSelected().url; |
+ if(url) { |
+ if(whitelist.check(url)) |
+ buttonElement.icon = '/images/icon18.png'; |
+ else |
+ buttonElement.icon = '/images/icon_green18.png'; |
+ } |
+ else |
+ buttonElement.icon = '/images/icon_yellow18.png'; |
+ }, |
+ click: function() { |
+ this.update(); |
+ }, |
+ enable: function() { |
+ preferences.bool('button', true); |
+ this.display(); |
+ }, |
+ disable: function() { |
+ preferences.bool('button', false); |
+ opera.contexts.toolbar.removeItem(buttonElement); |
+ |
+ opera.extension.windows.removeEventListener('focus', button.update, false); |
+ opera.extension.tabs.removeEventListener('focus', button.update, false); |
+ window.clearInterval(button.update, 1000); |
+ }, |
+ status: function() { |
+ return preferences.bool('button'); |
+ }, |
+ display: function() { |
+ if(this.status()) { |
+ this.update(); |
+ opera.contexts.toolbar.addItem(buttonElement); |
+ |
+ opera.extension.windows.addEventListener('focus', button.update, false); |
+ opera.extension.tabs.addEventListener('focus', button.update, false); |
+ window.setInterval(button.update, 1000); |
+ } |
+ } |
+}; |
+var properties = { |
+ disabled: true, |
+ icon: '/images/icon18.png', |
+ title: translate.get('ext_name') |
+}; |
+var buttonElement = opera.contexts.toolbar.createItem(properties); |
+buttonElement.addEventListener('click', button.click(), false); |
+ |
+button.display(); |