Skip to content

Commit

Permalink
Option to show ? wiki links for danbooru/e621 tags
Browse files Browse the repository at this point in the history
Disabled by default since the wiki pages likely contain NSFW images.
Closes #109
  • Loading branch information
DominikDoom committed Jan 12, 2023
1 parent 52593e6 commit d4db6a7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
36 changes: 34 additions & 2 deletions javascript/tagAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -446,6 +453,31 @@ function addResultsToList(textArea, results, tagword, resetList) {
// Print search term bolded in result
itemText.innerHTML = displayText.replace(tagword, `<b>${tagword}</b>`);

// 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)) {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions scripts/tag_autocomplete_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit d4db6a7

Please sign in to comment.