diff --git a/build.gradle b/build.gradle index c16be97..8cb57ac 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.1.60' + ext.kotlin_version = '1.2.0' repositories { mavenCentral() @@ -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 { diff --git a/content_script/src/main/kotlin/content_script.kt b/content_script/src/main/kotlin/content_script.kt index 141046e..7f59ec4 100644 --- a/content_script/src/main/kotlin/content_script.kt +++ b/content_script/src/main/kotlin/content_script.kt @@ -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 @@ -9,7 +10,7 @@ fun main(args: Array) { } 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") { diff --git a/content_script/src/main/kotlin/helpers.kt b/content_script/src/main/kotlin/helpers.kt deleted file mode 100644 index 4113c3d..0000000 --- a/content_script/src/main/kotlin/helpers.kt +++ /dev/null @@ -1 +0,0 @@ -external val browser: dynamic \ No newline at end of file diff --git a/popup/choose_beast.html b/popup/choose_beast.html index d2a78d1..b5a4c04 100644 --- a/popup/choose_beast.html +++ b/popup/choose_beast.html @@ -18,6 +18,7 @@

Try a different page.

+ diff --git a/popup/src/main/kotlin/helpers.kt b/popup/src/main/kotlin/helpers.kt deleted file mode 100644 index 691fef6..0000000 --- a/popup/src/main/kotlin/helpers.kt +++ /dev/null @@ -1,26 +0,0 @@ -import kotlin.js.Promise - -external val browser: Browser - -external class Browser { - val tabs: Tabs - val extension: Extension -} - -external class Tabs { - fun executeScript(def: Script): Promise> - fun insertCSS(id: Int, details: CssDetails): Promise - fun removeCSS(id: Int, details: CssDetails): Promise - fun sendMessage(id: Int, message: dynamic): Any - fun query(info: Query): Promise> -} - -external class Extension { - fun getURL(s: String): String -} - -class Tab(val id: Int) - -class Script(val file: String) -class CssDetails(val code: String) -class Query(val active: Boolean, val currentWindow: Boolean) \ No newline at end of file diff --git a/popup/src/main/kotlin/popup.kt b/popup/src/main/kotlin/popup.kt index c1100d5..ff1a921 100644 --- a/popup/src/main/kotlin/popup.kt +++ b/popup/src/main/kotlin/popup.kt @@ -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) { 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) @@ -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) }) } @@ -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" })