Commit 7a6a0809 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Transform into a web extension

parent e6d7c4e79bf6
......@@ -8,7 +8,8 @@
},
"permissions": [
"tabs",
"activeTab"
"activeTab",
"webRequest"
],
"browser_action": {
"default_icon": "icons/browser_action_disabled.png",
......@@ -17,7 +18,7 @@
"content_scripts": [
{
"matches": [
"*://*/*"
"<all_urls>"
],
"js": [
"src/content/main.js"
......
var currentTab;
var allTabs = {};
function updateIcon() {
function getTabData(id) {
if (!allTabs.hasOwnProperty(id)) {
allTabs[id] = {
isActive: false
};
}
return allTabs[id];
}
function updateIcon(tabId) {
data = getTabData(tabId);
chrome.browserAction.setIcon({
path: allTabs[currentTab.id] ? {
path: data.isActive ? {
48: "icons/browser_action.png"
} : {
48: "icons/browser_action_disabled.png"
},
tabId: currentTab.id
tabId: tabId
});
}
function toggleActive() {
allTabs[currentTab.id] = !allTabs[currentTab.id];
updateIcon();
function toggleActive(tab) {
data = getTabData(tab.id);
data.isActive = !data.isActive;
updateIcon(tab.id);
}
chrome.browserAction.onClicked.addListener(toggleActive);
function updateActiveTab(tabs) {
function updateTab(tabs) {
if (tabs[0]) {
currentTab = tabs[0];
if (!allTabs.hasOwnProperty(currentTab.id)) {
allTabs[currentTab.id] = false;
}
}
}
var gettingActiveTab = chrome.tabs.query({ active: true, currentWindow: true }, updateTab);
if (gettingActiveTab != null) {
gettingActiveTab.then(updateTab);
}
function onTabActivated(tabId) {
updateIcon(tabId);
}
// listen to tab URL changes
chrome.tabs.onUpdated.addListener(updateActiveTab);
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { onTabActivated(tabId); });
// listen to tab switching
chrome.tabs.onActivated.addListener(updateActiveTab);
// listen for window switching
chrome.windows.onFocusChanged.addListener(updateActiveTab);
// update when the extension loads initially
updateActiveTab();
\ No newline at end of file
chrome.tabs.onActivated.addListener(function (activeInfo) { onTabActivated(activeInfo.tabId); });
function onHeaders(details) {
console.log(details);
}
// listen to received headers
chrome.webRequest.onHeadersReceived.addListener(onHeaders, { urls: ["<all_urls>"] }, ["responseHeaders"]);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment