tridactyl/src/commandline_content.ts
Oliver Blanthorn 07c3688f8d Bonus late night commit
All the mistakes are Colin's fault
- Generic listener
- Send messages to command line
- ^ doesn't work unless frame is opened in new tab
2017-10-06 03:40:17 +01:00

36 lines
1.2 KiB
TypeScript

/** Inject an input element into unsuspecting webpages and provide an API for interaction with tridactyl */
/* TODO:
CSS
Friendliest-to-webpage way of injecting commandline bar?
Security: how to prevent other people's JS from seeing or accessing the bar or its output?
- Method here is isolation via iframe
- Web content can replace the iframe, but can't view or edit its content.
- see doc/escalating-privilege.md for other approaches.
*/
// inject the commandline iframe into a content page
let cmdline_iframe: HTMLIFrameElement = undefined
function init(){
cmdline_iframe = window.document.createElement("iframe")
cmdline_iframe.setAttribute("src", browser.extension.getURL("static/commandline.html"))
window.document.body.appendChild(cmdline_iframe)
}
export function show(){
if (cmdline_iframe === undefined) {
init()
}
cmdline_iframe.setAttribute("style", "position: fixed; top: 0; left: 0; z-index: 10000; width: 100%; height: 36px; border: 0; padding: 0; margin: 1;");
}
export function hide(){
cmdline_iframe.setAttribute("style", "display: none")
}
export function focus(){
show()
cmdline_iframe.focus()
}