update loopback script to include interrogator "telephone" option, "remove" user script saving because i don't think JS can even silently write to one of its own files.... prove me wrong? please?

This commit is contained in:
tim h 2023-02-25 07:30:52 -06:00
parent 0e54435f4c
commit eb8946266f
4 changed files with 80 additions and 52 deletions

View file

@ -1,8 +1,8 @@
{
"defaultScripts": {
"Loopback": {
"titleText": "IMG2IMG ONLY\n\nParams:\nloops (int) //def: 8\ndenoising_strength_change_factor (decimal, 0.90-1.10) //def: 0.99",
"scriptValues": "[8, 0.99]"
"titleText": "IMG2IMG ONLY\n\nParams:\nloops (int) //def: 8\ndenoising_strength_change_factor (decimal, 0.90-1.10) //def: 0.99\nappend_interrogation (enum, str: [\"None\",\"CLIP\",\"DeepBooru\"]) //def: None",
"scriptValues": "[8, 0.99, \"None\"]"
},
"Prompt matrix": {
"titleText": "Params:\nput_at_start (bool): expect pipe (|) delimited options at start of prompt //def: false\ndifferent_seeds (bool): use different seeds for each picture //def: false\nprompt_type (enum, str: [\"positive\",\"negative\"]) //def: \"positive\"\nvariations_delimiter (enum, str [\"comma\", \"space\"] //def: \"comma\"\nmargin_size (int): px margin value //def: 2",

View file

@ -374,24 +374,29 @@
<!-- <option id="no_selected_script" value="">Select a script...</option>
<option id="custom" value="custom">Custom</option> -->
</select>
<button
<!-- <button
id="save-custom-script"
disabled="disabled"
title="Save custom script"
onclick="saveCustomScript()">
<image src="./res/icons/save.svg" width="60%"></image>
</button>
</button> -->
</div>
<div id="script-name" class="script-name">
<label for="script-name-input">Script Name:</label>
<label for="scrip-name-input">Script Name:</label>
<br />
<input id="script-name-input" disabled="disabled" />
<input
id="script-name-input"
disabled="disabled"
onfocusout="storeUserscriptVal(event, 'name')" />
<br />
</div>
<div id="script-args" class="script-args">
<label for="script-args-input">Script Args List:</label>
<br />
<textarea id="script-args-input"></textarea>
<textarea
id="script-args-input"
onfocusout="storeUserscriptVal(event, 'args')"></textarea>
<br />
</div>
</div>

View file

@ -1406,7 +1406,7 @@ function refreshScripts() {
selector.innerHTML = "";
createBaseScriptOptions();
loadDefaultScripts();
loadUserScripts();
// loadUserScripts();
}
function createBaseScriptOptions() {
@ -1433,41 +1433,48 @@ async function loadDefaultScripts() {
selector.appendChild(opt);
}
defaultScripts = json;
//return json;
}
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;
}
// 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 = () => {
scriptName.disabled = false;
saveScriptButton.disabled = false;
// saveScriptButton.disabled = false;
};
let disable = () => {
scriptName.disabled = true;
saveScriptButton.disabled = true;
// saveScriptButton.disabled = true;
};
let selected = event.target.value;
let scriptName = document.getElementById("script-name-input");
let scriptArgs = document.getElementById("script-args-input");
let saveScriptButton = document.getElementById("save-custom-script");
// let saveScriptButton = document.getElementById("save-custom-script");
scriptName.value = selected;
scriptArgs.title = "";
disable();
switch (selected) {
case "custom": {
scriptName.value = "";
scriptArgs.value = "[]";
let _script_name_input =
localStorage.getItem("openoutpaint/script_name_input") === null
? ""
: localStorage.getItem("openoutpaint/script_name_input");
let _script_args_input =
localStorage.getItem("openoutpaint/script_args_input") === null
? "[]"
: localStorage.getItem("openoutpaint/script_args_input");
scriptName.value = _script_name_input;
scriptArgs.value = _script_args_input;
scriptArgs.title = "";
enable();
break;
@ -1484,44 +1491,58 @@ function changeScript(event) {
scriptArgs.value = defaultScripts.defaultScripts[selected].scriptValues;
scriptArgs.title = defaultScripts.defaultScripts[selected].titleText;
}
// FURTHER TODO see if this is even plausible as i don't think JS can arbitrarily save data to files without downloading
// 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();
}
// else if (selected in userScripts.userScripts) {
// scriptArgs.value = userScripts.userScripts[selected].scriptValues;
// enable();
// }
// 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 {
}
}
}
// 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) {
// super hacky
// actually doesn't work at all yet so i'm leaving it here to taunt and remind me of my failures
// try {
// if (value.toLowerCase().includes("pix2pix")) {
// document
// .querySelector(".instruct-pix2pix-img-cfg")
// .classList.remove("invisible");
// } else {
// document
// .querySelector(".instruct-pix2pix-img-cfg")
// .classList.add("invisible");
// }
// } catch (e) {
// // highly likely not currently using img2img tool, do nothing
// }
}
try {
if (value.toLowerCase().includes("pix2pix")) {
document
.querySelector(".instruct-pix2pix-img-cfg")
.classList.remove("invisible");
} else {
document
.querySelector(".instruct-pix2pix-img-cfg")
.classList.add("invisible");
}
} catch (e) {
// highly likely not currently using img2img tool, do nothing
function storeUserscriptVal(evt, type) {
let currentScript = document.getElementById("script-selector").value;
if (currentScript === "custom") {
console.log(type);
console.log(evt);
let val = (currentScript = document.getElementById(
"script-" + type + "-input"
).value);
localStorage.setItem("openoutpaint/script_" + type + "_input", val);
}
}

View file

@ -519,6 +519,7 @@ const stampTool = () =>
const {checkbox: flipCheckbox, setValue: flipSetValue} =
_toolbar_input.checkbox(
state,
"openoutpaint/stamp-flip",
"flipStamp",
"Flip Stamp",
"icon-flip-vertical"
@ -530,6 +531,7 @@ const stampTool = () =>
const {checkbox: mirrorCheckbox, setValue: mirrorSetValue} =
_toolbar_input.checkbox(
state,
"openoutpaint/stamp-mirror",
"mirrorStamp",
"Mirror Stamp",
"icon-flip-horizontal"