outpaint prefix to localstorage things
Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
parent
35ee716159
commit
232b52bc4b
4 changed files with 61 additions and 39 deletions
47
js/index.js
47
js/index.js
|
@ -171,7 +171,7 @@ function startup() {
|
|||
? hostEl.value.substring(0, hostEl.value.length - 1)
|
||||
: hostEl.value;
|
||||
hostEl.value = host;
|
||||
localStorage.setItem("host", host);
|
||||
localStorage.setItem("openoutpaint/host", host);
|
||||
checkConnection();
|
||||
};
|
||||
});
|
||||
|
@ -192,7 +192,7 @@ function testHostConfiguration() {
|
|||
* Check host configuration
|
||||
*/
|
||||
const hostEl = document.getElementById("host");
|
||||
hostEl.value = localStorage.getItem("host");
|
||||
hostEl.value = localStorage.getItem("openoutpaint/host");
|
||||
|
||||
const requestHost = (prompt, def = "http://127.0.0.1:7860") => {
|
||||
let value = window.prompt(prompt, def);
|
||||
|
@ -201,12 +201,12 @@ function testHostConfiguration() {
|
|||
value = value.endsWith("/") ? value.substring(0, value.length - 1) : value;
|
||||
host = value;
|
||||
hostEl.value = host;
|
||||
localStorage.setItem("host", host);
|
||||
localStorage.setItem("openoutpaint/host", host);
|
||||
|
||||
testHostConfiguration();
|
||||
};
|
||||
|
||||
const current = localStorage.getItem("host");
|
||||
const current = localStorage.getItem("openoutpaint/host");
|
||||
if (current) {
|
||||
if (!current.match(/^https?:\/\/[a-z0-9][a-z0-9.]+[a-z0-9](:[0-9]+)?$/i))
|
||||
requestHost(
|
||||
|
@ -587,19 +587,19 @@ function changeMaskBlur() {
|
|||
stableDiffusionData.mask_blur = parseInt(
|
||||
document.getElementById("maskBlur").value
|
||||
);
|
||||
localStorage.setItem("mask_blur", stableDiffusionData.mask_blur);
|
||||
localStorage.setItem("openoutpaint/mask_blur", stableDiffusionData.mask_blur);
|
||||
}
|
||||
|
||||
function changeSeed() {
|
||||
stableDiffusionData.seed = document.getElementById("seed").value;
|
||||
localStorage.setItem("seed", stableDiffusionData.seed);
|
||||
localStorage.setItem("openoutpaint/seed", stableDiffusionData.seed);
|
||||
}
|
||||
|
||||
function changeHiResFix() {
|
||||
stableDiffusionData.enable_hr = Boolean(
|
||||
document.getElementById("cbxHRFix").checked
|
||||
);
|
||||
localStorage.setItem("enable_hr", stableDiffusionData.enable_hr);
|
||||
localStorage.setItem("openoutpaint/enable_hr", stableDiffusionData.enable_hr);
|
||||
}
|
||||
|
||||
function changeSyncCursorSize() {
|
||||
|
@ -880,7 +880,10 @@ function changeStyles() {
|
|||
});
|
||||
}
|
||||
|
||||
localStorage.setItem("promptStyle", JSON.stringify(selectedString));
|
||||
localStorage.setItem(
|
||||
"openoutpaint/promptStyle",
|
||||
JSON.stringify(selectedString)
|
||||
);
|
||||
|
||||
// change the model
|
||||
if (selectedString.length > 0)
|
||||
|
@ -901,16 +904,16 @@ async function getSamplers() {
|
|||
}));
|
||||
|
||||
// Initial sampler
|
||||
if (localStorage.getItem("sampler") != null) {
|
||||
samplerAutoComplete.value = localStorage.getItem("sampler");
|
||||
if (localStorage.getItem("openoutpaint/sampler") != null) {
|
||||
samplerAutoComplete.value = localStorage.getItem("openoutpaint/sampler");
|
||||
} else {
|
||||
samplerAutoComplete.value = data[0].name;
|
||||
localStorage.setItem("sampler", samplerAutoComplete.value);
|
||||
localStorage.setItem("openoutpaint/sampler", samplerAutoComplete.value);
|
||||
}
|
||||
|
||||
samplerAutoComplete.onchange.on(({value}) => {
|
||||
stableDiffusionData.sampler_index = value;
|
||||
localStorage.setItem("sampler", value);
|
||||
localStorage.setItem("openoutpaint/sampler", value);
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn("[index] Failed to fetch samplers");
|
||||
|
@ -921,8 +924,8 @@ async function upscaleAndDownload() {
|
|||
// Future improvements: some upscalers take a while to upscale, so we should show a loading bar or something, also a slider for the upscale amount
|
||||
|
||||
// get cropped canvas, send it to upscaler, download result
|
||||
var upscale_factor = localStorage.getItem("upscale_x")
|
||||
? localStorage.getItem("upscale_x")
|
||||
var upscale_factor = localStorage.getItem("openoutpaint/upscale_x")
|
||||
? localStorage.getItem("openoutpaint/upscale_x")
|
||||
: 2;
|
||||
var upscaler = upscalerAutoComplete.value;
|
||||
var croppedCanvas = cropCanvas(
|
||||
|
@ -976,21 +979,23 @@ async function upscaleAndDownload() {
|
|||
function loadSettings() {
|
||||
// set default values if not set
|
||||
var _mask_blur =
|
||||
localStorage.getItem("mask_blur") == null
|
||||
localStorage.getItem("openoutpaint/mask_blur") == null
|
||||
? 0
|
||||
: localStorage.getItem("mask_blur");
|
||||
: localStorage.getItem("openoutpaint/mask_blur");
|
||||
var _seed =
|
||||
localStorage.getItem("seed") == null ? -1 : localStorage.getItem("seed");
|
||||
localStorage.getItem("openoutpaint/seed") == null
|
||||
? -1
|
||||
: localStorage.getItem("openoutpaint/seed");
|
||||
|
||||
let _enable_hr =
|
||||
localStorage.getItem("enable_hr") === null
|
||||
localStorage.getItem("openoutpaint/enable_hr") === null
|
||||
? false
|
||||
: localStorage.getItem("enable_hr") === "true";
|
||||
: localStorage.getItem("openoutpaint/enable_hr") === "true";
|
||||
|
||||
let _sync_cursor_size =
|
||||
localStorage.getItem("sync_cursor_size") === null
|
||||
localStorage.getItem("openoutpaint/sync_cursor_size") === null
|
||||
? true
|
||||
: localStorage.getItem("sync_cursor_size") === "true";
|
||||
: localStorage.getItem("openoutpaint/sync_cursor_size") === "true";
|
||||
|
||||
// set the values into the UI
|
||||
document.getElementById("maskBlur").value = Number(_mask_blur);
|
||||
|
|
|
@ -3,10 +3,14 @@ const imageCollection = layers.registerCollection(
|
|||
"image",
|
||||
{
|
||||
w: parseInt(
|
||||
(localStorage && localStorage.getItem("settings.canvas-width")) || 2048
|
||||
(localStorage &&
|
||||
localStorage.getItem("openoutpaint/settings.canvas-width")) ||
|
||||
2048
|
||||
),
|
||||
h: parseInt(
|
||||
(localStorage && localStorage.getItem("settings.canvas-height")) || 2048
|
||||
(localStorage &&
|
||||
localStorage.getItem("openoutpaint/settings.canvas-height")) ||
|
||||
2048
|
||||
),
|
||||
},
|
||||
{
|
||||
|
@ -57,7 +61,7 @@ const uiCtx = uiCanvas.getContext("2d", {desynchronized: true});
|
|||
* Here we setup canvas dynamic scaling
|
||||
*/
|
||||
(() => {
|
||||
let expandSize = localStorage.getItem("expand-size") || 1024;
|
||||
let expandSize = localStorage.getItem("openoutpaint/expand-size") || 1024;
|
||||
expandSize = parseInt(expandSize, 10);
|
||||
|
||||
const askSize = () => {
|
||||
|
@ -66,7 +70,7 @@ const uiCtx = uiCanvas.getContext("2d", {desynchronized: true});
|
|||
if (!by) return null;
|
||||
else {
|
||||
const len = parseInt(by, 10);
|
||||
localStorage.setItem("expand-size", len);
|
||||
localStorage.setItem("openoutpaint/expand-size", len);
|
||||
expandSize = len;
|
||||
return len;
|
||||
}
|
||||
|
|
26
js/prompt.js
26
js/prompt.js
|
@ -20,8 +20,8 @@ async function getStyles() {
|
|||
/** @type {string[]} */
|
||||
let stored = null;
|
||||
try {
|
||||
stored = JSON.parse(localStorage.getItem("promptStyle"));
|
||||
// doesn't seem to throw a syntaxerror if the localstorage item simply doesn't exist?
|
||||
stored = JSON.parse(localStorage.getItem("openoutpaint/promptStyle"));
|
||||
// doesn't seem to throw a syntaxerror if the localStorage item simply doesn't exist?
|
||||
if (stored == null) stored = [];
|
||||
} catch (e) {
|
||||
stored = [];
|
||||
|
@ -40,11 +40,14 @@ async function getStyles() {
|
|||
selected = value;
|
||||
}
|
||||
stableDiffusionData.styles = selected;
|
||||
localStorage.setItem("promptStyle", JSON.stringify(selected));
|
||||
localStorage.setItem(
|
||||
"openoutpaint/promptStyle",
|
||||
JSON.stringify(selected)
|
||||
);
|
||||
});
|
||||
|
||||
styleSelectElement.value = stored;
|
||||
localStorage.setItem("promptStyle", JSON.stringify(stored));
|
||||
localStorage.setItem("openoutpaint/promptStyle", JSON.stringify(stored));
|
||||
} catch (e) {
|
||||
console.warn("[index] Failed to fetch prompt styles");
|
||||
console.warn(e);
|
||||
|
@ -66,18 +69,21 @@ async function getStyles() {
|
|||
promptEl.oninput = () => {
|
||||
stableDiffusionData.prompt = promptEl.value;
|
||||
promptEl.title = promptEl.value;
|
||||
localStorage.setItem("prompt", stableDiffusionData.prompt);
|
||||
localStorage.setItem("openoutpaint/prompt", stableDiffusionData.prompt);
|
||||
};
|
||||
|
||||
negativePromptEl.oninput = () => {
|
||||
stableDiffusionData.negative_prompt = negativePromptEl.value;
|
||||
negativePromptEl.title = negativePromptEl.value;
|
||||
localStorage.setItem("neg_prompt", stableDiffusionData.negative_prompt);
|
||||
localStorage.setItem(
|
||||
"openoutpaint/neg_prompt",
|
||||
stableDiffusionData.negative_prompt
|
||||
);
|
||||
};
|
||||
|
||||
// Load from local storage if set
|
||||
const storedPrompt = localStorage.getItem("prompt");
|
||||
const storedNeg = localStorage.getItem("neg_prompt");
|
||||
const storedPrompt = localStorage.getItem("openoutpaint/prompt");
|
||||
const storedNeg = localStorage.getItem("openoutpaint/neg_prompt");
|
||||
const promptDefaultValue =
|
||||
storedPrompt === null ? defaultPrompt : storedPrompt;
|
||||
const negativePromptDefaultValue =
|
||||
|
@ -137,7 +143,7 @@ async function getStyles() {
|
|||
stableDiffusionData.prompt = prompt;
|
||||
promptEl.title = prompt;
|
||||
promptEl.value = prompt;
|
||||
localStorage.setItem("prompt", prompt);
|
||||
localStorage.setItem("openoutpaint/prompt", prompt);
|
||||
});
|
||||
promptBtn.textContent = (samePrompt ? "= " : "") + prompt;
|
||||
|
||||
|
@ -147,7 +153,7 @@ async function getStyles() {
|
|||
stableDiffusionData.negative_prompt = negative;
|
||||
negativePromptEl.title = negative;
|
||||
negativePromptEl.value = negative;
|
||||
localStorage.setItem("neg_prompt", negative);
|
||||
localStorage.setItem("openoutpaint/neg_prompt", negative);
|
||||
});
|
||||
negativeBtn.textContent = (sameNegativePrompt ? "= " : "") + negative;
|
||||
|
||||
|
|
|
@ -65,14 +65,21 @@
|
|||
const canvasHeight = document.getElementById("canvas-height");
|
||||
|
||||
function writeToLocalStorage() {
|
||||
localStorage.setItem("settings.canvas-width", canvasWidth.value);
|
||||
localStorage.setItem("settings.canvas-height", canvasHeight.value);
|
||||
localStorage.setItem(
|
||||
"openoutpaint/settings.canvas-width",
|
||||
canvasWidth.value
|
||||
);
|
||||
localStorage.setItem(
|
||||
"openoutpaint/settings.canvas-height",
|
||||
canvasHeight.value
|
||||
);
|
||||
}
|
||||
|
||||
// Loads values from local storage
|
||||
canvasWidth.value = localStorage.getItem("settings.canvas-width") || 2048;
|
||||
canvasWidth.value =
|
||||
localStorage.getItem("openoutpaint/settings.canvas-width") || 2048;
|
||||
canvasHeight.value =
|
||||
localStorage.getItem("settings.canvas-height") || 2048;
|
||||
localStorage.getItem("openoutpaint/settings.canvas-height") || 2048;
|
||||
|
||||
writeToLocalStorage();
|
||||
|
||||
|
|
Loading…
Reference in a new issue