Skip to content

Instantly share code, notes, and snippets.

Avatar
🤖
beep bop

Kirill Rakhman cypressious

🤖
beep bop
View GitHub Profile
View content_script.kt
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") {
View declarations.kt
external val browser: Browser
external class Browser {
val tabs: Tabs
}
external class Tabs {
fun executeScript(def: Script): Promise<List<Any>>
}
View popup.pt1.kt
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)
}
View popup.pt2.kt
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)
})
}
View manifest.json
{
"manifest_version": 2,
"name": "Beastify",
"version": "1.0",
"permissions": [
"activeTab"
],
"browser_action": {
"default_icon": "icons/beasts-32.png",
View choose_beasts.html
<!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>
View build.gradle
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 Nov 18, 2017
Firefox Webextension in Kotlin
View build.gradle
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 Dec 22, 2016
Gradle Script to wait for Emulator to boot (Android)
View build.gradle
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
View delayUntilTest1.kt
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() }
)
You can’t perform that action at this time.