Danbooru Tags Copier

1-Click copies Danbooru, deep Danbooru tags. Useful as AI drawing prompts.

  1. // ==UserScript==
  2. // @name Danbooru Tags Copier
  3. // @namespace ruocaled
  4. // @version 0.11
  5. // @description 1-Click copies Danbooru, deep Danbooru tags. Useful as AI drawing prompts.
  6. // @author You
  7. // @match https://danbooru.donmai.us/posts/*
  8. // @match http://dev.kanotype.net:8003/deepdanbooru/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=donmai.us
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13. (function() {
  14. const copy = (hostname) => {
  15. if (hostname === "danbooru.donmai.us") {
  16. let tags = $(`.search-tag`).map((i, el) => $(el).text()).toArray().filter(tag => !tag.match(/hand|nail|finger|wrist/)).join(" ").toString();
  17. if (tags) {
  18. navigator.clipboard.writeText(tags);
  19. }
  20. return tags;
  21. } else {
  22. let tags = $(".col-md-auto tr a").map((i, el) => {
  23. return {
  24. tag: $(el).text().replace(/_/g, " "),
  25. score: parseFloat($(el).parent().next().text())
  26. };
  27. }).toArray().sort((a, b) => (b.score - a.score)).filter(el => el.score > 0.6 && !el.tag.match(/rating:/i)).map(el => el.tag).join(",");
  28.  
  29. return tags;
  30. }
  31.  
  32. };
  33.  
  34. const addBtns = (hostname) => {
  35. if (hostname === "danbooru.donmai.us") {
  36. $("#post-options ul").append(`<li id="post-option-copy-tags">
  37. <a class="copy-tags-link" href="#">Copy tags</a>
  38. </li>`);
  39. $("#post-option-copy-tags").click(() => {
  40. const tags = copy(hostname);
  41. $("#content").prepend(`<div class="notice notice-small post-notice">
  42. Tags have been copied to your clipboard. (<span style="color:var(--link-color)">${tags}</span>)
  43. </div>`);
  44. });
  45. } else {
  46. $('img').after(`<div class="col-sm"></div><a class="copy-tags-link" href="#">Copy tags</a></div>`);
  47. $(".copy-tags-link").click(() => {
  48. const tags = copy(hostname);
  49. $('.copy-tags-link').after(`<div>Sorted tags: <span style="color:blueviolet">${tags}</a> </div>`)
  50. });
  51. }
  52.  
  53. };
  54.  
  55. addBtns(location.hostname);
  56.  
  57. // Your code here...
  58. })();