Javascript: calling asynchronously-initialized libraries from synchronous code

With the power of await, this isn't so difficult: let nacl, scrypt; function main() { /* Synchronous code that calls nacl and scrypt */ } (async () => { [nacl, scrypt] = await Promise.all([new Promise(nacl_factory.instantiate), new Promise(scrypt_module_factory)]); return main(); })();

Auto-updating userscripts hosted on Github Gist

In the process of crafting this small set of improvements to Advance Wars By Web, I found out about the proper URL for auto-updating userscripts which are hosted on Microsoft's "Gist" service: // @updateURL This will always redirect to the latest version of the file.

Javascript: getElementByXPath

function getElementByXPath(path, context=null, _document=undefined) { if( _document === undefined ) _document = document; let res = document.evaluate(path, _document, context, XPathResult.FIRST_ORDERED_NODE_TYPE); if( !res ) return null; return res.singleNodeValue; } function getTextByXPath(path, context=null, _document=undefined) { let e = getElementByXPath(path, context, _document); if( !e ) return undefined; return e.textContent; } function getTextByQuerySelector(selector) { let e = document.querySelector(selector); if( !e ) return undefined; return e.textContent; }