Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cypressious committed Dec 4, 2017
1 parent 4438247 commit dcef211
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 36 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.1.60'
ext.kotlin_version = '1.2.0'

repositories {
mavenCentral()
Expand All @@ -17,10 +17,12 @@ allprojects {

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
compile 'com.github.cypressious.kotlin-webextensions-declarations:webextensions-declarations:v0.1'
}

compileKotlin2Js {
Expand Down
3 changes: 2 additions & 1 deletion content_script/src/main/kotlin/content_script.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.w3c.dom.HTMLElement
import org.w3c.dom.asList
import webextensions.browser
import kotlin.browser.document
import kotlin.browser.window

Expand All @@ -9,7 +10,7 @@ fun main(args: Array<String>) {
}
window.asDynamic().hasRun = true

browser.runtime.onMessage.addListener { message ->
browser.runtime.onMessage.addListener { message,_,_ ->
if (message.command === "beastify") {
insertBeast(message.beastURL as String)
} else if (message.command === "reset") {
Expand Down
1 change: 0 additions & 1 deletion content_script/src/main/kotlin/helpers.kt

This file was deleted.

1 change: 1 addition & 0 deletions popup/choose_beast.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<p>Try a different page.</p>
</div>
<script src="build/classes/kotlin/main/min/kotlin.js"></script>
<script src="build/classes/kotlin/main/min/declarations.js"></script>
<script src="build/classes/kotlin/main/min/popup.js"></script>
</body>

Expand Down
26 changes: 0 additions & 26 deletions popup/src/main/kotlin/helpers.kt

This file was deleted.

18 changes: 11 additions & 7 deletions popup/src/main/kotlin/popup.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import extensionTypes.InjectDetails
import org.w3c.dom.Element
import tabs.QueryInfo
import webextensions.browser
import kotlin.browser.document
import kotlin.js.Promise


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")),
details = InjectDetails(file = "$SCRIPT_PATH/kotlin.js")),
browser.tabs.executeScript(
details = InjectDetails(file = "$SCRIPT_PATH/declarations.js")),
browser.tabs.executeScript(
Script("$SCRIPT_PATH/content_script.js"))
details = InjectDetails(file = "$SCRIPT_PATH/content_script.js"))
))
.then({ listenForClicks() })
.catch(::reportExecuteScriptError)
Expand All @@ -25,8 +29,8 @@ 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) })
browser.tabs.query(QueryInfo(active = true, currentWindow = true))
.then({ tabs -> handleClick(target, tabs[0].id!!) })
.catch(::reportError)
})
}
Expand All @@ -41,13 +45,13 @@ fun handleClick(target: Element, id: Int) {
if (target.classList.contains("beast")) {
val url = getUrl(target.textContent)

browser.tabs.insertCSS(id, CssDetails(CSS_HIDE_PAGE))
browser.tabs.insertCSS(id, InjectDetails(code = CSS_HIDE_PAGE))
browser.tabs.sendMessage(id, jsObject {
command = "beastify"
beastURL = url
})
} else {
browser.tabs.removeCSS(id, CssDetails(CSS_HIDE_PAGE))
browser.tabs.removeCSS(id, InjectDetails(code = CSS_HIDE_PAGE))
browser.tabs.sendMessage(id, jsObject {
command = "reset"
})
Expand Down

0 comments on commit dcef211

Please sign in to comment.