added page action example

This commit is contained in:
Will Bamberg
2015-12-17 23:16:57 -08:00
parent c289fac208
commit 7ad0db26ac
5 changed files with 88 additions and 0 deletions

1
chill-out/README.md Normal file
View File

@@ -0,0 +1 @@
# chill-out

60
chill-out/background.js Normal file
View File

@@ -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});
});

1
chill-out/button/LICENSE Normal file
View File

@@ -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/.

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 B

26
chill-out/manifest.json Normal file
View File

@@ -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"]
}
}