Created
September 14, 2022 19:28
-
-
Save avin/1576d45f99ffa9f54dbece375c29858a to your computer and use it in GitHub Desktop.
Keep solo element on page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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