fix: Get generators to work on Chrome; make wrl-only plugin also (#71)
Reviewed-on: #71 Co-authored-by: Glen Whitney <glen@studioinfinity.org> Co-committed-by: Glen Whitney <glen@studioinfinity.org>
This commit is contained in:
parent
c895f2d30f
commit
e742ef3460
7 changed files with 184 additions and 40 deletions
|
@ -8,6 +8,16 @@ knownExtensions := /[.](?:wrl|x3d|gltf|glb|obj|stl|ply)$/
|
|||
certainlyHandled :=
|
||||
knownExtensions.source.slice(0, -2).split('wrl|')[1].split '|'
|
||||
|
||||
// Basic poller, loosely based on
|
||||
// https://codereview.stackexchange.com/questions/272936/retry-a-callback-function-n-times-until-success
|
||||
// modified so delay doubles each time
|
||||
tryN := (tries: number, delay: number,
|
||||
callback: () => Promise<boolean>): Promise<void> =>
|
||||
if tries
|
||||
worked := await callback()
|
||||
unless worked
|
||||
setTimeout tryN.bind(this, tries-1, delay*2, callback), delay
|
||||
|
||||
function makeBrowser(url: string, width: string, height: string,
|
||||
config: ConfigType)
|
||||
x_ite_rel := 'deps/x_ite/x_ite.mjs'
|
||||
|
@ -117,13 +127,16 @@ configPromise.then((config) =>
|
|||
madeConway .= false
|
||||
|
||||
// See if we are on George Hart's Conway-notation generator page
|
||||
inputs := $('input[type="button"][value="Generate"][onclick="viewVRML()"]')
|
||||
inputs .= $('input[type="button"][value="Generate"][onclick="viewVRML()"]')
|
||||
if config.vrmlview and inputs.length is 1
|
||||
// Seems so, fix the generator
|
||||
// Note that modifying the onclick prop is not the recommended way to
|
||||
// change button click functionality, but we need to clear out the old
|
||||
// behavior so I wasn't sure how else to do it
|
||||
inputs.prop 'onclick', (i, val) => () =>
|
||||
// Remove old button and add new copy:
|
||||
predecessor := $('input[name="notation"]')
|
||||
inputs.remove()
|
||||
predecessor.after('<input type="button" value="Generate">')
|
||||
inputs = $('input[type="button"][value="Generate"]')
|
||||
// now add new handler
|
||||
inputs.on 'click', =>
|
||||
import(browser.runtime.getURL('conway.js')).then (conway) =>
|
||||
notation := $('input[name="notation"]').val()
|
||||
unless notation then return
|
||||
|
@ -144,19 +157,26 @@ configPromise.then((config) =>
|
|||
panelFrame := $('frame[name="panel"][src="prism-maker-subpanel.html"]')
|
||||
if config.vrmlview and panelFrame.length is 1
|
||||
// Seems so, fix the generator
|
||||
panelFrame.on "load", =>
|
||||
// unfortunately, in Chrome it is necessary to poll
|
||||
// until the frame is done loading.
|
||||
tryN 5, 100, =>
|
||||
unless frames[1] return false
|
||||
panelDoc := frames[1].document
|
||||
vrmlDoc := frames[0].document
|
||||
vrmlBody := $('body', vrmlDoc)
|
||||
// Grab the initial text while it is still easy to get
|
||||
// We are presuming here that the body just contains a single
|
||||
// text node. That should stay true unless GWH changes the page.
|
||||
textNode := vrmlBody.contents()[0]
|
||||
unless textNode return false // ask to go again
|
||||
return := true // OK, this is it
|
||||
initialVrml1: string := textNode.textContent or ''
|
||||
// Now build up the vrml frame as we want it
|
||||
viewerDiv := $('<div></div>')
|
||||
$('head').after $('<body></body>')
|
||||
$('body').append viewerDiv
|
||||
// We are presuming here that the body just contains a single
|
||||
// text node. That should stay true unless GWH changes the page.
|
||||
newBody := $('body')
|
||||
newBody[0].style.maxHeight = '310px'
|
||||
newBody.append viewerDiv
|
||||
initialVrml97 := convert initialVrml1
|
||||
{canvas, browser3D: prismBrowser} :=
|
||||
await makeBrowser '', '300px', '300px', config
|
||||
|
@ -172,6 +192,7 @@ configPromise.then((config) =>
|
|||
$('input[type="button"][value="View"][onclick="ViewVRML()"]',
|
||||
panelDoc)
|
||||
unless prismBtn.length is 1 return
|
||||
|
||||
prismBtn.prop 'onclick', (i, val) => =>
|
||||
import(browser.runtime.getURL('prism.js')).then (prism) =>
|
||||
numerator := parseInt(
|
||||
|
|
|
@ -5,7 +5,11 @@ cache := await browser.storage.local.get flags
|
|||
for each box of flags
|
||||
checkbox := document.getElementById(box) as HTMLInputElement
|
||||
unless checkbox then continue
|
||||
checkbox.checked = cache[box] ?? (box is 'vrmlview' or box is 'joyce')
|
||||
if box in cache
|
||||
checkbox.checked = cache[box]
|
||||
else
|
||||
checkbox.checked = box is 'vrmlview' or box is 'joyce'
|
||||
browser.storage.local.set [box]: checkbox.checked
|
||||
|
||||
document.body.addEventListener 'click', (event) ->
|
||||
elt := event.target as HTMLInputElement
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue