Skip to content

Commit

Permalink
feat: ✨ 优化 ehentai My Tags 页标签排序
Browse files Browse the repository at this point in the history
  • Loading branch information
hymbz committed Oct 7, 2024
1 parent f6689b4 commit 496043e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .xo-config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
"no-param-reassign": "error",
// 禁用 prefer-const 的自动修复
"prefer-const": "off",
"no-autofix/prefer-const": "warn",
"no-autofix/prefer-const": ["warn", { "destructuring": "all" }],

// 不限制代码深度
"max-depth": "off",
Expand Down
18 changes: 17 additions & 1 deletion src/site/ehentai/sortTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { querySelector } from 'helper';
interface Tag {
e: HTMLElement;
id: number;
group: string;
name: string;
weight: number;
watch: boolean;
hidden: boolean;
Expand Down Expand Up @@ -40,11 +42,23 @@ export const sortTags = () => {
defaultColor,
16,
);
let [group, name] = e
.querySelector<HTMLElement>(`#tagpreview_${id}`)!
.title.split(':');
// 合并性别相关的命名空间,以便不同命名空间下的相同标签可以排在一起
switch (group) {
case 'female':
case 'male':
case 'mixed':
group = 'gender';
}

tagList[color] ||= [];
tagList[color].push({
e,
id: Number(id),
group,
name,
weight: Number(
e.querySelector<HTMLInputElement>('input[id^=tagweight_]')!.value,
),
Expand All @@ -54,11 +68,13 @@ export const sortTags = () => {
}

const sortDom = () => {
const collator = new Intl.Collator();
const sortFn = (a: Tag, b: Tag) => {
if (a.weight !== b.weight) return a.weight - b.weight;
if (a.watch !== b.watch) return a.watch ? 1 : -1;
if (a.hidden !== b.hidden) return a.hidden ? -1 : 1;
return a.id - b.id;
if (a.group !== b.group) return collator.compare(a.group, b.group);
return collator.compare(a.name, b.name);
};

let i = tagEleList.length;
Expand Down

0 comments on commit 496043e

Please sign in to comment.