mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-18 23:38:31 +02:00
29 lines
642 B
JavaScript
29 lines
642 B
JavaScript
chrome.runtime.onMessage.addListener(handleMessage);
|
|
|
|
function handleMessage(request, sender, sendResponse) {
|
|
switch(request.name) {
|
|
case "highlight-para":
|
|
highlightPara();
|
|
break;
|
|
case "show-foo":
|
|
showFoo();
|
|
break;
|
|
case "call-confirm":
|
|
callConfirm();
|
|
}
|
|
}
|
|
|
|
function highlightPara() {
|
|
var pageScriptPara = document.getElementById("page-script-para");
|
|
pageScriptPara.style.backgroundColor = "blue";
|
|
}
|
|
|
|
function showFoo() {
|
|
var output = document.getElementById("output");
|
|
output.textContent = "window.foo=" + window.foo;
|
|
}
|
|
|
|
function callConfirm() {
|
|
window.confirm("Are you sure?");
|
|
}
|