[Huggingface] Text to Video Brute-Forcer

Clicks the generate button until success

  1. // ==UserScript==
  2. // @name [Huggingface] Text to Video Brute-Forcer
  3. // @namespace onlypuppy7
  4. // @match https://damo-vilab-modelscope-text-to-video-synthesis.hf.space/*
  5. // @grant GM_setValue
  6. // @grant GM_getValue
  7. // @grant GM_addStyle
  8. // @grant GM_registerMenuCommand
  9. // @grant GM_unregisterMenuCommand
  10. // @grant GM_getResourceText
  11. // @grant GM_getResourceURL
  12. // @grant GM_addElement
  13. // @grant GM_openInTab
  14. // @version 1.0
  15. // @author onlypuppy7
  16. // @description Clicks the generate button until success
  17. // @license MIT
  18. // ==/UserScript==
  19.  
  20. (() => {
  21. const intervalMs = 200;
  22. let isScriptInitiated = false;
  23. let framesSliderValue = GM_getValue("framesSliderValue", 32);
  24.  
  25. let configMenu;
  26. let isMinimized = false;
  27.  
  28. const observeSlider = setInterval(() => {
  29. const labelWrap = document.querySelector('.label-wrap');
  30. if (labelWrap) {
  31. labelWrap.click();
  32. const framesSlider = document.querySelector("#range_id_1");
  33. if (framesSlider) {
  34. clearInterval(observeSlider);
  35. setFramesSliderValue(framesSliderValue);
  36. }
  37. }
  38. }, 100);
  39. function checkForText() {
  40. if (isScriptInitiated) {
  41. const text = document.documentElement.textContent;
  42. if (text.includes("queue: ")) {
  43. console.log("Text found! Stopping...");
  44. setStatus("done");
  45. return;
  46. }
  47.  
  48. const button = document.querySelector("#component-6");
  49. if (button) {
  50. button.click();
  51. console.log("Button clicked. Waiting for the next attempt...");
  52. }
  53.  
  54. setTimeout(checkForText, intervalMs);
  55. }
  56. }
  57.  
  58. function setFramesSliderValue(value) {
  59. const framesSlider = document.querySelector("#range_id_1");
  60. if (framesSlider) {
  61. framesSlider.value = value;
  62. framesSlider.dispatchEvent(new Event("input", { bubbles: true }));
  63. console.log(`Frames slider set to ${value}.`);
  64. }
  65. }
  66.  
  67. function handleKeyPress(event) {
  68. if (event.key === "Enter") {
  69. startBruteForcer();
  70. }
  71. }
  72.  
  73. function updateFramesSliderValue(newValue) {
  74. framesSliderValue = newValue;
  75. GM_setValue("framesSliderValue", newValue);
  76. }
  77.  
  78. function minimizeMenu() {
  79. isMinimized = !isMinimized;
  80. const contentContainer = document.getElementById("config-menu-content");
  81. const minimizeButton = document.getElementById("minimize-button");
  82. if (contentContainer && minimizeButton) {
  83. contentContainer.style.display = isMinimized ? "none" : "block";
  84. minimizeButton.textContent = isMinimized ? "+" : "-";
  85. }
  86. }
  87.  
  88. function createConfigMenu() {
  89. configMenu = document.createElement("div");
  90. configMenu.id = "config-menu";
  91. configMenu.style.position = "fixed";
  92. configMenu.style.top = "20px";
  93. configMenu.style.left = "20px";
  94. configMenu.style.zIndex = "9999";
  95. configMenu.style.background = "rgba(255, 255, 255, 0.9)";
  96. configMenu.style.border = "1px solid #ccc";
  97. configMenu.style.borderRadius = "5px";
  98. configMenu.style.padding = "10px";
  99. configMenu.style.boxShadow = "0 0 10px rgba(0, 0, 0, 0.2)";
  100. configMenu.innerHTML = `
  101. <div id="config-menu-header" style="display: flex; justify-content: space-between; align-items: center;">
  102. <span id="config-menu-title" style="font-weight: bold;">Brute-Forcer Config </span>
  103. <button id="minimize-button" style="font-size: 16px; cursor: pointer;">-</button>
  104. </div>
  105. <div id="config-menu-content">
  106. <div>
  107. <label for="frames-slider">Frames:</label>
  108. <input type="number" id="frames-slider" min="16" max="32" step="1" style="width: 40px;">
  109. </div>
  110. <div>
  111. <label>Press Enter to Start</label>
  112. </div>
  113. <button id="start-button">Start Brute-Forcer</button>
  114. <button id="download-button">Download MP4</button>
  115. <div id="status-area"></div>
  116. </div>
  117. `;
  118.  
  119. document.body.appendChild(configMenu);
  120.  
  121. const framesSlider = document.getElementById("frames-slider");
  122. if (framesSlider) {
  123. framesSlider.value = framesSliderValue;
  124. framesSlider.addEventListener("input", (event) => {
  125. const newValue = parseInt(event.target.value);
  126. updateFramesSliderValue(newValue);
  127. });
  128. }
  129. const startButton = document.getElementById("start-button");
  130. startButton.addEventListener("click", () => {
  131. startBruteForcer();
  132. });
  133.  
  134. const downloadButton = document.getElementById("download-button");
  135. downloadButton.addEventListener("click", () => {
  136. const videoElement = document.querySelector('video');
  137. const filenameInput = document.querySelector('input[data-testid="textbox"]');
  138. if (videoElement && filenameInput) {
  139. const videoUrl = videoElement.getAttribute('src');
  140. const filename = filenameInput.value.trim();
  141. const pattern = /[^a-zA-Z0-9-_]/g;
  142. const sanitizedFilename = filename.replace(pattern, '_');
  143. if (sanitizedFilename) {
  144. const anchorElement = document.createElement('a');
  145. anchorElement.href = videoUrl;
  146. anchorElement.download = sanitizedFilename + '.mp4';
  147. anchorElement.click();
  148. } else {
  149. console.log('Invalid filename.');
  150. }
  151. } else {
  152. console.log('Video element or filename input not found.');
  153. }
  154.  
  155. function sanitizeFilename(filename) {
  156. // Regex pattern to replace invalid filename characters with underscores
  157. }
  158. });
  159.  
  160. const minimizeButton = document.getElementById("minimize-button");
  161. minimizeButton.addEventListener("click", () => {
  162. minimizeMenu();
  163. });
  164. }
  165.  
  166. function setStatus(status) {
  167. const statusArea = document.getElementById("status-area");
  168. if (statusArea) {
  169. statusArea.textContent = "";
  170. const statusIcon = document.createElement("span");
  171. statusIcon.className = "status-icon";
  172. statusArea.appendChild(statusIcon);
  173. statusArea.classList.remove("idle", "brute-forcing", "done");
  174. if (status === "idle") {
  175. statusArea.classList.add("idle");
  176. } else if (status === "brute-forcing") {
  177. statusArea.classList.add("brute-forcing");
  178. const loader = document.createElement("span");
  179. loader.className = "loader";
  180. statusArea.appendChild(loader);
  181. } else if (status === "done") {
  182. statusArea.classList.add("done");
  183. }
  184. }
  185. }
  186.  
  187. function startBruteForcer() {
  188. console.log("Script initiated.");
  189. isScriptInitiated = true;
  190. setStatus("brute-forcing");
  191. checkForText();
  192. }
  193.  
  194. function initializeScript() {
  195. GM_addStyle(`
  196. #config-menu {
  197. font-family: Arial, sans-serif;
  198. font-size: 14px;
  199. background-color: #fff;
  200. border: 1px solid #ccc;
  201. border-radius: 5px;
  202. box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  203. padding: 10px;
  204. position: absolute;
  205. top: 20px;
  206. left: 20px;
  207. z-index: 9999;
  208. }
  209.  
  210. #config-menu-header {
  211. display: flex;
  212. justify-content: space-between;
  213. align-items: center;
  214. background-color: #f0f0f0;
  215. padding: 5px;
  216. border-bottom: 1px solid #ccc;
  217. }
  218.  
  219. #config-menu-content {
  220. margin-top: 10px;
  221. }
  222.  
  223. #frames-slider,
  224. #frames-slider-value {
  225. display: inline-block;
  226. }
  227.  
  228. #enter-toggle-checkbox {
  229. margin-left: 5px;
  230. }
  231.  
  232. #start-button {
  233. margin-top: 10px;
  234. }
  235.  
  236. #status-area {
  237. margin-top: 20px;
  238. display: flex;
  239. align-items: center;
  240. }
  241.  
  242. .status-icon {
  243. display: inline-block;
  244. width: 10px;
  245. height: 10px;
  246. border-radius: 50%;
  247. margin-right: 5px;
  248. }
  249.  
  250. .idle .status-icon {
  251. background-color: gray;
  252. }
  253.  
  254. .brute-forcing .status-icon {
  255. background-color: darkblue;
  256. }
  257.  
  258. .done .status-icon {
  259. background-color: green;
  260. }
  261.  
  262. .loader {
  263. border: 3px solid #f3f3f3;
  264. border-top: 3px solid #3498db;
  265. border-radius: 50%;
  266. width: 10px;
  267. height: 10px;
  268. animation: spin 0.5s linear infinite;
  269. margin-left: 5px;
  270. }
  271.  
  272. @keyframes spin {
  273. 0% {
  274. transform: rotate(0deg);
  275. }
  276. 100% {
  277. transform: rotate(360deg);
  278. }
  279. }
  280. `);
  281.  
  282. createConfigMenu();
  283. setStatus("idle");
  284. document.addEventListener("keydown", handleKeyPress);
  285. }
  286.  
  287. initializeScript();
  288. })();