Random Prompt from Related Tags.

Press Ctrl+Y to create a random prompt from the results of Danbooru's RelatedTags and copy it to the clipboard. If you press Alt, it will be 20, if you press Shift, it will be 30, and if you press both Alt and Shift, it will be 50.

  1. // ==UserScript==
  2. // @name Random Prompt from Related Tags.
  3. // @namespace https://www6.notion.site/dc99953d5f04405c893fba95dace0722
  4. // @version 1
  5. // @description Press Ctrl+Y to create a random prompt from the results of Danbooru's RelatedTags and copy it to the clipboard. If you press Alt, it will be 20, if you press Shift, it will be 30, and if you press both Alt and Shift, it will be 50.
  6. // @author SenY
  7. // @match https://danbooru.donmai.us/related_tag*
  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 generateTags = (tagsLimit) => {
  16. let tags = document.getElementById("search_query").value.split(" ").map(x => x.trim().replace(/_/g, " "));
  17. let order = document.getElementById("search_order")
  18. if(order && order.value){
  19. order = order.value.toLowerCase();
  20. while (tags.length < tagsLimit){
  21. document.querySelectorAll('[href^="/posts?tags="]').forEach(a => {
  22. let tr = a.closest("tr");
  23. let tag = a.textContent.trim().replace(/_/g, " ");
  24. let num = tr.querySelector("."+order+"-column span").textContent.replace("%", "") - 0;
  25. let randomNum = Math.floor(Math.random() * 101);
  26. if (num > randomNum && tags.length < tagsLimit && !tags.includes(tag) ) {
  27. tags.push(tag);
  28. }
  29. })
  30. }
  31. console.log(tags.join(", "));
  32. navigator.clipboard.writeText(tags.join(", "));
  33. }else{
  34. alert("Please select any value on Order property.");
  35. }
  36. }
  37. document.addEventListener("keyup", (e) => {
  38. if (e.ctrlKey && e.code === 'KeyY') {
  39. if (!e.altKey && !e.shiftKey) {
  40. generateTags(10);
  41. } else if (e.altKey && !e.shiftKey) {
  42. generateTags(20);
  43. } else if (!e.altKey && e.shiftKey) {
  44. generateTags(30);
  45. } else if (e.altKey && e.shiftKey) {
  46. generateTags(50);
  47. }
  48. }
  49. });
  50. })();