Last active
October 31, 2025 15:24
-
-
Save zecka/f9280348ca8eae9d0655e5b8b26ef30a to your computer and use it in GitHub Desktop.
Kill all style and link rel stylesheet in webpage from browser
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
| (() => { | |
| 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