This repository has been archived on 2024-03-31. You can view files and clone it, but cannot push or open issues or pull requests.
template-chrome-extension/background.js

67 lines
1.2 KiB
JavaScript

chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([{
conditions: [new chrome.declarativeContent.PageStateMatcher({
pageUrl: {
schemes: ['https', 'http']
}
})],
actions: [new chrome.declarativeContent.ShowPageAction()]
}]);
});
chrome.runtime.onMessage.addListener(
function(rq) {
switch (rq.action) {
case "new_tab":
newTab();
break;
case "open_tab":
openTab(rq.location);
break;
case "update_tab":
updateTab(rq.location);
break;
default: break;
}
}
);
//chrome.pageAction.onClicked.addListener(function() {
/*
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {
"action": "content_func_1"
});
//alert("!bg1");
});
*/
// openTab("popup.html");
//});
function newTab() {
chrome.tabs.create({ "url": "about:blank" });
}
function openTab(url) {
chrome.tabs.create({ "url": url });
}
function updateTab(url) {
chrome.tabs.update({ "url": url });
}