/** * @module lib/dom * This module contains various functions for working with the DOM - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#dom) */ /** * Returns `unsafeWindow` if the `@grant unsafeWindow` is given, otherwise falls back to the regular `window` */ export function getUnsafeWindow(): Window { try { // throws ReferenceError if the "@grant unsafeWindow" isn't present return unsafeWindow; } catch { return window; } } /** * Adds a parent container around the provided element * @returns Returns the new parent element */ export function addParent(element: TElem, newParent: TParentElem): TParentElem { 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 `