Skip to content

Instantly share code, notes, and snippets.

@allyouaskfor
Created July 27, 2024 07:29
Show Gist options
  • Save allyouaskfor/915966105842a16bdec0b8d89b27a08b to your computer and use it in GitHub Desktop.
Save allyouaskfor/915966105842a16bdec0b8d89b27a08b to your computer and use it in GitHub Desktop.
Userscripts GM_addStyle fix
// ==UserScript==
// @name Example
// @supportURL https://stackoverflow.com/a/33176845/6369424
// @description Fix GM_addStyle undefined.
// ==/UserScript==
function GM_addStyle(css) {
const style = document.getElementById("elytSdda_MG") || (function() {
const style = document.createElement('style');
style.type = 'text/css';
style.id = "elytSdda_MG";
document.head.appendChild(style);
return style;
})();
const sheet = style.sheet;
sheet.insertRule(css, (sheet.rules || sheet.cssRules || []).length);
}
GM_addStyle(`
p { color:red; }
`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment