Danbooru Tag Copier

Automatically copy all general tags from danbooru page to your clipboard

2022-10-21 일자. 최신 버전을 확인하세요.

질문, 리뷰하거나, 이 스크립트를 신고하세요.
  1. // ==UserScript==
  2. // @name Danbooru Tag Copier
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Automatically copy all general tags from danbooru page to your clipboard
  6. // @author watzon
  7. // @match https://danbooru.donmai.us/posts/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=donmai.us
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. const copyEmoji = '📋';
  16.  
  17. const artistsHeader = document.querySelectorAll('h3.artist-tag-list')[0]
  18. const copyrightHeader = document.querySelectorAll('h3.copyright-tag-list')[0]
  19. const characterHeader = document.querySelectorAll('h3.character-tag-list')[0]
  20. const generalHeader = document.querySelectorAll('h3.general-tag-list')[0]
  21. const metaHeader = document.querySelectorAll('h3.meta-tag-list')[0]
  22.  
  23. const artistsList = document.querySelectorAll('ul.artist-tag-list > li')
  24. const copyrightList = document.querySelectorAll('ul.copyright-tag-list > li')
  25. const characterList = document.querySelectorAll('ul.character-tag-list > li')
  26. const generalList = document.querySelectorAll('ul.general-tag-list > li')
  27. const metaList = document.querySelectorAll('ul.meta-tag-list > li')
  28.  
  29. const copyTags = (list) => {
  30. console.log(list);
  31. const tags = Array.from(list).map((li) => li.getAttribute('data-tag-name'));
  32. const taglist = tags.join(', ');
  33. console.log(taglist);
  34.  
  35. if (window.clipboardData && window.clipboardData.setData) {
  36. // Internet Explorer-specific code path to prevent textarea being shown while dialog is visible.
  37. return window.clipboardData.setData("Text", taglist);
  38.  
  39. }
  40.  
  41. else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
  42. var textarea = document.createElement("textarea");
  43. textarea.textContent = taglist;
  44. textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in Microsoft Edge.
  45. document.body.appendChild(textarea);
  46. textarea.select();
  47. try {
  48. return document.execCommand("copy"); // Security exception may be thrown by some browsers.
  49. }
  50. catch (ex) {
  51. console.warn("Copy to clipboard failed.", ex);
  52. return prompt("Copy to clipboard: Ctrl+C, Enter", taglist);
  53. }
  54. finally {
  55. document.body.removeChild(textarea);
  56. }
  57. }
  58. }
  59.  
  60. const lists = [
  61. [artistsHeader, artistsList],
  62. [copyrightHeader, copyrightList],
  63. [characterHeader, characterList],
  64. [generalHeader, generalList],
  65. [metaHeader, metaList],
  66. ];
  67.  
  68. for (const [header, list] of lists) {
  69. if (!header || !list) continue;
  70. const button = document.createElement('button');
  71. button.onclick = () => copyTags(list);
  72. button.setHTML(copyEmoji);
  73. button.setAttribute('type', 'button');
  74. button.setAttribute('title', 'Copy tags to clipboard');
  75. button.style.backgroundColor = 'transparent';
  76. button.style.border = 'none';
  77. button.style.padding = '0 4px';
  78. header.appendChild(button);
  79. }
  80. })();