Skip to content

Instantly share code, notes, and snippets.

View cypressious's full-sized avatar
🤖
beep bop

Kirill Rakhman cypressious

🤖
beep bop
View GitHub Profile
{
"manifest_version": 2,
"name": "Beastify",
"version": "1.0",
"permissions": [
"activeTab"
],
"browser_action": {
"default_icon": "icons/beasts-32.png",
fun listenForClicks() {
document.addEventListener("click", { e ->
val target = e.target as? Element ?: return@addEventListener
browser.tabs.query(Query(active = true, currentWindow = true))
.then({ tabs -> handleClick(target, tabs[0].id) })
.catch(::reportError)
})
}
const val SCRIPT_PATH = "/content_script/build/classes/kotlin/main/min"
fun main(args: Array<String>) {
Promise.all(arrayOf(
browser.tabs.executeScript(Script("$SCRIPT_PATH/kotlin.js")),
browser.tabs.executeScript(Script("$SCRIPT_PATH/content_script.js"))
))
.then({ listenForClicks() })
.catch(::reportExecuteScriptError)
}
external val browser: Browser
external class Browser {
val tabs: Tabs
}
external class Tabs {
fun executeScript(def: Script): Promise<List<Any>>
}
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") {