diff --git a/src/config.ts b/src/config.ts index f9418af..c692847 100644 --- a/src/config.ts +++ b/src/config.ts @@ -4,3 +4,7 @@ export class SzuruSiteConfig { username = "user"; authToken = ""; } + +export class TagCategoryColor { + constructor(public name: string, public color: string) {} +} diff --git a/src/dynamicStyle.ts b/src/dynamicStyle.ts new file mode 100644 index 0000000..17747fa --- /dev/null +++ b/src/dynamicStyle.ts @@ -0,0 +1,19 @@ +import { TagCategoryColor } from "./config"; + +export function makeCssName(prefix: string, name: string) { + return prefix + "-" + name.replace(/[^a-z0-9]/g, "_"); +} + +export function refreshTagCategoryColorMap(tagCategories: TagCategoryColor[], styleElement?: HTMLStyleElement) { + if (styleElement) { + document.head.removeChild(styleElement); + } + styleElement = document.createElement("style"); + document.head.appendChild(styleElement); + for (let category of tagCategories) { + const ruleName = makeCssName("tag", category.name); + styleElement.sheet!.insertRule(`.${ruleName} { color: ${category.color} }`, styleElement.sheet!.cssRules.length); + console.log("adding " + category); + } + return styleElement; +} diff --git a/src/options/App.vue b/src/options/App.vue index ee88498..0ca2e49 100644 --- a/src/options/App.vue +++ b/src/options/App.vue @@ -1,17 +1,24 @@