Danbooru Tag Extractor

Extract tags from Danbooru image pages and copy them to the clipboard when a button is clicked.

  1. // ==UserScript==
  2. // @name Danbooru Tag Extractor
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Extract tags from Danbooru image pages and copy them to the clipboard when a button is clicked.
  6. // @author Shinnpuru
  7. // @match https://danbooru.donmai.us/posts/*
  8. // @grant GM_setClipboard
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function extractTags() {
  16. // Select all tag links within the tag list section
  17. let tagElements = document.querySelectorAll('#tag-list a.search-tag');
  18.  
  19. // Extract the text content of each tag
  20. let tags = [];
  21. tagElements.forEach(function(tagElement) {
  22. tags.push(tagElement.textContent.trim());
  23. });
  24.  
  25. // Join the tags into a string separated by spaces
  26. return tags.join(',');
  27. }
  28.  
  29. function createCopyButton() {
  30. // Create the button element
  31. let button = document.createElement('button');
  32. button.innerText = 'Copy Tags';
  33. button.style.position = 'fixed';
  34. button.style.bottom = '10px';
  35. button.style.right = '10px';
  36. button.style.padding = '10px';
  37. button.style.backgroundColor = '#008CBA';
  38. button.style.color = 'white';
  39. button.style.border = 'none';
  40. button.style.borderRadius = '5px';
  41. button.style.cursor = 'pointer';
  42. button.style.zIndex = '9999';
  43.  
  44. // Add click event listener to the button
  45. button.addEventListener('click', function() {
  46. let tags = extractTags();
  47. GM_setClipboard(tags);
  48. alert('Tags copied to clipboard!');
  49. });
  50.  
  51. // Append the button to the body
  52. document.body.appendChild(button);
  53. }
  54.  
  55. // Run the script when the page is fully loaded
  56. window.addEventListener('load', createCopyButton);
  57.  
  58. })();