{AppletDescription, AdapParams, params, flags, ConfigType} from ./adapptypes.ts // (At least some of) Joyce's pages have inline scripts that remove their // own applet nodes, so we have to watch for them as they are added. Hence, // this script runs at document_start, and watches for applets being added, // setting up the joyceApplets structure as it goes joyceApplets: AppletDescription[] := [] obs := new MutationObserver (mutationList) => for each change of mutationList for each newGenericNode of change.addedNodes newNode := (newGenericNode as HTMLElement) newParent := (change.target as HTMLElement) unless newNode.tagName is 'APPLET' then continue unless newNode.getAttribute('code') is 'Geometry' then continue id .= newParent.getAttribute 'id' unless id id = 'joyceApplet' + joyceApplets.length newParent.setAttribute 'id', id joyceApplets.push { html: newNode.outerHTML, params(newNode.children), id, width: parseInt(newNode.getAttribute('width') ?? '200'), height: parseInt(newNode.getAttribute('height') ?? '200') } config := childList: true, subtree: true obs.observe document.documentElement, config function addScriptTag(url: string, module = false) return new Promise (resolve, reject) => script := document.createElement 'script' script.addEventListener 'load', resolve script.addEventListener 'error', reject script.src = url if module then script.type = 'module' document.head.appendChild script document.addEventListener "DOMContentLoaded", async => finalJoyceApplet := document.querySelector "applet[code='Geometry']" if joyceApplets.length or finalJoyceApplet config := await browser.storage.local.get(flags) as ConfigType adapParams: AdapParams := { codebase: browser.runtime.getURL('deps/GeoGebra/HTML5/5.0/webSimple'), config, joyceApplets } // @ts-ignore window.wrappedJSObject.adapParams = cloneInto(adapParams, window) addScriptTag(browser.runtime.getURL 'deps/GeoGebra/deployggb.js').then => addScriptTag browser.runtime.getURL('adapptlet.js'), true