GM_addStyle()
appends the <style>
element it creates to the <head>
, therefore it can't modify the styling of Shadow DOM elements. You need to use GM_addElement()
.
// ==UserScript==
// @name Shadow DOM styling
// @version 0.1
// @author double-beep
// @match http*://example.com
// @grant GM_addElement
// ==/UserScript==
(function() {
'use strict';
const shadowRoot = document.querySelector('element');
const styles = `div { color: red; }`;
GM_addElement(shadowRoot, 'style', { textContent: styles });
})();
If the styles aren't applied, you can create a <script>
element instead in a similar way:
GM_addElement(shadowRoot, 'script', {
textContent: 'shadowRootElement.shadowRoot.querySelector("...").style.color = "red";'
});