const handlers = {}; var onloadOld = onload || (() => {}); onload = () => { onloadOld(); init(); } function init() { for(const k in handlers) { for (const n of getNodes(k)) { handlers[k](n); } } } function getNodes(scriptType) { return Array.from( document.querySelectorAll(`script[type="orep/${scriptType}"]`) ).filter(n => !n.dataset.handled); } export function register(scriptType, handler) { if (scriptType in handlers) throw new Error(`'${scriptType}' is already registered`); handlers[scriptType] = handler; }