mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-05 03:12:33 +01:00
tampermonkey script: support site styles
This commit is contained in:
parent
1fcbe56133
commit
b6239e30e2
4 changed files with 29 additions and 0 deletions
|
@ -0,0 +1,4 @@
|
|||
/* Hide the stupid rounding masks on server icons */
|
||||
:root foreignObject {
|
||||
mask: none !important;
|
||||
}
|
|
@ -2,4 +2,5 @@
|
|||
-main Main
|
||||
--macro Macro.init()
|
||||
|
||||
-D js-es=6
|
||||
-js script.js
|
||||
|
|
|
@ -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};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue