/** * Returns `unsafeWindow` if the `@grant unsafeWindow` is given, otherwise falls back to the regular `window` */ export function getUnsafeWindow() { try { // throws ReferenceError if the "@grant unsafeWindow" isn't present return unsafeWindow; } catch(e) { return window; } } /** * Inserts {@linkcode afterElement} as a sibling just after the provided {@linkcode beforeElement} * @returns Returns the {@linkcode afterElement} */ export function insertAfter(beforeElement: Element, afterElement: Element) { beforeElement.parentNode?.insertBefore(afterElement, beforeElement.nextSibling); return afterElement; } /** * Adds a parent container around the provided element * @returns Returns the new parent element */ export function addParent(element: Element, newParent: Element) { const oldParent = element.parentNode; if(!oldParent) throw new Error("Element doesn't have a parent node"); oldParent.replaceChild(newParent, element); newParent.appendChild(element); return newParent; } /** * Adds global CSS style in the form of a `