1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
function do_something (request, sender, sendResponse) {
//removeEverything();
change(request.myparam);
console.log("DONE!!");
browser.runtime.onMessage.removeListener(do_something);
}
function removeEverything () {
while (document.body.firstChild) {
document.body.firstChild.remove();
}
}
function change (param) {
document.getElementById("title").setAttribute("background-color", "#809060");
console.log("param: " + param);
document.getElementById("title").setAttribute("background-color", "#FF0000");
}
/*
Assign do_something() as a listener for messages from the extension.
*/
browser.runtime.onMessage.addListener(do_something);
| >
>
|
<
>
>
<
|
>
|
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| import { echo } from "../mymodule";
echo("CONTENT SCRIPRT!!!");
function handleMessage2 (oRequest, xSender, sendResponse) {
console.log(`[Content script] received: ${oRequest.content}`);
change(request.myparam);
//browser.runtime.onMessage.removeListener(handleMessage);
sendResponse({response: "response from content script"});
}
function removeEverything () {
while (document.body.firstChild) {
document.body.firstChild.remove();
}
}
function change (param) {
document.getElementById("title").setAttribute("background-color", "#809060");
console.log("param: " + param);
document.getElementById("title").setAttribute("background-color", "#FF0000");
}
/*
Assign do_something() as a listener for messages from the extension.
*/
browser.runtime.onMessage.addListener(handleMessage2);
|