mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 06:18:35 +02:00
28 lines
547 B
JavaScript
28 lines
547 B
JavaScript
/*
|
|
clear():
|
|
* either reloads or clears the page depending on the request
|
|
*/
|
|
function clear(request, sender, sendResponse) {
|
|
switch (request.type){
|
|
case "Reload":
|
|
location.reload();
|
|
break;
|
|
case "Blank":
|
|
removeEverything();
|
|
break;
|
|
}
|
|
|
|
chrome.runtime.onMessage.removeListener(clear);
|
|
}
|
|
|
|
function removeEverything() {
|
|
while (document.body.firstChild) {
|
|
document.body.firstChild.remove();
|
|
}
|
|
}
|
|
|
|
/*
|
|
Assign clear() as a listener for messages from the extension.
|
|
*/
|
|
chrome.runtime.onMessage.addListener(clear);
|