goroman

Untitled

Dec 1st, 2023
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.37 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Designer AI Slop
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Auto Slop
  6. // @author (You)
  7. // @match https://designer.microsoft.com/image-creator*
  8. // @run-at document-end
  9. // @grant GM_download
  10. // @grant GM_addStyle
  11. // ==/UserScript==
  12.  
  13. // --------------------------------
  14.  
  15. // if yellow warning = will try again after 5s
  16. // if red warning = will try again after 45s
  17. // ON/OFF = enable/disable autoclick
  18. // turn it off first if you are testing words/prompts, so it won't autoclick if you get a bad word warning
  19. // tested with Tampermonkey
  20.  
  21. var audio = new Audio('https://website.com/ding.mp3'); //put a url to a mp3 that you want to play when an image is generated. or leave empty ''
  22. audio.volume = 1.0; // 0.0 to 1.0
  23.  
  24. // --------------------------------
  25.  
  26. function playAudio() { //may not work with browsers with anti-autoplay rules
  27. audio.play();
  28. };
  29.  
  30. let timeoutId1 = null
  31. let timeoutId2 = null
  32.  
  33. function createToggleButton() {
  34. let textarea = document.querySelector('.fui-Button.ri7kuyr');
  35. if (textarea) {
  36. let toggle = document.createElement('div');
  37. toggle.className = 'toggleButton';
  38. let isOn = localStorage.getItem('toggleState') === 'ON' ? true : false;
  39. toggle.innerText = isOn ? 'ON' : 'OFF';
  40. toggle.style.backgroundColor = isOn ? 'green' : 'red';
  41. toggle.addEventListener('click', function() {
  42. isOn = !isOn;
  43. toggle.innerText = isOn ? 'ON' : 'OFF';
  44. toggle.style.backgroundColor = isOn ? 'green' : 'red';
  45. localStorage.setItem('toggleState', isOn ? 'ON' : 'OFF');
  46.  
  47. if (!isOn) {
  48. clearTimeout(timeoutId1);
  49. timeoutId1 = null
  50. clearTimeout(timeoutId2);
  51. timeoutId2 = null
  52. document.title = "Image Creator";
  53. }
  54. });
  55. toggle.style.display = 'block';
  56. toggle.style.marginLeft = 'auto';
  57. toggle.style.marginRight = 'auto';
  58. textarea.parentNode.insertBefore(toggle, textarea.nextSibling);
  59. return true;
  60. }
  61. return false;
  62. }
  63.  
  64. let intervalId = setInterval(function() {
  65. if (createToggleButton()) {
  66. clearInterval(intervalId);
  67. }
  68. }, 2000);
  69.  
  70. GM_addStyle(`
  71. .toggleButton {
  72. border: none;
  73. color: white;
  74. padding: 02px 20px;
  75. text-align: center;
  76. text-decoration: none;
  77. display: inline-block;
  78. font-size: 16px;
  79. margin: 4px 2px;
  80. cursor: pointer;
  81. }
  82. `);
  83.  
  84. function addDownloadButtons() {
  85. let grid = document.querySelector('[data-testid^="media-asset-button"]');
  86. if (!grid) { return }
  87. let buttons = document.querySelectorAll('[data-testid^="media-asset-button"]');
  88. if (buttons[0].nextSibling && buttons[0].nextSibling.tagName === 'BUTTON') { return true; }
  89. if (grid) { grid.click(); }
  90. let divs = document.querySelectorAll('.fui-FluentProvider.fui-FluentProvider1.___1bsm0mz');
  91. if (divs.length >= 2) {
  92. divs[1].style.display = 'none';
  93. }
  94. let images;
  95. if (buttons.length === 1) {
  96. images = document.querySelectorAll('.___1h0r9zi.f22iagw');
  97. } else {
  98. images = document.querySelectorAll('[data-testid^="media-asset-modal-item-"]');
  99. }
  100. let firstUrl = images[0].firstChild.src;
  101. let storedUrl = localStorage.getItem('firstUrl');
  102. if (storedUrl !== firstUrl) {
  103. localStorage.setItem('firstUrl', firstUrl);
  104. playAudio();
  105. document.title = "Done!";
  106. }
  107. let element = document.querySelector('[data-testid="media-asset-modal-close-btn"]');
  108. if (element) { element.click(); }
  109. for (let i = 0; i < buttons.length; i++) {
  110. if (images[i]) {
  111. let img = images[i].firstChild;
  112. let dataUrl = img.src;
  113. let newButton = document.createElement('button');
  114. newButton.innerText = 'Download Image ' + (i + 1);
  115. newButton.style.display = 'block';
  116. newButton.style.margin = 'auto';
  117. newButton.style.marginTop = '10px';
  118. newButton.addEventListener('click', function() {
  119. let date = new Date();
  120. let year = date.getFullYear();
  121. let month = (date.getMonth() + 1).toString().padStart(2, '0');
  122. let day = date.getDate().toString().padStart(2, '0');
  123. let hours = date.getHours().toString().padStart(2, '0');
  124. let minutes = date.getMinutes().toString().padStart(2, '0');
  125. let seconds = date.getSeconds().toString().padStart(2, '0');
  126. let dateTime = year + '-' + month + '-' + day + ' ' + hours + '_' + minutes + '_' + seconds;
  127. let downloadOptions = {
  128. url: dataUrl,
  129. name: 'Designer - ' + dateTime + '.jpg'
  130. };
  131. GM_download(downloadOptions);
  132. });
  133. buttons[i].parentNode.insertBefore(newButton, buttons[i].nextSibling);
  134. }
  135. }
  136. return false;
  137. }
  138.  
  139. function CheckAndClickButton() {
  140. let toggleState = localStorage.getItem('toggleState');
  141. if (toggleState === 'OFF') {
  142. return;
  143. }
  144. let warning1 = document.querySelector('.___ogrvaz0.f5ogflp.f1hqa2wf.f1f09k3d'); //yellow warning
  145. let warning2 = document.querySelector('.___1fkmo9w.f5ogflp.f1hqa2wf.f1f09k3d'); //red warning
  146. let button = document.querySelector('.fui-Button.ri7kuyr.___vnqwgp0.ffp7eso.f1p3nwhy');
  147. if (button) {
  148. if (warning1 && !timeoutId1) {
  149. document.title = "Working...";
  150. timeoutId1 = setTimeout(function() {
  151. button.click();
  152. timeoutId1 = null;
  153. }, 5000); // Wait for 5 seconds to click
  154. }
  155. if (warning2 && !timeoutId2) {
  156. document.title = "Working...";
  157. timeoutId2 = setTimeout(function() {
  158. button.click();
  159. timeoutId2 = null;
  160. }, 45000); // Wait for 45 seconds to click
  161. }
  162. }
  163. }
  164.  
  165. setInterval(function() {
  166. let button = document.querySelector('.fui-Button.ri7kuyr.___vnqwgp0.ffp7eso.f1p3nwhy');
  167. if (button) {
  168. addDownloadButtons();
  169. if (!button.disabled) {
  170. CheckAndClickButton();
  171. }
  172. }
  173. }, 2000); // Check page every 2 seconds
Advertisement
Add Comment
Please, Sign In to add comment