Files
webextensions-examples/beastify/content_scripts/clear.js
2016-10-14 01:25:37 +03:00

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);