Skip to content

Instantly share code, notes, and snippets.

@zecka
Last active October 31, 2025 15:24
Show Gist options
  • Save zecka/f9280348ca8eae9d0655e5b8b26ef30a to your computer and use it in GitHub Desktop.
Save zecka/f9280348ca8eae9d0655e5b8b26ef30a to your computer and use it in GitHub Desktop.
Kill all style and link rel stylesheet in webpage from browser
(() => {
let count = 0;
const removeInRoot = root => {
const styles = root.querySelectorAll('style');
styles.forEach(s => s.remove());
count += styles.length;
const stylesLinks = root.querySelectorAll('link[rel="stylesheet"]');
stylesLinks.forEach(s => s.remove());
count += stylesLinks.length;
// Parcourt les Shadow DOM
const withShadow = root.querySelectorAll('*');
withShadow.forEach(el => {
if (el.shadowRoot) removeInRoot(el.shadowRoot);
});
};
// Page principale
removeInRoot(document);
// Iframes même origine
document.querySelectorAll('iframe').forEach(ifr => {
try {
if (ifr.contentDocument) removeInRoot(ifr.contentDocument);
} catch (_) { /* cross-origin, on ignore */ }
});
console.log(`Supprimé ${count} <style>`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment