Midjourney一键点击

当你在Discord中打开Midjourney机器人时,一次点击一排的所有按钮!😊

  1. // ==UserScript==
  2. // @name Midjourney Click All
  3. // @description Click all the buttons in a row at once when you're in Discord with Midjourney bot open! 😊
  4. // @author mefengl
  5. // @version 0.3.3
  6. // @namespace https://github.com/mefengl
  7. // @icon https://www.google.com/s2/favicons?sz=64&domain=midjourney.com
  8. // @license MIT
  9. // @match https://discord.com/channels/*
  10. // @grant none
  11.  
  12. // @name:en Midjourney Click All
  13. // @description:en Click all the buttons in a row at once when you're in Discord with Midjourney bot open! 😊
  14. // @name:zh-CN Midjourney一键点击
  15. // @description:zh-CN 当你在Discord中打开Midjourney机器人时,一次点击一排的所有按钮!😊
  16. // @name:es Midjourney Click Todo
  17. // @description:es ¡Haz clic en todos los botones en una fila a la vez cuando estés en Discord con el bot de Midjourney abierto! 😊
  18. // @name:hi Midjourney सभी पर क्लिक करें
  19. // @description:hi जब आप Discord में Midjourney बॉट के साथ हों, तो एक बार में सभी बटनों पर क्लिक करें! 😊
  20. // @name:ar Midjourney انقر على الكل
  21. // @description:ar انقر على جميع الأزرار في صف واحد في وقت واحد عندما تكون في Discord مع بوت Midjourney مفتوح! 😊
  22. // @name:pt Midjourney Clique Tudo
  23. // @description:pt Clique em todos os botões em uma linha de uma vez quando estiver no Discord com o bot Midjourney aberto! 😊
  24. // @name:ru Midjourney Нажмите на все
  25. // @description:ru Нажмите все кнопки в ряду сразу, когда вы находитесь в Discord с открытым ботом Midjourney! 😊
  26. // @name:ja Midjourney すべてをクリック
  27. // @description:ja DiscordでMidjourneyボットを開いているときに、一度にすべてのボタンをクリックします!😊
  28. // @name:de Midjourney Klick Alles
  29. // @description:de Klicken Sie auf alle Tasten in einer Reihe auf einmal, wenn Sie in Discord mit dem geöffneten Midjourney-Bot sind! 😊
  30. // @name:fr Midjourney Cliquez sur Tout
  31. // @description:fr Cliquez sur tous les boutons d'une rangée à la fois lorsque vous êtes sur Discord avec le bot Midjourney ouvert! 😊
  32. // ==/UserScript==
  33. "use strict";
  34. (() => {
  35. var __async = (__this, __arguments, generator) => {
  36. return new Promise((resolve, reject) => {
  37. var fulfilled = (value) => {
  38. try {
  39. step(generator.next(value));
  40. } catch (e) {
  41. reject(e);
  42. }
  43. };
  44. var rejected = (value) => {
  45. try {
  46. step(generator.throw(value));
  47. } catch (e) {
  48. reject(e);
  49. }
  50. };
  51. var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
  52. step((generator = generator.apply(__this, __arguments)).next());
  53. });
  54. };
  55.  
  56. // ../../packages/monkit/dist/index.mjs
  57. function onUrlChange(callback) {
  58. let oldHref = document.location.href;
  59. return window.setInterval(() => {
  60. const newHref = document.location.href;
  61. if (oldHref !== newHref)
  62. callback(oldHref = newHref);
  63. }, 1e3);
  64. }
  65.  
  66. // ../../packages/midkit/dist/index.mjs
  67. function sleep(ms) {
  68. return new Promise((resolve) => setTimeout(resolve, ms));
  69. }
  70. function getButtonContainers(container = document.body) {
  71. return Array.from(container.querySelectorAll("[id^='message-accessorie'] [class^='children']"));
  72. }
  73. var CLONE_BUTTON_CLASS = "cloned-button";
  74. function getButtons(temp) {
  75. const buttons = temp.querySelectorAll("button");
  76. const originalButtons = Array.from(buttons).filter((button) => !button.classList.contains(CLONE_BUTTON_CLASS));
  77. return originalButtons;
  78. }
  79. function oneMoreButton(temp) {
  80. const buttons = getButtons(temp);
  81. const lastButton = buttons[buttons.length - 1];
  82. const cloneButton = lastButton.cloneNode();
  83. cloneButton.classList.add(CLONE_BUTTON_CLASS);
  84. lastButton.parentNode.insertBefore(cloneButton, lastButton.nextSibling);
  85. return cloneButton;
  86. }
  87. function getSubmitButton() {
  88. return document.querySelector('button[type="submit"]');
  89. }
  90. function submitForm() {
  91. return __async(this, null, function* () {
  92. const submitButton = getSubmitButton();
  93. if (!submitButton) {
  94. console.log("No submit button found");
  95. return;
  96. }
  97. submitButton.click();
  98. });
  99. }
  100. function getFormNumber() {
  101. const forms = document.querySelectorAll("form");
  102. return forms.length;
  103. }
  104. function clickAllButtonsWithConfirm(temp) {
  105. return __async(this, null, function* () {
  106. const buttons = getButtons(temp);
  107. for (const button of buttons) {
  108. button.click();
  109. while (getFormNumber() === 1) {
  110. yield sleep(500);
  111. console.log("Opening...");
  112. }
  113. submitForm();
  114. while (getFormNumber() === 2) {
  115. yield sleep(500);
  116. console.log("Submitting...");
  117. }
  118. }
  119. });
  120. }
  121. function isClicking(button) {
  122. return button.querySelector("div > div").getAttribute("aria-hidden") === "true";
  123. }
  124. function clickAllButtons(temp) {
  125. return __async(this, null, function* () {
  126. const buttons = getButtons(temp);
  127. buttons.pop();
  128. for (const button of buttons) {
  129. button.click();
  130. while (!isClicking(button)) {
  131. yield sleep(10);
  132. console.log("Waiting for clicking...");
  133. }
  134. while (isClicking(button)) {
  135. yield sleep(500);
  136. console.log("Clicking...");
  137. }
  138. }
  139. });
  140. }
  141. function smartClickAllButtons(temp) {
  142. return __async(this, null, function* () {
  143. const buttons = getButtons(temp);
  144. const testText = buttons[0].textContent;
  145. if (testText == null ? void 0 : testText.startsWith("U")) {
  146. yield clickAllButtons(temp);
  147. } else {
  148. yield clickAllButtonsWithConfirm(temp);
  149. }
  150. });
  151. }
  152. function getScrollerInner() {
  153. return document.querySelector("[data-list-id='chat-messages']");
  154. }
  155. function onScrollerInnerChange(callback) {
  156. let observer = new MutationObserver((mutations) => {
  157. for (let mutation of mutations) {
  158. for (let node of Array.from(mutation.addedNodes)) {
  159. if (node.nodeName.toLowerCase() === "li" && node instanceof Element)
  160. callback(node);
  161. }
  162. }
  163. });
  164. const scrollerInner = getScrollerInner();
  165. if (!scrollerInner)
  166. return null;
  167. observer.observe(scrollerInner, { childList: true });
  168. return observer;
  169. }
  170.  
  171. // src/index.ts
  172. function initialize() {
  173. return __async(this, null, function* () {
  174. yield new Promise((resolve) => window.addEventListener("load", resolve));
  175. yield new Promise((resolve) => setTimeout(resolve, 6e3));
  176. });
  177. }
  178. function addClickAllButton(root) {
  179. const buttonContainers = getButtonContainers(root);
  180. for (const buttonContainer of buttonContainers) {
  181. if (getButtons(buttonContainer).length < 4)
  182. continue;
  183. const clickAllButton = oneMoreButton(buttonContainer);
  184. clickAllButton.textContent = "ALL";
  185. clickAllButton.addEventListener("click", () => {
  186. smartClickAllButtons(buttonContainer);
  187. });
  188. }
  189. }
  190. function addClickAllButtonWithCheck(root) {
  191. if (!(root == null ? void 0 : root.querySelector(".cloned-button")))
  192. addClickAllButton(root);
  193. }
  194. function checkClickAllButtonFiveTimes(root) {
  195. return __async(this, null, function* () {
  196. for (let i = 0; i < 5; i++) {
  197. yield new Promise((resolve) => setTimeout(resolve, 3e3));
  198. addClickAllButtonWithCheck(root);
  199. }
  200. });
  201. }
  202. function addClickAllButtonWithCheckFiveTimes(root) {
  203. return __async(this, null, function* () {
  204. addClickAllButton(root);
  205. yield checkClickAllButtonFiveTimes(root);
  206. });
  207. }
  208. function main() {
  209. return __async(this, null, function* () {
  210. yield initialize();
  211. addClickAllButton(void 0);
  212. onScrollerInnerChange(addClickAllButtonWithCheckFiveTimes);
  213. onUrlChange(() => {
  214. addClickAllButton(void 0);
  215. onScrollerInnerChange(addClickAllButtonWithCheckFiveTimes);
  216. });
  217. });
  218. }
  219. (function() {
  220. main();
  221. })();
  222. })();