mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 06:18:35 +02:00
added short comments for all JS functions
This commit is contained in:
@@ -1,18 +1,33 @@
|
||||
// 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);
|
||||
|
||||
/*
|
||||
beastify():
|
||||
* removes every node in the document.body,
|
||||
* then inserts the chosen beast
|
||||
* then removes itself as a listener
|
||||
*/
|
||||
function beastify(request, sender, sendResponse) {
|
||||
removeEverything();
|
||||
insertBeast(beastNameToURL(request.beast));
|
||||
chrome.runtime.onMessage.removeListener(beastify);
|
||||
}
|
||||
|
||||
/*
|
||||
Remove every node under document.body
|
||||
*/
|
||||
function removeEverything() {
|
||||
while (document.body.firstChild) {
|
||||
document.body.firstChild.remove();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Given a URL to a beast image, create and style an IMG node pointing to
|
||||
that image, then insert the node into the document.
|
||||
*/
|
||||
function insertBeast(beastURL) {
|
||||
var beastImage = document.createElement("img");
|
||||
beastImage.setAttribute("src", beastURL);
|
||||
@@ -21,6 +36,9 @@ function insertBeast(beastURL) {
|
||||
document.body.appendChild(beastImage);
|
||||
}
|
||||
|
||||
/*
|
||||
Given the name of a beast, get the URL to the corresponding image.
|
||||
*/
|
||||
function beastNameToURL(beastName) {
|
||||
switch (beastName) {
|
||||
case "Frog":
|
||||
|
||||
Reference in New Issue
Block a user