2017-09-29 18:29:36 +01:00
|
|
|
/** Script used in the commandline iframe. Communicates with background. */
|
2017-10-02 00:59:51 +01:00
|
|
|
|
2017-10-05 23:11:56 +01:00
|
|
|
import * as Messaging from './messaging'
|
|
|
|
|
2017-09-29 18:29:36 +01:00
|
|
|
let clInput = window.document.getElementById("tridactyl-input") as HTMLInputElement
|
|
|
|
clInput.focus()
|
|
|
|
|
|
|
|
/* Process the commandline on enter. */
|
|
|
|
clInput.addEventListener("keydown", function (keyevent) {
|
|
|
|
if (keyevent.key === "Enter") {
|
|
|
|
process()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
/* Send the commandline to the background script and await response. */
|
|
|
|
function process() {
|
|
|
|
console.log(clInput.value)
|
2017-10-05 15:27:45 +01:00
|
|
|
browser.runtime.sendMessage({type: "commandline", exStr: "hidecommandline"})
|
2017-10-05 21:32:33 +01:00
|
|
|
browser.runtime.sendMessage({type: "commandline", exStr: clInput.value})
|
2017-09-29 18:29:36 +01:00
|
|
|
clInput.value = ""
|
|
|
|
}
|
2017-10-02 00:59:51 +01:00
|
|
|
|
2017-10-05 23:11:56 +01:00
|
|
|
function changecommand(newcommand?: string){
|
2017-10-06 04:16:02 +01:00
|
|
|
if (newcommand !== undefined) {
|
2017-10-05 21:48:43 -07:00
|
|
|
clInput.value = newcommand + " "
|
2017-10-06 04:16:02 +01:00
|
|
|
}
|
|
|
|
// Focus is lost for some reason.
|
|
|
|
clInput.focus()
|
2017-10-05 23:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function handler(message) {
|
|
|
|
console.log(message)
|
|
|
|
// this[message.command](...message.args)
|
|
|
|
changecommand(...message.args)
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Messaging.addListener('commandline_frame', handler)
|
|
|
|
} catch(e) {
|
|
|
|
console.error("WAHWAH", e)
|
|
|
|
}
|