tampermonkey script: support site styles

This commit is contained in:
LordMZTE 2024-03-25 21:28:48 +01:00
parent 1fcbe56133
commit b6239e30e2
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
4 changed files with 29 additions and 0 deletions

View file

@ -0,0 +1,4 @@
/* Hide the stupid rounding masks on server icons */
:root foreignObject {
mask: none !important;
}

View file

@ -2,4 +2,5 @@
-main Main
--macro Macro.init()
-D js-es=6
-js script.js

View file

@ -1,9 +1,12 @@
#if macro
import haxe.macro.Compiler;
import haxe.macro.Context;
import sys.FileSystem;
import sys.io.File;
#end
using StringTools;
macro function init() {
var oldHeader = Context.definedValue("source-header");
var header = Std.string(File.read("assets/header.txt").readAll());
@ -15,3 +18,14 @@ macro function fileContent(path:String):haxe.macro.Expr.ExprOf<String> {
return macro $v{Std.string(File.read(path).readAll())};
}
macro function siteStyles():haxe.macro.Expr.ExprOf<Map<String, String>> {
var map:Array<haxe.macro.Expr> = [];
for (f in FileSystem.readDirectory("assets/site_styles")) {
if (f.endsWith(".css")) {
map.push(macro $v{f.substr(0, f.length - 4)} => Macro.fileContent($v{'assets/site_styles/$f'}));
}
}
return macro $a{map};
}

View file

@ -1,6 +1,8 @@
import js.Browser;
function main() {
var siteStyles = Macro.siteStyles();
var ownStyle = Browser.document.createStyleElement();
ownStyle.innerHTML = Macro.fileContent("assets/own_style.css");
@ -13,6 +15,14 @@ function main() {
if (!actions.ToggleStyleAction.blacklist.has(Browser.window.location.hostname)) {
Browser.document.body.appendChild(style);
}
var siteStyle = siteStyles[Browser.window.location.hostname];
if (siteStyle != null) {
var siteStyleElem = Browser.document.createStyleElement();
siteStyleElem.innerHTML = siteStyle;
Browser.document.body.appendChild(siteStyleElem);
Browser.console.log("added site style: ", siteStyleElem);
}
});
new actions.InfoAction().register();