Get Booru Tags (Edited)

Press the [`] tilde key under ESC to open a prompt with all tags

  1. // ==UserScript==
  2. // @name Get Booru Tags (Edited)
  3. // @namespace https://github.com/onusai/
  4. // @version 0.12
  5. // @description Press the [`] tilde key under ESC to open a prompt with all tags
  6. // @author Onusai#6441/ScriptAnon
  7. // @require https://code.jquery.com/jquery-3.6.1.min.js
  8. // @match https://gelbooru.com/index.php?page=post&s=view&id=*
  9. // @match https://danbooru.donmai.us/posts/*
  10. // @match https://e621.net/posts/*
  11. // @match https://rule34.xxx/index.php?page=post&s=view&id=*
  12. // @match https://rule34.paheal.net/post/view/*
  13. // @match https://furry.booru.org/index.php?page=post&s=view&id=*
  14. // @match https://e926.net/posts/*
  15. // @match https://booru.allthefallen.moe/posts/*
  16. // @match https://tbib.org/index.php?page=post&s=view&id=*
  17. // @match https://aibooru.online/posts/*
  18. // @match https://lolibooru.moe/post/show/*
  19. // @match https://infinibooru.moe/post/*
  20. // @grant none
  21. // @license MIT
  22. // ==/UserScript==
  23.  
  24. (function () {
  25. 'use strict';
  26.  
  27.  
  28. let hot_key = "`"; // edit to change hotkey
  29. let remove_commas = false; // set to false to include commas
  30. let remove_underscores = true; // set to false to include underscore
  31. let remove_parentheses = true; // set to false to include parentheses
  32.  
  33.  
  34. $(document).on('keydown', (event) => {
  35. if (event.key == hot_key) {
  36. let tags = null;
  37. if (window.location.href.includes("/gelbooru.com")) tags = get_gel_tags();
  38. else if (window.location.href.includes("/danbooru.donmai.us")) tags = get_dan_tags();
  39. else if (window.location.href.includes("/e621.net")) tags = get_e621_tags();
  40. else if (window.location.href.includes("/rule34.xxx")) tags = get_rule34xxx_tags();
  41. else if (window.location.href.includes("/rule34.paheal.net")) tags = get_rule34paheal_tags();
  42. else if (window.location.href.includes("/furry.booru.org")) tags = get_furrybooru_tags();
  43. else if (window.location.href.includes("/e926.net")) tags = get_e926_tags();
  44. else if (window.location.href.includes("/booru.allthefallen.moe")) tags = get_dan_tags();
  45. else if (window.location.href.includes("/tbib.org")) tags = get_furrybooru_tags();
  46. else if (window.location.href.includes("/aibooru.online")) tags = get_dan_tags();
  47. else if (window.location.href.includes("/lolibooru.moe")) tags = get_rule34xxx_tags();
  48. else if (window.location.href.includes("/infinibooru.moe")) tags = get_infinibooru_tags();
  49.  
  50. if (tags != null) {
  51. for (var i = 0; i < tags.length; i++) {
  52. if (remove_underscores) tags[i] = tags[i].replace("_", " ");
  53. else tags[i] = tags[i].replace(" ", "_");
  54. }
  55. let fprompt = tags.join(", ");
  56. if (remove_commas) fprompt = fprompt.replaceAll(",", "");
  57. if (remove_parentheses) fprompt = fprompt.replaceAll("(", "").replaceAll(")", "")
  58. prompt("Prompt: " + tags.length + " tags\nTo check token length go to: https://beta.openai.com/tokenizer", fprompt);
  59. }
  60. }
  61. })
  62.  
  63. function get_gel_tags() {
  64. let elms = ["tag-type-general", "tag-type-character", "tag-type-metadata", "tag-type-artist", "tag-type-copyright"];
  65. let iprompt = [];
  66. elms.forEach(tag => {
  67. Array.from(document.getElementsByClassName(tag)).forEach(e => {
  68. iprompt.push(e.children[1].textContent);
  69. })
  70. });
  71. return iprompt;
  72. }
  73.  
  74. function get_dan_tags() {
  75. let elms = ["general-tag-list", "character-tag-list", "meta-tag-list", "artist-tag-list", "copyright-tag-list"];
  76. let iprompt = [];
  77. elms.forEach(tag => {
  78. Array.from(document.getElementsByClassName(tag)).forEach(e => {
  79. if (e.tagName == "UL") {
  80. Array.from(e.getElementsByClassName("search-tag")).forEach(s => {
  81. iprompt.push(s.textContent);
  82. })
  83. }
  84. })
  85. });
  86. return iprompt;
  87. }
  88.  
  89. function get_e621_tags() {
  90. let elms = ["artist-tag-list", "species-tag-list", "general-tag-list", "artist-tag-list"];
  91. let iprompt = [];
  92. elms.forEach(tag => {
  93. Array.from(document.getElementsByClassName(tag)).forEach(e => {
  94. if (e.tagName == "UL") {
  95. Array.from(e.getElementsByClassName("search-tag")).forEach(s => {
  96. iprompt.push(s.textContent);
  97. })
  98. }
  99. })
  100. });
  101. return iprompt;
  102. }
  103.  
  104. function get_rule34paheal_tags() {
  105. let elms = ["tag_name_cell"];
  106. let iprompt = [];
  107. elms.forEach(tag => {
  108. Array.from(document.getElementsByClassName(tag)).forEach(e => {
  109. Array.from(e.getElementsByClassName("tag_name")).forEach(s => {
  110. iprompt.push(s.innerHTML);
  111. })
  112. })
  113. });
  114. return iprompt;
  115. }
  116.  
  117. function get_rule34xxx_tags() {
  118. let elm = document.getElementById("tag-sidebar");
  119. let pattern = /(^\d)|(\s)|([[A-Za-z])/g;
  120. let iprompt = [];
  121.  
  122. let children = elm.children;
  123. Array.from(children).forEach(li => {
  124. var tag = li.innerText.replace("?", "").trim();
  125. var tagarray = tag.match(pattern).toString().replaceAll(",", "").trim();
  126. iprompt.push(tagarray);
  127. iprompt = iprompt.filter(item => item !== "Copyright");
  128. iprompt = iprompt.filter(item => item !== "Artist");
  129. iprompt = iprompt.filter(item => item !== "General");
  130. iprompt = iprompt.filter(item => item !== "Character");
  131. });
  132. return iprompt;
  133. }
  134.  
  135. function get_furrybooru_tags() {
  136. let elms = ["tag-type-general", "tag-type-character", "tag-type-metadata", "tag-type-artist", "tag-type-copyright"];
  137. let iprompt = [];
  138. elms.forEach(tag => {
  139. Array.from(document.getElementsByClassName(tag)).forEach(e => {
  140. iprompt.push(e.children[0].textContent);
  141. })
  142. });
  143. return iprompt;
  144. }
  145.  
  146. function get_e926_tags() {
  147. let elms = ["artist-tag-list", "species-tag-list", "general-tag-list", "artist-tag-list"];
  148. let iprompt = [];
  149. elms.forEach(tag => {
  150. Array.from(document.getElementsByClassName(tag)).forEach(e => {
  151. if (e.tagName == "UL") {
  152. Array.from(e.getElementsByClassName("search-tag")).forEach(s => {
  153. iprompt.push(s.textContent);
  154. })
  155. }
  156. })
  157. });
  158. return iprompt;
  159. }
  160.  
  161. function get_infinibooru_tags() {
  162. let elm = document.getElementsByClassName("compact-tags");
  163. let textcontent = elm[0].textContent;
  164. let iprompt = [];
  165. let tagarray = textcontent.split(' ');
  166. tagarray.forEach(e => {
  167. iprompt.push(e.replace("_", " ").replace("_", " ").replace("_", " "));
  168. })
  169. return iprompt;
  170. }
  171.  
  172. })();