WIP really remedial attempts at getting user-savable scripts happening

computer crashing sigh
This commit is contained in:
tim h 2023-02-19 09:49:48 -06:00
parent 769182508f
commit 0e54435f4c
4 changed files with 114 additions and 41 deletions

View file

@ -371,9 +371,16 @@
<div class="menu-container" style="min-width: 200px"> <div class="menu-container" style="min-width: 200px">
<div id="script-select" class="script-select"> <div id="script-select" class="script-select">
<select id="script-selector" onchange="changeScript(event)"> <select id="script-selector" onchange="changeScript(event)">
<option id="no_selected_script" value="">Select a script...</option> <!-- <option id="no_selected_script" value="">Select a script...</option>
<option id="custom" value="custom">Other</option> <option id="custom" value="custom">Custom</option> -->
</select> </select>
<button
id="save-custom-script"
disabled="disabled"
title="Save custom script"
onclick="saveCustomScript()">
<image src="./res/icons/save.svg" width="60%"></image>
</button>
</div> </div>
<div id="script-name" class="script-name"> <div id="script-name" class="script-name">
<label for="script-name-input">Script Name:</label> <label for="script-name-input">Script Name:</label>
@ -451,7 +458,7 @@
<!-- Content --> <!-- Content -->
<script src="js/prompt.js?v=7a1c68c" type="text/javascript"></script> <script src="js/prompt.js?v=7a1c68c" type="text/javascript"></script>
<script src="js/index.js?v=c9b95ae" type="text/javascript"></script> <script src="js/index.js?v=ef5a869" type="text/javascript"></script>
<script <script
src="js/ui/floating/history.js?v=4f29db4" src="js/ui/floating/history.js?v=4f29db4"
@ -465,7 +472,7 @@
src="js/ui/tool/generic.js?v=3e678e0" src="js/ui/tool/generic.js?v=3e678e0"
type="text/javascript"></script> type="text/javascript"></script>
<script src="js/ui/tool/dream.js?v=00fdfe4" type="text/javascript"></script> <script src="js/ui/tool/dream.js?v=5330f89" type="text/javascript"></script>
<script <script
src="js/ui/tool/maskbrush.js?v=e9bd0eb" src="js/ui/tool/maskbrush.js?v=e9bd0eb"
type="text/javascript"></script> type="text/javascript"></script>

View file

