-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
92 lines (85 loc) · 2.93 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const accentMap = {
"Full palette" : "unset", // undefined css var name
"Rosewater" : "var(--ctp-rosewater)",
"Flamingo" : "var(--ctp-flamingo)",
"Pink" : "var(--ctp-pink)",
"Mauve" : "var(--ctp-mauve)",
"Red" : "var(--ctp-red)",
"Maroon" : "var(--ctp-maroon)",
"Peach" : "var(--ctp-peach)",
"Yellow" : "var(--ctp-yellow)",
"Green" : "var(--ctp-green)",
"Teal" : "var(--ctp-teal)",
"Sky" : "var(--ctp-sky)",
"Sapphire" : "var(--ctp-sapphire)",
"Blue" : "var(--ctp-blue)",
"Lavender" : "var(--ctp-lavender)"
};
const accentClasses = Object.values(accentMap);
const accentNames = Object.keys(accentMap);
const settings = [
{
key: "CtpAccent",
title: "Select accent color",
description: "Note: Logseq's accent color should be disabled under Setting > General",
type: "enum",
enumPicker: "select",
enumChoices: accentNames,
default: "Full palette"
},
{
key: "CtpWhiteboard",
title: "Override Whiteboard theme to light theme?",
description: " Override whiteboard theme to use Latte theme flavor",
type: "boolean",
default: false,
},
];
function setWhiteboardOverride(bool) {
const rootContainer = parent.document.querySelector(`html`);
if (bool) {
rootContainer.classList.add('whiteboard-latte');
} else {
rootContainer.classList.remove('whiteboard-latte');
}
}
function setAccent(accentName) {
logseq.provideStyle({
key: 'ctp-accent',
style: `
:root:not([data-color]), :root[data-color='none'], :root[data-color='logseq'] {
--ctp-accent: ${accentMap[accentName]};
}
html.whiteboard-latte div.whiteboard-page {
--ctp-accent: ${accentMap[accentName]};
}
html.whiteboard-latte div.dashboard-card {
--ctp-accent: ${accentMap[accentName]};
}
html.whiteboard-latte div.tl-tooltip-content {
--ctp-accent: ${accentMap[accentName]};
}
html.whiteboard-latte div.tl-select-input-content {
--ctp-accent: ${accentMap[accentName]};
}
`,
});
}
function reloadCss() {
var links = parent.document.getElementsByTagName("link");
var link = Array.from(links).find(l => l.href.includes("ctp"));
link.href += "";
}
async function main() {
logseq.useSettingsSchema(settings);
logseq.onSettingsChanged(updatedSettings => {
if (setAccent(updatedSettings.CtpAccent)) {
console.log(`Applied ${updatedSettings.CtpAccent} accent✨`);
}
if (setWhiteboardOverride(updatedSettings.CtpWhiteboard)) {
console.log(`${updatedSettings.CtpWhiteboard ? 'Applied' : 'Removed'} Latte whiteboard flavor✨`);
}
});
}
// bootstrap
logseq.ready(main).catch(console.error)