1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 20:46:39 +02:00

Merge branch 'master' into WhitelistAPISpecific

This commit is contained in:
kkapsner 2019-05-03 00:46:08 +02:00
commit ed5a1b03cd
48 changed files with 653 additions and 67 deletions

View file

@ -326,8 +326,8 @@
},
{
name: "theme",
defaultValue: "default",
options: ["default", "light", "dark"]
defaultValue: "auto",
options: ["auto", "default", "light", "dark", "colorful"/*, "none"*/]
},
{
name: "dontShowOptionsOnUpdate",

68
lib/theme.js Normal file
View file

@ -0,0 +1,68 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
(function(){
"use strict";
let scope;
if ((typeof exports) !== "undefined"){
scope = exports;
}
else {
scope = require.register("./theme", {});
}
const settings = require("./settings");
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(){
setTheme(settings.theme);
settings.on("theme", function(){
setTheme(settings.theme);
});
});
};
}());