mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-17 23:08:33 +02:00
try a different way
This commit is contained in:
@@ -1,14 +1,23 @@
|
|||||||
// Assign beastify() as a listener for messages from the extension.
|
// Assign beastify() as a listener for messages from the extension.
|
||||||
chrome.runtime.onMessage.addListener(beastify);
|
chrome.runtime.onMessage.addListener(beastify);
|
||||||
|
|
||||||
function beastify(request, sender, sendResponse) {
|
function beastify(request, sender, sendResponse) {
|
||||||
var beastURL = beastNameToURL(request.beast);
|
removeEverything();
|
||||||
var images = document.querySelectorAll("img");
|
insertBeast(beastNameToURL(request.beast));
|
||||||
for (var i = 0; i < images.length; ++i) {
|
}
|
||||||
images[i].setAttribute("src", beastURL);
|
|
||||||
|
function removeEverything() {
|
||||||
|
while (document.body.firstChild) {
|
||||||
|
document.body.firstChild.remove();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
chrome.runtime.onMessage.removeListener(beastify);
|
|
||||||
|
function insertBeast(beastURL) {
|
||||||
|
var beastImage = document.createElement("img");
|
||||||
|
beastImage.setAttribute("src", beastURL);
|
||||||
|
beastImage.setAttribute("style", "width: 100vw");
|
||||||
|
beastImage.setAttribute("style", "height: 100vh");
|
||||||
|
document.body.appendChild(beastImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
function beastNameToURL(beastName) {
|
function beastNameToURL(beastName) {
|
||||||
|
|||||||
Reference in New Issue
Block a user