AUTOMATIC1111_Change_output_folder / AUTOMATIC1111 - change output folder.user.js
Nix0n's picture
Upload AUTOMATIC1111 - change output folder.user.js
0b56a4e
// ==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();
}
})();