Guest User

copy tag

a guest
Oct 12th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.09 KB | Source Code | 0 0
  1. // ==UserScript==
  2. // @name         Tags to clipboard for prompts
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  Copy image tags for prompting
  6. // @author       /h/ anon
  7. // @match        https://danbooru.donmai.us/*
  8. // @icon         https://www.google.com/s2/favicons?sz=64&domain=donmai.us
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13.   "use strict";
  14.  
  15.   const allTagsEl = document.querySelector(".categorized-tag-list");
  16.   const tagCategoryEls = allTagsEl.querySelectorAll("h3");
  17.  
  18.   [...tagCategoryEls].forEach((categoryEl) => {
  19.     const tagsWrapperEl = categoryEl.nextElementSibling;
  20.     const tagEls = tagsWrapperEl.querySelectorAll("[data-tag-name]");
  21.     const tags = [...tagEls].map((el) =>
  22.       el.dataset.tagName.replaceAll("_", " ")
  23.     );
  24.  
  25.     categoryEl.insertAdjacentHTML(
  26.       "afterend",
  27.       `<button id="${categoryEl.className}">Copy Tags</button>`
  28.     );
  29.  
  30.     document.getElementById(categoryEl.className).addEventListener('click', () => {
  31.         navigator.clipboard.writeText(tags.join(", "));
  32.     });
  33.   });
  34. })();
Tags: userscript
Add Comment
Please, Sign In to add comment