@ -145,6 +145,7 @@ var url = "/sdapi/v1/";
const basePixelCount = 64; //64 px - ALWAYS 64 PX const basePixelCount = 64; //64 px - ALWAYS 64 PX
var focused = true; var focused = true;
let defaultScripts = {}; let defaultScripts = {};
let userScripts = {};
function startup() { function startup() {
testHostConfiguration(); testHostConfiguration();
@ -171,7 +172,7 @@ function startup() {
changeRestoreFaces(); changeRestoreFaces();
changeSyncCursorSize(); changeSyncCursorSize();
checkFocus(); checkFocus();
loadDefaultScripts(); refreshScripts();
} }
function setFixedHost(h, changePromptMessage) { function setFixedHost(h, changePromptMessage) {
@ -1400,6 +1401,28 @@ function checkFocus() {
} }
} }
function refreshScripts() {
selector = document.getElementById("script-selector");
selector.innerHTML = "";
createBaseScriptOptions();
loadDefaultScripts();
loadUserScripts();
}
function createBaseScriptOptions() {
selector = document.getElementById("script-selector");
var noScript = document.createElement("option");
noScript.id = "no_selected_script";
noScript.value = "";
noScript.innerHTML = "Select a script...";
selector.appendChild(noScript);
var customScript = document.createElement("option");
customScript.id = "custom";
customScript.value = "custom";
customScript.innerHTML = "Custom";
selector.appendChild(customScript);
}
async function loadDefaultScripts() { async function loadDefaultScripts() {
selector = document.getElementById("script-selector"); selector = document.getElementById("script-selector");
const response = await fetch("./defaultscripts.json"); const response = await fetch("./defaultscripts.json");
@ -1413,17 +1436,33 @@ async function loadDefaultScripts() {
//return json; //return json;
} }
function changeScript(evt) { async function loadUserScripts() {
selector = document.getElementById("script-selector");
const response = await fetch("./userdefinedscripts.json");
const json = await response.json();
for (const key in json.userScripts) {
var opt = document.createElement("option");
opt.value = opt.innerHTML = key;
selector.appendChild(opt);
}
userScripts = json;
}
function changeScript(event) {
let enable = () => { let enable = () => {
scriptName.disabled = false; scriptName.disabled = false;
saveScriptButton.disabled = false;
}; };
let disable = () => { let disable = () => {
scriptName.disabled = true; scriptName.disabled = true;
saveScriptButton.disabled = true;
}; };
let selected = evt.target.value; let selected = event.target.value;
let scriptName = document.getElementById("script-name-input"); let scriptName = document.getElementById("script-name-input");
let scriptArgs = document.getElementById("script-args-input"); let scriptArgs = document.getElementById("script-args-input");
let saveScriptButton = document.getElementById("save-custom-script");
scriptName.value = selected; scriptName.value = selected;
scriptArgs.title = "";
disable(); disable();
switch (selected) { switch (selected) {
case "custom": { case "custom": {
@ -1436,21 +1475,38 @@ function changeScript(evt) {
case "": { case "": {
// specifically no selected script // specifically no selected script
scriptArgs.value = ""; scriptArgs.value = "";
scriptArgs.title = "";
break; break;
} }
default: { default: {
// check defaultScripts objects for selected script
scriptName.value = selected; scriptName.value = selected;
// check default scripts for selected script
if (selected in defaultScripts.defaultScripts) {
scriptArgs.value = defaultScripts.defaultScripts[selected].scriptValues; scriptArgs.value = defaultScripts.defaultScripts[selected].scriptValues;
scriptArgs.title = defaultScripts.defaultScripts[selected].titleText; scriptArgs.title = defaultScripts.defaultScripts[selected].titleText;
}
// if not found, check user scripts // if not found, check user scripts
// TODO yknow what check userscripts first; if customizations have been made load those instead of defaults, i'm too stupid to do that right now
else if (selected in userScripts.userScripts) {
scriptArgs.value = userScripts.userScripts[selected].scriptValues;
enable();
}
// if not found, wtf // if not found, wtf
} }
} }
} }
async function saveCustomScript() {
let selector = document.getElementById("script-name-input");
let selected = selector.value;
let args = document.getElementById("script-args-input").value;
if (selected.trim() != "") {
if (selected in userScripts.userScripts) {
userScripts.userScripts[selected].scriptValues = args;
} else {
}
}
}
function togglePix2PixImgCfg(value) { function togglePix2PixImgCfg(value) {
// super hacky // super hacky
// actually doesn't work at all yet so i'm leaving it here to taunt and remind me of my failures // actually doesn't work at all yet so i'm leaving it here to taunt and remind me of my failures

View file

@ -1449,6 +1449,8 @@ const dreamTool = () =>
state.overMaskPx = 20; state.overMaskPx = 20;
state.preserveMasks = false; state.preserveMasks = false;
state.eagerGenerateCount = 0; state.eagerGenerateCount = 0;
state.carve_blur = 0;
state.carve_threshold = 10;
state.carve_blur = 0; state.carve_blur = 0;
state.carve_threshold = 10; state.carve_threshold = 10;
@ -1700,7 +1702,7 @@ const dreamTool = () =>
} }
).checkbox; ).checkbox;
// Keep Masked Content Checkbox // Keep Unmasked Content Checkbox
state.ctxmenu.keepUnmaskedLabel = _toolbar_input.checkbox( state.ctxmenu.keepUnmaskedLabel = _toolbar_input.checkbox(
state, state,
"openoutpaint/dream-keepunmasked", "openoutpaint/dream-keepunmasked",
@ -1724,7 +1726,7 @@ const dreamTool = () =>
} }
).checkbox; ).checkbox;
// Keep Masked Content Blur Slider // Keep Unmasked Content Blur Slider
state.ctxmenu.keepUnmaskedBlurSlider = _toolbar_input.slider( state.ctxmenu.keepUnmaskedBlurSlider = _toolbar_input.slider(
state, state,
"openoutpaint/dream-keepunmaskedblur", "openoutpaint/dream-keepunmaskedblur",
@ -1780,11 +1782,13 @@ const dreamTool = () =>
"icon-slice", "icon-slice",
() => { () => {
if (state.removeBackground) { if (state.removeBackground) {
state.ctxmenu.carveBlurLabel.classList.remove("invisible"); state.ctxmenu.carveBlurSlider.classList.remove("invisible");
state.ctxmenu.carveThresholdLabel.classList.remove("invisible"); state.ctxmenu.carveThresholdSlider.classList.remove(
"invisible"
);
} else { } else {
state.ctxmenu.carveBlurLabel.classList.add("invisible"); state.ctxmenu.carveBlurSlider.classList.add("invisible");
state.ctxmenu.carveThresholdLabel.classList.add("invisible"); state.ctxmenu.carveThresholdSlider.classList.add("invisible");
} }
} }
).checkbox; ).checkbox;
@ -1817,7 +1821,7 @@ const dreamTool = () =>
} }
).slider; ).slider;
// bg carve blur // bg carve blur
state.ctxmenu.carveBlurLabel = _toolbar_input.slider( state.ctxmenu.carveBlurSlider = _toolbar_input.slider(
state, state,
"openoutpaint/dream-carveblur", "openoutpaint/dream-carveblur",
"carve_blur", "carve_blur",
@ -1829,9 +1833,9 @@ const dreamTool = () =>
textStep: 1, textStep: 1,
} }
).slider; ).slider;
state.ctxmenu.carveBlurLabel.classList.add("invisible"); state.ctxmenu.carveBlurSlider.classList.add("invisible");
// bg carve threshold // bg carve threshold
state.ctxmenu.carveThresholdLabel = _toolbar_input.slider( state.ctxmenu.carveThresholdSlider = _toolbar_input.slider(
state, state,
"openoutpaint/dream-carvethreshold", "openoutpaint/dream-carvethreshold",
"carve_threshold", "carve_threshold",
@ -1843,7 +1847,7 @@ const dreamTool = () =>
textStep: 1, textStep: 1,
} }
).slider; ).slider;
state.ctxmenu.carveThresholdLabel.classList.add("invisible"); state.ctxmenu.carveThresholdSlider.classList.add("invisible");
} }
menu.appendChild(state.ctxmenu.cursorSizeSlider); menu.appendChild(state.ctxmenu.cursorSizeSlider);
@ -1854,12 +1858,12 @@ const dreamTool = () =>
array.appendChild(state.ctxmenu.invertMaskLabel); array.appendChild(state.ctxmenu.invertMaskLabel);
array.appendChild(state.ctxmenu.preserveMasksLabel); array.appendChild(state.ctxmenu.preserveMasksLabel);
//menu.appendChild(document.createElement("br")); //menu.appendChild(document.createElement("br"));
array.appendChild(state.ctxmenu.removeBackgroundLabel);
array.appendChild(state.ctxmenu.keepUnmaskedLabel); array.appendChild(state.ctxmenu.keepUnmaskedLabel);
array.appendChild(state.ctxmenu.removeBackgroundLabel);
menu.appendChild(array); menu.appendChild(array);
menu.appendChild(state.ctxmenu.carveBlurLabel);
menu.appendChild(state.ctxmenu.carveThresholdLabel);
menu.appendChild(state.ctxmenu.keepUnmaskedBlurSlider); menu.appendChild(state.ctxmenu.keepUnmaskedBlurSlider);
menu.appendChild(state.ctxmenu.carveBlurSlider);
menu.appendChild(state.ctxmenu.carveThresholdSlider);
// menu.appendChild(state.ctxmenu.keepUnmaskedBlurSliderLinebreak); // menu.appendChild(state.ctxmenu.keepUnmaskedBlurSliderLinebreak);
// menu.appendChild(state.ctxmenu.preserveMasksLabel); // menu.appendChild(state.ctxmenu.preserveMasksLabel);
// menu.appendChild(document.createElement("br")); // menu.appendChild(document.createElement("br"));
@ -1951,6 +1955,8 @@ const img2imgTool = () =>
state.fullResolution = false; state.fullResolution = false;
state.preserveMasks = false; state.preserveMasks = false;
state.eagerGenerateCount = 0; state.eagerGenerateCount = 0;
state.carve_blur = 0;
state.carve_threshold = 10;
state.denoisingStrength = 0.7; state.denoisingStrength = 0.7;
@ -2306,7 +2312,7 @@ const img2imgTool = () =>
} }
).checkbox; ).checkbox;
// Keep Masked Content Checkbox // Keep Unmasked Content Checkbox
state.ctxmenu.keepUnmaskedLabel = _toolbar_input.checkbox( state.ctxmenu.keepUnmaskedLabel = _toolbar_input.checkbox(
state, state,
"openoutpaint/img2img-keepunmasked", "openoutpaint/img2img-keepunmasked",
@ -2330,7 +2336,7 @@ const img2imgTool = () =>
} }
).checkbox; ).checkbox;
// Keep Masked Content Blur Slider // Keep Unmasked Content Blur Slider
state.ctxmenu.keepUnmaskedBlurSlider = _toolbar_input.slider( state.ctxmenu.keepUnmaskedBlurSlider = _toolbar_input.slider(
state, state,
"openoutpaint/img2img-unmaskedblur", "openoutpaint/img2img-unmaskedblur",
@ -2400,11 +2406,13 @@ const img2imgTool = () =>
"icon-slice", "icon-slice",
() => { () => {
if (state.removeBackground) { if (state.removeBackground) {
state.ctxmenu.carveBlurLabel.classList.remove("invisible"); state.ctxmenu.carveBlurSlider.classList.remove("invisible");
state.ctxmenu.carveThresholdLabel.classList.remove("invisible"); state.ctxmenu.carveThresholdSlider.classList.remove(
"invisible"
);
} else { } else {
state.ctxmenu.carveBlurLabel.classList.add("invisible"); state.ctxmenu.carveBlurSlider.classList.add("invisible");
state.ctxmenu.carveThresholdLabel.classList.add("invisible"); state.ctxmenu.carveThresholdSlider.classList.add("invisible");
} }
} }
).checkbox; ).checkbox;
@ -2473,7 +2481,7 @@ const img2imgTool = () =>
); );
// bg carve blur // bg carve blur
state.ctxmenu.carveBlurLabel = _toolbar_input.slider( state.ctxmenu.carveBlurSlider = _toolbar_input.slider(
state, state,
"openoutpaint/img2img-carveblur", "openoutpaint/img2img-carveblur",
"carve_blur", "carve_blur",
@ -2485,10 +2493,10 @@ const img2imgTool = () =>
textStep: 1, textStep: 1,
} }
).slider; ).slider;
state.ctxmenu.carveBlurLabel.classList.add("invisible"); state.ctxmenu.carveBlurSlider.classList.add("invisible");
// bg carve threshold // bg carve threshold
state.ctxmenu.carveThresholdLabel = _toolbar_input.slider( state.ctxmenu.carveThresholdSlider = _toolbar_input.slider(
state, state,
"openoutpaint/img2img-carvethreshold", "openoutpaint/img2img-carvethreshold",
"carve_threshold", "carve_threshold",
@ -2500,7 +2508,7 @@ const img2imgTool = () =>
textStep: 1, textStep: 1,
} }
).slider; ).slider;
state.ctxmenu.carveThresholdLabel.classList.add("invisible"); state.ctxmenu.carveThresholdSlider.classList.add("invisible");
} }
menu.appendChild(state.ctxmenu.cursorSizeSlider); menu.appendChild(state.ctxmenu.cursorSizeSlider);
@ -2509,12 +2517,12 @@ const img2imgTool = () =>
array.appendChild(state.ctxmenu.snapToGridLabel); array.appendChild(state.ctxmenu.snapToGridLabel);
array.appendChild(state.ctxmenu.invertMaskLabel); array.appendChild(state.ctxmenu.invertMaskLabel);
array.appendChild(state.ctxmenu.preserveMasksLabel); array.appendChild(state.ctxmenu.preserveMasksLabel);
array.appendChild(state.ctxmenu.removeBackgroundLabel);
array.appendChild(state.ctxmenu.keepUnmaskedLabel); array.appendChild(state.ctxmenu.keepUnmaskedLabel);
array.appendChild(state.ctxmenu.removeBackgroundLabel);
menu.appendChild(array); menu.appendChild(array);
menu.appendChild(state.ctxmenu.carveBlurLabel);
menu.appendChild(state.ctxmenu.carveThresholdLabel);
menu.appendChild(state.ctxmenu.keepUnmaskedBlurSlider); menu.appendChild(state.ctxmenu.keepUnmaskedBlurSlider);
menu.appendChild(state.ctxmenu.carveBlurSlider);
menu.appendChild(state.ctxmenu.carveThresholdSlider);
// menu.appendChild(state.ctxmenu.keepUnmaskedBlurSliderLinebreak); // menu.appendChild(state.ctxmenu.keepUnmaskedBlurSliderLinebreak);
menu.appendChild(state.ctxmenu.inpaintTypeSelect); menu.appendChild(state.ctxmenu.inpaintTypeSelect);
menu.appendChild(state.ctxmenu.denoisingStrengthSlider); menu.appendChild(state.ctxmenu.denoisingStrengthSlider);

View file

@ -1,6 +1,8 @@
{ {
"userScript1": { "userScripts": {
"testScript1": {
"title": "template", "title": "template",
"scriptValues": "[1, 0.999, true, \"4-10 [3]\", \"test text\"]" "scriptValues": "[1, 0.999, true, \"4-10 [3]\", \"test text\"]"
} }
} }
}