added short comments for all JS functions

This commit is contained in:
Will Bamberg
2016-01-14 15:06:44 -08:00
parent d65a87520c
commit b636b41f1b
9 changed files with 85 additions and 1 deletions

View File

@@ -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":