From 0a2aa49777761952852b50cd027177774e40a2e5 Mon Sep 17 00:00:00 2001 From: Victor Seiji Hariki Date: Mon, 19 Dec 2022 20:42:13 -0300 Subject: [PATCH 1/2] just a file I'm using to test iframe functionality Signed-off-by: Victor Seiji Hariki --- pages/embed.test.html | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 pages/embed.test.html diff --git a/pages/embed.test.html b/pages/embed.test.html new file mode 100644 index 0000000..6917689 --- /dev/null +++ b/pages/embed.test.html @@ -0,0 +1,74 @@ + + + + + openOutpaint embed + + + + + + + From a04a071965c2245a7725f123bbc8a929c574f9d7 Mon Sep 17 00:00:00 2001 From: Victor Seiji Hariki Date: Mon, 19 Dec 2022 22:23:24 -0300 Subject: [PATCH 2/2] now allows for fixed host setting also makes rest of localstorage data prefixed Signed-off-by: Victor Seiji Hariki --- js/index.js | 33 +++++++++++++++++++++++++++------ js/webui.js | 6 ++++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/js/index.js b/js/index.js index b328b14..2b072f6 100644 --- a/js/index.js +++ b/js/index.js @@ -81,6 +81,9 @@ }; })(); +// Parse url parameters +const urlParams = new URLSearchParams(window.location.search); + window.onload = startup; var stableDiffusionData = { @@ -184,6 +187,22 @@ function startup() { changeSyncCursorSize(); } +function setFixedHost(host, changePromptMessage) { + const hostInput = document.getElementById("host"); + hostInput.value = host; + hostInput.readOnly = true; + hostInput.style.cursor = "default"; + hostInput.style.backgroundColor = "#ddd"; + hostInput.addEventListener("dblclick", () => { + if (confirm(changePromptMessage)) { + hostInput.style.backgroundColor = null; + hostInput.style.cursor = null; + hostInput.readOnly = false; + hostInput.focus(); + } + }); +} + /** * Initial connection checks */ @@ -195,8 +214,10 @@ function testHostConfiguration() { hostEl.value = localStorage.getItem("openoutpaint/host"); const requestHost = (prompt, def = "http://127.0.0.1:7860") => { - let value = window.prompt(prompt, def); - if (value === null) value = "http://127.0.0.1:7860"; + let value = null; + + if (!urlParams.has("noprompt")) value = window.prompt(prompt, def); + if (value === null) value = def; value = value.endsWith("/") ? value.substring(0, value.length - 1) : value; host = value; @@ -489,16 +510,16 @@ const makeSlider = ( textStep = null, valuecb = null ) => { - const local = lsKey && localStorage.getItem(lsKey); + const local = lsKey && localStorage.getItem(`openoutpaint/${lsKey}`); const def = parseFloat(local === null ? defaultValue : local); let cb = (v) => { stableDiffusionData[lsKey] = v; - if (lsKey) localStorage.setItem(lsKey, v); + if (lsKey) localStorage.setItem(`openoutpaint/${lsKey}`, v); }; if (valuecb) { cb = (v) => { valuecb(v); - localStorage.setItem(lsKey, v); + localStorage.setItem(`openoutpaint/${lsKey}`, v); }; } return createSlider(label, el, { @@ -607,7 +628,7 @@ function changeSyncCursorSize() { document.getElementById("cbxSyncCursorSize").checked ); //is this horribly hacky, putting it in SD data instead of making a gross global var? localStorage.setItem( - "sync_cursor_size", + "openoutpaint/sync_cursor_size", stableDiffusionData.sync_cursor_size ); if (stableDiffusionData.sync_cursor_size) { diff --git a/js/webui.js b/js/webui.js index 9151498..bdc4ca4 100644 --- a/js/webui.js +++ b/js/webui.js @@ -72,6 +72,12 @@ console.debug( `[webui] Communication with '${origin}' has been initialized` ); + if (data.host) + setFixedHost( + data.host, + `Are you sure you want to modify the host?\nThis configuration was provided by the hosting page\n - ${parentWindow.document.title} (${origin})` + ); + break; case "openoutpaint/add-resource": {