这样可以根据需要决定是否在某些主题下使用或不使用。
当白名单生效时,黑名单不生效。
因为不知道会不会考虑加上,这里贡献一下自己的垃圾代码,仅供其他用户可使用 😂
let me = {};
// 加载css代码 from Dark+
me.loadStyle = function (
innerHTML,
id = null,
position = "afterend",
element = window.theme.element.themeStyle,
) {
let style = document.createElement('style');
if (id) style.id = id;
style.innerHTML = innerHTML;
// document.head.appendChild(style);
element.insertAdjacentElement(position, style);
}
// 白名单主题执行
me.callWhiteList = function(themeArr=[], callback=nul){
let curTheme = window.siyuan.config.appearance[window.siyuan.config.appearance.mode?"themeDark":"themeLight"] ;
if(themeArr.includes(curTheme)){
if (typeof callback === 'function') setTimeout(callback, 0);
}
}
// 黑名单主题执行
me.callBlackList = function(themeArr=[], callback=nul){
let curTheme = window.siyuan.config.appearance[window.siyuan.config.appearance.mode?"themeDark":"themeLight"] ;
if(!themeArr.includes(curTheme)){
if (typeof callback === 'function') setTimeout(callback, 0);
}
}
me.start = async function(){
//读取配置
function readConfig(config){
return () =>{
if(config["type"] == "css"){
me.loadStyle(config["content"], config["name"]);
return;
}
if(config["type"] == "js"){
eval(config["content"]);
}
}
}
// 执行配置文件的js和css
const response = await fetch("/snippets/me_conf.json");
me.configList = await response.json();
me.configList.forEach(item => {
if(!item["enabled"]){
return;
}
// 白名单优先,有白的时候不用黑。
item["whiteList"] = item["whiteList"] || [];
if(item["whiteList"].length > 0){
me.callWhiteList(item["whiteList"], readConfig(item));
return;
}
// 有白名单时,黑名单不生效。
me.callBlackList(item["blackList"], readConfig(item));
});
}
me.start();
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于