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
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") {
external val browser: Browser
external class Browser {
val tabs: Tabs
}
external class Tabs {
fun executeScript(def: Script): Promise<List<Any>>
}
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)
}
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)
})
}
{
"manifest_version": 2,
"name": "Beastify",
"version": "1.0",
"permissions": [
"activeTab"
],
"browser_action": {
"default_icon": "icons/beasts-32.png",
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="choose_beast.css"/>
</head>
<body>
<div id="popup-content">
<div class="button beast">Frog</div>
buildscript {
ext.kotlin_version = '1.1.60'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
@cypressious
cypressious / build.gradle
Last active November 18, 2017 18:52
Firefox Webextension in Kotlin
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.60'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
@cypressious
cypressious / build.gradle
Created December 22, 2016 11:09
Gradle Script to wait for Emulator to boot (Android)
task waitForEmulator << {
def start = System.currentTimeMillis()
while (System.currentTimeMillis() - start < 60000) {
def out = new StringBuilder()
def process = 'adb shell getprop init.svc.bootanim'.execute()
process.consumeProcessOutput(out, null)
process.waitForOrKill(1000)
if (out.toString().trim() == "stopped") return
val mutex = Semaphore(0)
val source = Observable.interval(200, TimeUnit.MILLISECONDS).take(10)
val delayed = source.delayUntil(3L)
println("${System.currentTimeMillis()}: start")
delayed.subscribe(
{ println("${System.currentTimeMillis()}: $it") },
{ println("Failed with $it") },
{ mutex.release() }
)