Skip to content

Instantly share code, notes, and snippets.

@Birch-san
Created March 3, 2025 19:39
Show Gist options
  • Save Birch-san/a5c4b061b2a4029704f5adfadb87dc88 to your computer and use it in GitHub Desktop.
Save Birch-san/a5c4b061b2a4029704f5adfadb87dc88 to your computer and use it in GitHub Desktop.
Danbooru tag to prompt bookmarklet
javascript: (async function copyTags() {
const replacements = {
v: "peace sign",
"double v": "double peace",
"|_|": "bar eyes",
"\\||/": "opem \\m/",
":|": "neutral face",
";|": "neutral face",
"eyepatch bikini": "square bikini",
"tachi-e": "character image",
};
const blockedTags = ["original"];
const regex = /(\d(boy|girl|other)s?)/i;
const prompt = [
...document.querySelectorAll("ul.artist-tag-list li"),
...document.querySelectorAll("ul.character-tag-list li"),
...document.querySelectorAll("ul.copyright-tag-list li"),
...document.querySelectorAll("ul.general-tag-list li"),
]
.map((li) => li.getAttribute("data-tag-name"))
.filter((tag) => tag && tag.length > 0 && !blockedTags.includes(tag))
.map((tag) => (tag.length <= 3 ? tag : tag.replace(/_/g, " ")))
.map((tag) => replacements[tag] || tag)
.sort((a, b) => {
if (regex.test(a)) {
return -1;
}
if (regex.test(b)) {
return 1;
}
return 0;
})
.join(", ");
if (!prompt) {
alert("No tags found!");
return;
}
if (navigator.clipboard) {
try {
await navigator.clipboard.writeText(prompt);
} catch(err) {
console.warn("Clipboard copy failed.", err);
alert(`Can't copy to clipboard. Here's the prompt, copy it yourself:\n${prompt}`);
}
} else {
const textarea = document.createElement("textarea");
textarea.value = prompt;
document.body.appendChild(textarea);
textarea.select();
document.execCommand("copy");
document.body.removeChild(textarea);
}
const frag = document.createDocumentFragment();
const explanation = document.createElement('div');
explanation.innerText = "Copied to clipboard, probably:";
explanation.style = "text-wrap: wrap; padding-left: 5px; padding-right: 5px;";
frag.appendChild(explanation);
const pre = document.createElement('pre');
pre.style = "text-wrap: wrap; padding-left: 5px; padding-right: 5px;";
pre.innerText = prompt;
frag.appendChild(pre);
document.getElementById('top').appendChild(frag);
})();
@Birch-san
Copy link
Author

Birch-san commented Mar 3, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment