mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
parent
6301b744d2
commit
54e3f8d3f4
21 changed files with 246 additions and 202 deletions
58
lib/theme.js
58
lib/theme.js
|
@ -16,22 +16,52 @@
|
|||
|
||||
scope.init = function(page){
|
||||
const basePath = browser.extension.getURL("themes");
|
||||
|
||||
var baseLink = document.createElement("link");
|
||||
baseLink.href = `${basePath}/base/layout.css`;
|
||||
baseLink.rel = "alternative";
|
||||
baseLink.type = "text/css";
|
||||
document.head.appendChild(baseLink);
|
||||
const links = ["layout", page].filter(function(file){
|
||||
return file;
|
||||
}).map(function(file){
|
||||
var link = document.createElement("link");
|
||||
link.cbFile = file;
|
||||
link.rel = "alternative";
|
||||
link.type = "text/css";
|
||||
document.head.appendChild(link);
|
||||
return link;
|
||||
});
|
||||
|
||||
function setTheme(theme){
|
||||
switch (theme){
|
||||
case "none":
|
||||
baseLink.rel = "alternative";
|
||||
links.forEach(function(link){
|
||||
link.rel = "alternative";
|
||||
});
|
||||
break;
|
||||
case "auto":
|
||||
if (window.matchMedia("(prefers-color-scheme: dark)").matches){
|
||||
theme = "dark";
|
||||
}
|
||||
else {
|
||||
theme = "default";
|
||||
}
|
||||
// fall through
|
||||
default:
|
||||
baseLink.rel = "stylesheet";
|
||||
links.forEach(function(link){
|
||||
link.rel = "stylesheet";
|
||||
link.href = `${basePath}/${theme}/${link.cbFile}.css`;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
settings.onloaded(function(){
|
||||
const links = ["layout", page].filter(function(file){
|
||||
return file;
|
||||
}).map(function(file){
|
||||
var link = document.createElement("link");
|
||||
link.cbFile = file;
|
||||
link.href = `${basePath}/${settings.theme}/${file}.css`;
|
||||
link.rel = "stylesheet";
|
||||
link.type = "text/css";
|
||||
document.head.appendChild(link);
|
||||
return link;
|
||||
});
|
||||
setTheme(settings.theme);
|
||||
settings.on("theme", function(){
|
||||
links.forEach(function(link){
|
||||
link.href = `${basePath}/${settings.theme}/${link.cbFile}.css`;
|
||||
});
|
||||
setTheme(settings.theme);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue