e621 tag extract

add a button on post page that list all tags joined by comma, I hope you find it somewhat helpful in AI image prompts with https://t.me/makefoxbot. :)

  1. // ==UserScript==
  2. // @name e621 tag extract
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-06-18
  5. // @description add a button on post page that list all tags joined by comma, I hope you find it somewhat helpful in AI image prompts with https://t.me/makefoxbot. :)
  6. // @author shadystray (chatgpt really)
  7. // @match https://e621.net/posts/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=e621.net
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Function to find and join text by XPath
  18. function findAndJoinTextByXPath(xpath) {
  19. let results = [];
  20. let nodesSnapshot = document.evaluate(xpath, document, null, XPathResult.ANY_TYPE, null);
  21. let node = nodesSnapshot.iterateNext();
  22.  
  23. while (node) {
  24. results.push(node.textContent);
  25. node = nodesSnapshot.iterateNext();
  26. }
  27.  
  28. return results.join(", ");
  29. }
  30.  
  31. // Create the floating button
  32. let button = document.createElement('button');
  33. button.id = 'floatingButton';
  34. button.textContent = '+';
  35. button.style.position = 'fixed';
  36. button.style.bottom = '20px';
  37. button.style.right = '20px';
  38. button.style.backgroundColor = '#007bff';
  39. button.style.color = 'white';
  40. button.style.border = 'none';
  41. button.style.borderRadius = '50%';
  42. button.style.width = '50px';
  43. button.style.height = '50px';
  44. button.style.textAlign = 'center';
  45. button.style.fontSize = '24px';
  46. button.style.cursor = 'pointer';
  47. button.style.boxShadow = '2px 2px 5px rgba(0, 0, 0, 0.3)';
  48.  
  49. // Add click event listener to the button
  50. button.addEventListener('click', function() {
  51. let xpath = '/html/body/div[1]/div[3]/div/aside/section[3]/ul/li/a[@class="search-tag"]/text()'; // Replace with your XPath
  52. let joinedText = findAndJoinTextByXPath(xpath);
  53. console.log(joinedText);
  54. alert(joinedText); // Display the result in an alert for demonstration
  55. });
  56.  
  57. // Append the button to the body
  58. document.body.appendChild(button);
  59. })();