40 lines
891 B
JavaScript
40 lines
891 B
JavaScript
chrome.runtime.onMessage.addListener(
|
|
function (rq) {
|
|
if (rq.action === "content_func_1") {
|
|
alert("content_func_1");
|
|
}
|
|
}
|
|
);
|
|
|
|
|
|
// if (location_startsWith("www.google.com/")) {
|
|
// alert("Google!")
|
|
// }
|
|
|
|
// newTab();
|
|
// openTab("https://news.bbc.co.uk");
|
|
// updateTab("https://news.bbc.co.uk");
|
|
|
|
//alert("content");
|
|
|
|
|
|
function newTab() {
|
|
chrome.runtime.sendMessage({ "action": "new_tab" });
|
|
}
|
|
|
|
function openTab(url) {
|
|
chrome.runtime.sendMessage({ "action": "open_tab", "location": url });
|
|
}
|
|
|
|
function updateTab(url) {
|
|
chrome.runtime.sendMessage({ "action": "update_tab", "location": url });
|
|
}
|
|
|
|
|
|
function location_startsWith(needle) {
|
|
return startsWith(window.location.href, "http://" + needle) || startsWith(window.location.href, "https://" + needle);
|
|
}
|
|
|
|
function startsWith(haystack, needle) {
|
|
return (haystack.toLowerCase().indexOf(needle.toLowerCase()) == 0);
|
|
} |