Skip to content

Instantly share code, notes, and snippets.

@cypressious
Last active November 25, 2017 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cypressious/b9f16a2124e61b0c059870f3a46a2c65 to your computer and use it in GitHub Desktop.
Save cypressious/b9f16a2124e61b0c059870f3a46a2c65 to your computer and use it in GitHub Desktop.
fun main(args: Array<String>) {
if (window.asDynamic().hasRun == true) {
return
}
window.asDynamic().hasRun = true
browser.runtime.onMessage.addListener { message ->
if (message.command === "beastify") {
insertBeast(message.beastURL as String)
} else if (message.command === "reset") {
removeExistingBeasts()
}
}
}
fun insertBeast(beastURL: String) {
removeExistingBeasts()
val beastImage = document.createElement("img") as HTMLElement
beastImage.run {
setAttribute("src", beastURL)
style.height = "100vh"
className = "beastify-image"
}
document.body?.appendChild(beastImage)
}
fun removeExistingBeasts() {
val existingBeasts = document.querySelectorAll(".beastify-image")
for (beast in existingBeasts.asList()) {
beast.parentNode?.removeChild(beast)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment