...to automatically run user-defined JS. To make use of userscripts you have to install a browser extension called "userscript manager", which are available for all modern browsers.
Learn more about userscripts.
Here is an sample JS that checks if <head>
element contains any <style>
or <link rel="stylesheet">
. If no, then user-defined CSS is inserted:
const head = document.getElementsByTagName('head')[0];
if(head.querySelector('style, link[rel~=stylesheet]') === null) {
head.insertAdjacentHTML(
'beforeend',
'<link rel="stylesheet" href="https://unpkg.com/spcss" />'
);
}
Replace the "https://unpkg.com/spcss"
with a URL of your CSS.
There are other approaches to load CSS file using JS or you can insert a <style>
tag to define styles directly.
I'm not sure if it's possible to load a local CSS file from http://
page or access local filesystem from a userscript :(
but the script itself is a local file.
I've just published example above as a ready-to-use usercript: https://greasyfork.org/en/scripts/482860-default-css.