Skip to content

Instantly share code, notes, and snippets.

@avin
Created September 14, 2022 19:28
Show Gist options
  • Save avin/1576d45f99ffa9f54dbece375c29858a to your computer and use it in GitHub Desktop.
Save avin/1576d45f99ffa9f54dbece375c29858a to your computer and use it in GitHub Desktop.
Keep solo element on page
const onPageReady = (fn) => {
if (document.readyState !== 'loading') {
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
};
onPageReady(() => {
const doClean = (el) => {
const parent = el.parentElement;
for (const child of Array.from(parent.childNodes)) {
if (child !== el) {
child.remove();
}
}
el.style.padding = 0;
el.style.margin = 0;
if (parent !== document.body) {
doClean(parent);
}
};
const playerEl = document.querySelector('#cdnplayer'); // <<<<<<<<<<<
doClean(playerEl);
playerEl.style.width = '100vw';
playerEl.style.height = '100vh';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment