Skip to content

Instantly share code, notes, and snippets.

@yuiAs
Last active April 7, 2022 10:30
Show Gist options
  • Select an option

  • Save yuiAs/28824b47cb0e0d9bb0483f7f101113fd to your computer and use it in GitHub Desktop.

Select an option

Save yuiAs/28824b47cb0e0d9bb0483f7f101113fd to your computer and use it in GitHub Desktop.
const modifier = async () => {
const sleep = msec => new Promise(resolve => {
if (document.readyState === 'complete') {
setTimeout(resolve, msec);
} else {
document.addEventListener('readystatechange', () => {
if (document.readyState === 'complete') {
setTimeout(resolve, msec);
}
}, { capture: false, passive: true });
}
});
await sleep(100);
document.querySelectorAll('iframe[id^="twitter-widget-"]').forEach(elem => {
elem.addEventListener('load', () => {
elem.style.removeProperty('height');
}, { once: true, passive: true });
elem.style.removeProperty('height');
});
};
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
modifier();
}, { passive: true });
} else {
console.log(`already dispatched DOMContentLoaded`);
modifier();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment