diff --git a/chill-out/README.md b/chill-out/README.md new file mode 100644 index 0000000..4005df3 --- /dev/null +++ b/chill-out/README.md @@ -0,0 +1 @@ +# chill-out diff --git a/chill-out/background.js b/chill-out/background.js new file mode 100644 index 0000000..4920409 --- /dev/null +++ b/chill-out/background.js @@ -0,0 +1,60 @@ +var DELAY = 0.1; +var CATGIFS = "http://chilloutandwatchsomecatgifs.com/"; + +/* +Start-stop for the currently active tab, whenever this script is run. +*/ +chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + startStopAlarm(tabs[0].id); +}); + +/* +Start-stop for the currently active tab, whenever the user navigates. +*/ +chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { + if (!changeInfo.url) { + return; + } + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + if (tabId == tabs[0].id) { + startStopAlarm(tabId); + } + }); +}); + +/* +Start-stop for the currently active tab, whenever a new tab becomes active. +*/ +chrome.tabs.onActivated.addListener(function (activeInfo) { + startStopAlarm(activeInfo.tabId); +}); + +/* +Start-stop: clear all alarms, +then set a new alarm for the given tab. +*/ +function startStopAlarm(tabId) { + chrome.pageAction.hide(tabId); + chrome.alarms.clearAll(); + chrome.tabs.get(tabId, function(tab) { + if (tab.url != CATGIFS) { + chrome.alarms.create(tabId, {delayInMinutes: DELAY}); + } + }); +} + +/* +On alarm, show the page action. +*/ +chrome.alarms.onAlarm.addListener(function(alarm) { + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + chrome.pageAction.show(alarm.name); + }); +}); + +/* +On page action click, navigate the corresponding tab to the cat gifs. +*/ +chrome.pageAction.onClicked.addListener(function () { + chrome.tabs.update({url: CATGIFS}); +}); diff --git a/chill-out/button/LICENSE b/chill-out/button/LICENSE new file mode 100644 index 0000000..50b37ce --- /dev/null +++ b/chill-out/button/LICENSE @@ -0,0 +1 @@ +The icon "chillout.png" is taken from the IconBeast Lite iconset, and used under the terms of its license (http://www.iconbeast.com/faq/), with a link back to the website: http://www.iconbeast.com/free/. diff --git a/chill-out/button/chillout.png b/chill-out/button/chillout.png new file mode 100644 index 0000000..bcf6379 Binary files /dev/null and b/chill-out/button/chillout.png differ diff --git a/chill-out/manifest.json b/chill-out/manifest.json new file mode 100644 index 0000000..edc4c28 --- /dev/null +++ b/chill-out/manifest.json @@ -0,0 +1,26 @@ +{ + + "manifest_version": 2, + "name": "chillout-page-action", + "version": "1.0", + + "applications": { + "gecko": { + "id": "chillout-page-action@mozilla.org" + } + }, + + "permissions": [ + "tabs" + ], + + "page_action": { + "default_icon": "button/chillout.png", + "default_title": "Chill out" + }, + + "background": { + "scripts": ["background.js"] + } + +}