File size: 4,626 Bytes
0b56a4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// ==UserScript==
// @name         AUTOMATIC1111 - change output folder
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Quick change ouput folder
// @author       You
// @match        http://127.0.0.1:7860/
// @match        http://localhost:7860/
// @match        https*://*.loca.lt/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=0.1
// @grant        none
// @require      https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js
// @run-at document-end
// ==/UserScript==

(function() {
    'use strict';

    setTimeout(() => {
        const outputPathTxt2img1 = 'your/path/to/txt2img/output/folder';                         //here you put your main txt2img output folder path
        const outputPathTxt2img2 = 'your/path/to/alternative/txt2img/output/folder';			 //here you put your alternative txt2img output folder path

        const outputPathImg2img1 = 'your/path/to/img2img/output/folder';						 //here you put your main img2img output folder path
        const outputPathImg2img2 = 'your/path/to/alternative/img2img/output/folder';			 //here you put your alternative img2img output folder path

        const container = querySelectorAllShadows('.container')[0];
        const txt2imgInput = querySelectorAllShadows('#setting_outdir_txt2img_samples textarea')[0];
        const img2imgInput = querySelectorAllShadows('#setting_outdir_img2img_samples textarea')[0];
        const saveBtn = querySelectorAllShadows('#tab_settings .gr-button-primary')[0];

        const checked = txt2imgInput.value === outputPathTxt2img2 ? 'checked' : '';

        console.log(container)
        console.log(txt2imgInput)
        console.log(saveBtn)
        $(container).prepend( `
          <label class="toggle incognito">
  <input class="toggle-checkbox" type="checkbox" ${checked}>
  <div class="toggle-switch"></div>
  <span class="toggle-label">Alternative directory</span>
</label>
        ` );

        const incogintoEl = container.querySelector('.incognito .toggle-checkbox');
        incogintoEl.addEventListener('change', (e) => {
          const targetEl = e.currentTarget;
          if (targetEl.checked) {
              console.log("Checkbox is checked..");
              txt2imgInput.value = outputPathTxt2img2;
              img2imgInput.value = outputPathImg2img2;
          } else {
              console.log("Checkbox is not checked..");
              txt2imgInput.value = outputPathTxt2img1;
              img2imgInput.value = outputPathImg2img1;
          }
            console.log(txt2imgInput)
          txt2imgInput.dispatchEvent(new Event("input", { bubbles: true }));
          img2imgInput.dispatchEvent(new Event("input", { bubbles: true }));
        })
        console.log(incogintoEl)
    }, 1000)


    addStyle(`
      body {
         color:red;
      }
      .toggle {
  cursor: pointer;
  display: inline-block;
  margin-bottom: 2em;
}

.toggle-switch {
  display: inline-block;
  background: #ccc;
  border-radius: 16px;
  width: 58px;
  height: 32px;
  position: relative;
  vertical-align: middle;
  transition: background 0.25s;
}
.toggle-switch:before, .toggle-switch:after {
  content: "";
}
.toggle-switch:before {
  display: block;
  background: linear-gradient(to bottom, #fff 0%, #eee 100%);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
  width: 24px;
  height: 24px;
  position: absolute;
  top: 4px;
  left: 4px;
  transition: left 0.25s;
}
.toggle:hover .toggle-switch:before {
  background: linear-gradient(to bottom, #fff 0%, #fff 100%);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}
.toggle-checkbox:checked + .toggle-switch {
  background: #56c080;
}
.toggle-checkbox:checked + .toggle-switch:before {
  left: 30px;
}

.toggle-checkbox {
  position: absolute;
  visibility: hidden;
}

.toggle-label {
  margin-left: 5px;
  position: relative;
  top: 2px;
}
    `)

    function addStyle(styleText) {
        let s = document.createElement('style');
        s.appendChild(document.createTextNode(styleText));
        querySelectorAllShadows('.gradio-container')[0].appendChild(s);
    }

    function querySelectorAllShadows(selector, el = document.body) {
        // recurse on childShadows
        const childShadows = Array.from(el.querySelectorAll('*')).
        map(el => el.shadowRoot).filter(Boolean);

        const childResults = childShadows.map(child => querySelectorAllShadows(selector, child));

        // fuse all results into singular, flat array
        const result = Array.from(el.querySelectorAll(selector));
        return result.concat(childResults).flat();
    }

})();