diff --git a/README.md b/README.md index 6b0523a3..c81bf310 100644 --- a/README.md +++ b/README.md @@ -228,7 +228,7 @@ Cotrans 也有自己的油猴脚本 —— 「[Cotrans 漫画/图片翻译器](h ![eh标签染色](/docs/public/eh标签染色.webp) -> 标签颜色数据将在 `进入「My Tags」时` 和 `在「My Tags」中修改后` 更新 +> 标签颜色数据将在 `功能开启时`、`进入「My Tags」时` 和 `在「My Tags」中修改后` 更新 ### 识别广告页 diff --git a/docs/index.md b/docs/index.md index c763bec6..e4e8a150 100644 --- a/docs/index.md +++ b/docs/index.md @@ -228,7 +228,7 @@ Cotrans 也有自己的油猴脚本 —— 「[Cotrans 漫画/图片翻译器](h ![eh标签染色](https://comic-read-docs.pages.dev/eh标签染色.webp) -> 标签颜色数据将在 `进入「My Tags」时` 和 `在「My Tags」中修改后` 更新 +> 标签颜色数据将在 `功能开启时`、`进入「My Tags」时` 和 `在「My Tags」中修改后` 更新 ### 识别广告页 diff --git a/src/site/ehentai/colorizeTag.ts b/src/site/ehentai/colorizeTag.ts index 4c491167..4113b52b 100644 --- a/src/site/ehentai/colorizeTag.ts +++ b/src/site/ehentai/colorizeTag.ts @@ -1,4 +1,4 @@ -import { request } from 'main'; +import { domParse, request } from 'main'; import { type PageType } from '.'; @@ -18,25 +18,50 @@ import { type PageType } from '.'; const buildTagList = (tagList: Set, prefix: string) => `\n${[...tagList].map((tag) => `${prefix}${tag}`).join(',\n')}\n`; +const getTagSetHtml = async (tagset?: string) => { + const url = tagset ? `/mytags?tagset=${tagset}` : '/mytags'; + const res = await request(url, { fetch: true }); + return domParse(res.responseText); +}; + /** 获取最新的标签颜色数据 */ export const updateTagColor = async () => { - const res = await request('/mytags', { fetch: true }); - const backgroundMap: Record> = {}; const borderMap: Record> = {}; const colorMap: Record> = {}; - for (const [, color, border, background, title] of res.responseText.matchAll( - /
/g, - )) { - const tag = title.replaceAll(' ', '_').replaceAll(':', '\\:'); - - backgroundMap[background] ||= new Set(); - backgroundMap[background].add(tag); - borderMap[border] ||= new Set(); - borderMap[border].add(tag); - colorMap[color] ||= new Set(); - colorMap[color].add(tag); + const tagSetList: Document[] = []; + // 获取所有标签集的 html + const defaultTagSet = await getTagSetHtml(); + await Promise.all( + [ + ...defaultTagSet.querySelectorAll( + '#tagset_outer select option', + ), + ].map(async (option) => { + const tagSet = option.selected + ? defaultTagSet + : await getTagSetHtml(option.value); + if (tagSet.querySelector('#tagset_enable')?.checked) + tagSetList.push(tagSet); + }), + ); + + for (const html of tagSetList) { + for (const tagDom of html.querySelectorAll( + '#usertags_outer [id^=tagpreview_]', + )) { + const { color, borderColor, background } = tagDom.style; + const tag = tagDom.title.replaceAll(' ', '_').replaceAll(':', '\\:'); + if (!tag) continue; + + backgroundMap[background] ||= new Set(); + backgroundMap[background].add(tag); + borderMap[borderColor] ||= new Set(); + borderMap[borderColor].add(tag); + colorMap[color] ||= new Set(); + colorMap[color].add(tag); + } } let css = '';