xrsh-com/com/isoterminal/feat/index.js.js

31 lines
887 B
JavaScript
Raw Normal View History

if( typeof emulator != 'undefined' ){
// inside worker-thread
// unix to js device
this.emulator.readFromPipe( 'root/index.js', async (data) => {
const buf = await emulator.read_file("root/index.js")
const decoder = new TextDecoder('utf-8');
const js = decoder.decode(buf).replace(/^#!\/bin\/js/,'') // remove leftover shebangs if any
try{
this.postMessage({event:'runJavascript',data:[js]})
}catch(e){
console.error(e)
}
})
}else{
// inside browser-thread
ISOTerminal.prototype.runJavascript = function(js){
let $root = document.querySelector("script#root")
if( !$root ){
$root = document.createElement("script")
$root.id = "root"
document.body.appendChild($root)
}
$root.innerHTML = js
}
2024-09-23 16:58:48 +02:00
}