Advertisement
Guest User

sd-webui-img2img-modes

a guest
Jul 27th, 2023
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        sd-webui-img2img-modes
  3. // @namespace   Violentmonkey Scripts
  4. // @match       http://127.0.0.1:1111/
  5. // @grant       none
  6. // @version     1.0
  7. // @author      NAI Thread Anon
  8. // @description 28.07.2023, 00:00:00
  9. // ==/UserScript==
  10.  
  11. let ModeButtons       = document.createElement ('div');
  12. let UpscaleModeButton = document.createElement("button");
  13. UpscaleModeButton.innerHTML = "Upscale";
  14. UpscaleModeButton.setAttribute('id', 'UpscaleModeButton');
  15. UpscaleModeButton.style.margin = "3px";
  16.  
  17. let InpaintModeButton = document.createElement("button");
  18. InpaintModeButton.innerHTML = "Inpaint";
  19. InpaintModeButton.setAttribute('id', 'InpaintModeButton');
  20. InpaintModeButton.style.margin = "3px";
  21.  
  22. ModeButtons.appendChild(UpscaleModeButton);
  23. ModeButtons.appendChild(InpaintModeButton);
  24.  
  25. ModeButtons.setAttribute('id', 'myModesContainer');
  26. document.body.appendChild(ModeButtons);
  27.  
  28. ModeButtons.style.position = "fixed";
  29. ModeButtons.style.top = "0";
  30. ModeButtons.style.left = "0px";
  31. ModeButtons.style.margin = "3px";
  32. ModeButtons.style.zIndex = "9001";
  33.  
  34. document.getElementById("UpscaleModeButton").addEventListener (
  35.     "click", UpscaleModeButtonClickAction, false
  36. );
  37.  
  38. document.getElementById("InpaintModeButton").addEventListener (
  39.     "click", InpaintModeButtonClickAction, false
  40. );
  41.  
  42. function UpscaleModeButtonClickAction (zEvent) {
  43.  
  44.   let img2img_batch_count =         document.querySelector("#img2img_batch_count [type='range']");
  45.   let img2img_dimensions =          document.querySelector("#img2img_dimensions_row").children[0].children[1];
  46.   let img2img_denoising_strength =  document.querySelector("#img2img_denoising_strength [type='range']");
  47.   let MD_i2i_enabled =              document.querySelector("#MD-i2i-enabled [type='checkbox']");
  48.  
  49.   img2img_batch_count.value = 1;
  50.   img2img_dimensions.click();
  51.   img2img_denoising_strength.value = 0.35;
  52.   MD_i2i_enabled.checked = true;
  53.  
  54.   img2img_batch_count.dispatchEvent(new Event("input", { bubbles: true }));
  55.   img2img_denoising_strength.dispatchEvent(new Event("input", { bubbles: true }));
  56.   MD_i2i_enabled.dispatchEvent(new Event("input", { bubbles: true }));
  57.  
  58. }
  59.  
  60. function InpaintModeButtonClickAction (zEvent) {
  61.  
  62.   let img2img_batch_count =         document.querySelector("#img2img_batch_count [type='range']");
  63.   let img2img_width =               document.querySelector("#img2img_width [type='range']");
  64.   let img2img_height =              document.querySelector("#img2img_height [type='range']");
  65.   let img2img_denoising_strength =  document.querySelector("#img2img_denoising_strength [type='range']");
  66.   let MD_i2i_enabled =              document.querySelector("#MD-i2i-enabled [type='checkbox']");
  67.  
  68.   img2img_batch_count.value = 100;
  69.   img2img_width.value = 600;
  70.   img2img_height.value = 600;
  71.   img2img_denoising_strength.value = 0.48;
  72.   MD_i2i_enabled.checked = false;
  73.  
  74.   img2img_batch_count.dispatchEvent(new Event("input", { bubbles: true }));
  75.   img2img_width.dispatchEvent(new Event("input", { bubbles: true }));
  76.   img2img_height.dispatchEvent(new Event("input", { bubbles: true }));
  77.   img2img_denoising_strength.dispatchEvent(new Event("input", { bubbles: true }));
  78.   MD_i2i_enabled.dispatchEvent(new Event("input", { bubbles: true }));
  79.  
  80. }
  81.  
  82.  
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement