mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-15 05:42:27 +08:00
28 lines
569 B
JavaScript
28 lines
569 B
JavaScript
![]() |
const registeredClasses = new Set();
|
||
|
|
||
|
function createClassForColor(color) {
|
||
|
if (!color?.trim()) {
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
const normalizedColorName = color.replace(/[^a-z0-9]/gi, "");
|
||
|
|
||
|
if (!normalizedColorName.trim()) {
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
const className = 'color-' + normalizedColorName;
|
||
|
|
||
|
if (!registeredClasses.has(className)) {
|
||
|
$("head").append(`<style>.${className} { color: ${color} !important; }</style>`);
|
||
|
|
||
|
registeredClasses.add(className);
|
||
|
}
|
||
|
|
||
|
return className;
|
||
|
}
|
||
|
|
||
|
export default {
|
||
|
createClassForColor
|
||
|
};
|