Replies: 3 comments
-
Interesting project. Not tested yet, but just a question. You speak about these selector: These selectors are relatively new, by example: I use too Waterfox Classic, which is based to Firefox v.57: Actually i don't find a website which use shadoow-DOM with Waterfox Classic. Some test i do with an other userscript: |
Beta Was this translation helpful? Give feedback.
-
I haven't tried yet with the very old versions. I've FF 56 lying around and apparently By the way, the script doesn't modify the selectors. They are passed to the shadow-root and since the browser understand |
Beta Was this translation helpful? Give feedback.
-
Thanks ;-) |
Beta Was this translation helpful? Give feedback.
-
Early this week one of my most visited websites moved parts of its content to shadow-root elements, making it impossible to style with userstyle, or any global stylesheet. Fortunately they use "open" shadow which allowed me to quickly write a userscript to inject some style directly into them.
In the past I've already played with shadow elements by patching
attachShadow()
allowing me to interact with "closed" shadow-root (the wayback machine's header). The idea was to use this knowledge to write a userscript to run as a bridge between stylus and shadow-DOM elements.Two CSS selectors in particular are used in conjunction with shadow-DOM:
:host
and:host-context
. This will help to limit the amount of style rules injected in each shadow-root.With the userscript running in the current page (and frames, if necessary), any use of
:host
within stylus will immediately style shadow-DOM elements if they match the full selector. If the user has enabled "Live preview" the modifications will be applied immediately on shadow elements.How the userscript works:
attachShadow()
to capture creation of the elements. (With a small trick in the code to prevent detection by the webpage. When they try)<style>
elements.:host
selectors.<style>
element in each shadow-root with that style.I've tested with both FF and chrome (current and older versions) and it's running smoothly.
Note that for the moment the current version of the script doesn't match any website. You'll have to edit the settings of the userscript in your userscript manager to add matching urls. Don't forget the trailing
*
.You can get the userscript here.
There is a how-to on that page to quickly test the script on a webpage with shadow-DOM (wayback machine).
Beta Was this translation helpful? Give feedback.
All reactions