import { BasePlugin } from '../core/base-plugin.js'; import { __publicField, currentHref, NO, YES } from '../core/constants.js'; class FoldCategoryPlugin extends BasePlugin { getName() { return "FoldCategoryPlugin"; } async initCss() { const settingObj = await storageManager.getSetting(); return `\n \n `; } async handle() { if (window.isListPage && !currentHref.includes("advanced_search")) { this.highlightTag(); utils.loopDetector((() => $("#waitCheckBtn").length), (() => { this.createFoldBtn(); }), 1, 1e4, !0); $("#tags .tag-category .tag-expand").each(((index, el) => { $(el).parent().hasClass("collapse") && el.click(); })); } } highlightTag() { (async () => { const tags = await storageManager.getHighlightedTags(); tags && tags.forEach((text => { $(`#tags a.tag:contains(${text})`).addClass("highlighted"); $(`.tags a.tag:contains(${text})`).addClass("highlighted"); })); })().then(); $("#tags a.tag, .tags a.tag").hover((function() { const $tag = $(this), button = $(''); $tag.append(button); button.fadeIn(0); }), (function() { $(this).find(".highlight-btn").fadeOut(0, (function() { $(this).remove(); })); })); $(document).on("click", ".highlight-btn", (async function(e) { e.stopPropagation(); e.preventDefault(); const $tag = $(this).closest("a.tag"), clonedTag = $tag.clone(); clonedTag.find(".highlight-btn").remove(); const tagText = clonedTag.text().trim().replace(/\s*\(\d+\)$/, ""); let highlightedTags = await storageManager.getHighlightedTags(); if (highlightedTags.includes(tagText)) { highlightedTags = highlightedTags.filter((item => item !== tagText)); $tag.removeClass("highlighted"); } else { highlightedTags.push(tagText); $tag.addClass("highlighted"); } await storageManager.setHighlightedTags(highlightedTags); })); } async createFoldBtn() { const foldCategoryHotKey = await storageManager.getSetting("foldCategoryHotKey"); let $subTags = $("#tags"), checkTagStr = $("#tags dl div.tag.is-info").map((function() { return $(this).text().replaceAll("\n", "").replaceAll(" ", ""); })).get().join(" "); if (!checkTagStr) return; $(".tabs").append(`\n
\n
已选分类: ${checkTagStr}
\n \n \n ${foldCategoryHotKey ? ` (${foldCategoryHotKey})` : ""}\n \n \n\n
\n `); let $section = $("h2.section-title"); if ($section.length > 0) { $section.append('\n
\n \n \n \n \n
\n '); $subTags = $("section > div > div.box"); } if (!$subTags) return; let $foldCategoryBtn = $("#foldCategoryBtn"), isFolded = localStorage.getItem("jhs_foldCategory") === YES, [newText, newIcon] = isFolded ? [ "展开", "icon-angle-double-down" ] : [ "折叠", "icon-angle-double-up" ]; $foldCategoryBtn.find("span").text(newText).end().find("i").attr("class", newIcon); window.location.href.includes("noFold=1") || $subTags[isFolded ? "hide" : "show"](); $foldCategoryBtn.on("click", (async event => { event.preventDefault(); isFolded = !isFolded; localStorage.setItem("jhs_foldCategory", isFolded ? YES : NO); const [newText2, newIcon2] = isFolded ? [ "展开", "icon-angle-double-down" ] : [ "折叠", "icon-angle-double-up" ]; $foldCategoryBtn.find("span").text(newText2).end().find("i").attr("class", newIcon2); $subTags[isFolded ? "hide" : "show"](); })); } } export { FoldCategoryPlugin };