From d4db6a79070dcdbfa128ba6bf2adb57764a17ea1 Mon Sep 17 00:00:00 2001 From: Dominik Reh Date: Thu, 12 Jan 2023 15:49:53 +0100 Subject: [PATCH] Option to show ? wiki links for danbooru/e621 tags Disabled by default since the wiki pages likely contain NSFW images. Closes #109 --- javascript/tagAutocomplete.js | 36 ++++++++++++++++++++++++++++-- scripts/tag_autocomplete_helper.py | 1 + 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index 06ab794..b7c866f 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -70,6 +70,13 @@ const autocompleteCSS = ` flex-grow: 1; color: var(--meta-text-color); } + .acWikiLink { + padding: 0.5rem; + margin: -0.5rem 0 -0.5rem -0.5rem; + } + .acWikiLink:hover { + text-decoration: underline; + } .acListItem.acEmbeddingV1 { color: var(--embedding-v1-color); } @@ -169,6 +176,7 @@ async function syncOptions() { delayTime: opts["tac_delayTime"], useWildcards: opts["tac_useWildcards"], useEmbeddings: opts["tac_useEmbeddings"], + showWikiLinks: opts["tac_showWikiLinks"], // Insertion related settings replaceUnderscores: opts["tac_replaceUnderscores"], escapeParentheses: opts["tac_escapeParentheses"], @@ -408,7 +416,6 @@ function addResultsToList(textArea, results, tagword, resetList) { let itemText = document.createElement("div"); itemText.classList.add("acListItem"); - flexDiv.appendChild(itemText); let displayText = ""; // If the tag matches the tagword, we don't need to display the alias @@ -446,6 +453,31 @@ function addResultsToList(textArea, results, tagword, resetList) { // Print search term bolded in result itemText.innerHTML = displayText.replace(tagword, `${tagword}`); + // Add wiki link if the setting is enabled and a supported tag set loaded + if (CFG.showWikiLinks && (tagFileName.toLowerCase().startsWith("danbooru") || tagFileName.toLowerCase().startsWith("e621"))) { + let wikiLink = document.createElement("a"); + wikiLink.classList.add("acWikiLink"); + wikiLink.innerText = "?"; + + let linkPart = displayText; + // Only use alias result if it is one + if (displayText.includes("➝")) + linkPart = displayText.split(" ➝ ")[1]; + + // Set link based on selected file + let tagFileNameLower = tagFileName.toLowerCase(); + if (tagFileNameLower.startsWith("danbooru")) { + wikiLink.href = `https://danbooru.donmai.us/wiki_pages/${linkPart}`; + } else if (tagFileNameLower.startsWith("e621")) { + wikiLink.href = `https://e621.net/wiki_pages/${linkPart}`; + } + + wikiLink.target = "_blank"; + flexDiv.appendChild(wikiLink); + } + + flexDiv.appendChild(itemText); + // Add post count & color if it's a tag // Wildcards & Embeds have no tag category if (![ResultType.wildcardFile, ResultType.wildcardTag, ResultType.embedding].includes(result.type)) { @@ -461,7 +493,7 @@ function addResultsToList(textArea, results, tagword, resetList) { if (!colorGroup[cat]) cat = "-1"; - itemText.style = `color: ${colorGroup[cat][mode]};`; + flexDiv.style = `color: ${colorGroup[cat][mode]};`; } // Post count diff --git a/scripts/tag_autocomplete_helper.py b/scripts/tag_autocomplete_helper.py index 392e62c..9ed5bbc 100644 --- a/scripts/tag_autocomplete_helper.py +++ b/scripts/tag_autocomplete_helper.py @@ -224,6 +224,7 @@ def on_ui_settings(): shared.opts.add_option("tac_delayTime", shared.OptionInfo(100, "Time in ms to wait before triggering completion again (Requires restart)", section=TAC_SECTION)) shared.opts.add_option("tac_useWildcards", shared.OptionInfo(True, "Search for wildcards", section=TAC_SECTION)) shared.opts.add_option("tac_useEmbeddings", shared.OptionInfo(True, "Search for embeddings", section=TAC_SECTION)) + shared.opts.add_option("tac_showWikiLinks", shared.OptionInfo(False, "Show '?' next to tags, linking to its Danbooru or e621 wiki page (Warning: This is an external site and very likely contains NSFW examples!)", section=TAC_SECTION)) # Insertion related settings shared.opts.add_option("tac_replaceUnderscores", shared.OptionInfo(True, "Replace underscores with spaces on insertion", section=TAC_SECTION)) shared.opts.add_option("tac_escapeParentheses", shared.OptionInfo(True, "Escape parentheses on insertion", section=TAC_SECTION))