|
|
(()=>{ |
|
|
var CRC32; |
|
|
(function (factory) { |
|
|
if (typeof DO_NOT_EXPORT_CRC === "undefined") { |
|
|
if ("object" === typeof exports) { |
|
|
factory(exports); |
|
|
} else if ("function" === typeof define && define.amd) { |
|
|
define(function () { |
|
|
var module = {}; |
|
|
factory(module); |
|
|
return module; |
|
|
}); |
|
|
} else { |
|
|
factory((CRC32 = {})); |
|
|
} |
|
|
} else { |
|
|
factory((CRC32 = {})); |
|
|
} |
|
|
})(function (CRC32) { |
|
|
CRC32.version = "0.3.0"; |
|
|
|
|
|
function signed_crc_table() { |
|
|
var c = 0, |
|
|
table = new Array(256); |
|
|
|
|
|
for (var n = 0; n != 256; ++n) { |
|
|
c = n; |
|
|
c = c & 1 ? -306674912 ^ (c >>> 1) : c >>> 1; |
|
|
c = c & 1 ? -306674912 ^ (c >>> 1) : c >>> 1; |
|
|
c = c & 1 ? -306674912 ^ (c >>> 1) : c >>> 1; |
|
|
c = c & 1 ? -306674912 ^ (c >>> 1) : c >>> 1; |
|
|
c = c & 1 ? -306674912 ^ (c >>> 1) : c >>> 1; |
|
|
c = c & 1 ? -306674912 ^ (c >>> 1) : c >>> 1; |
|
|
c = c & 1 ? -306674912 ^ (c >>> 1) : c >>> 1; |
|
|
c = c & 1 ? -306674912 ^ (c >>> 1) : c >>> 1; |
|
|
table[n] = c; |
|
|
} |
|
|
|
|
|
return typeof Int32Array !== "undefined" ? new Int32Array(table) : table; |
|
|
} |
|
|
|
|
|
var table = signed_crc_table(); |
|
|
|
|
|
var use_buffer = typeof Buffer !== "undefined"; |
|
|
function crc32_bstr(bstr) { |
|
|
if (bstr.length > 32768) |
|
|
if (use_buffer) return crc32_buf_8(new Buffer(bstr)); |
|
|
var crc = -1, |
|
|
L = bstr.length - 1; |
|
|
for (var i = 0; i < L; ) { |
|
|
crc = table[(crc ^ bstr.charCodeAt(i++)) & 0xff] ^ (crc >>> 8); |
|
|
crc = table[(crc ^ bstr.charCodeAt(i++)) & 0xff] ^ (crc >>> 8); |
|
|
} |
|
|
if (i === L) crc = (crc >>> 8) ^ table[(crc ^ bstr.charCodeAt(i)) & 0xff]; |
|
|
return crc ^ -1; |
|
|
} |
|
|
|
|
|
function crc32_buf(buf) { |
|
|
if (buf.length > 10000) return crc32_buf_8(buf); |
|
|
for (var crc = -1, i = 0, L = buf.length - 3; i < L; ) { |
|
|
crc = (crc >>> 8) ^ table[(crc ^ buf[i++]) & 0xff]; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ buf[i++]) & 0xff]; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ buf[i++]) & 0xff]; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ buf[i++]) & 0xff]; |
|
|
} |
|
|
while (i < L + 3) crc = (crc >>> 8) ^ table[(crc ^ buf[i++]) & 0xff]; |
|
|
return crc ^ -1; |
|
|
} |
|
|
|
|
|
function crc32_buf_8(buf) { |
|
|
for (var crc = -1, i = 0, L = buf.length - 7; i < L; ) { |
|
|
crc = (crc >>> 8) ^ table[(crc ^ buf[i++]) & 0xff]; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ buf[i++]) & 0xff]; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ buf[i++]) & 0xff]; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ buf[i++]) & 0xff]; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ buf[i++]) & 0xff]; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ buf[i++]) & 0xff]; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ buf[i++]) & 0xff]; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ buf[i++]) & 0xff]; |
|
|
} |
|
|
while (i < L + 7) crc = (crc >>> 8) ^ table[(crc ^ buf[i++]) & 0xff]; |
|
|
return crc ^ -1; |
|
|
} |
|
|
|
|
|
|
|
|
function crc32_str(str) { |
|
|
for (var crc = -1, i = 0, L = str.length, c, d; i < L; ) { |
|
|
c = str.charCodeAt(i++); |
|
|
if (c < 0x80) { |
|
|
crc = (crc >>> 8) ^ table[(crc ^ c) & 0xff]; |
|
|
} else if (c < 0x800) { |
|
|
crc = (crc >>> 8) ^ table[(crc ^ (192 | ((c >> 6) & 31))) & 0xff]; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ (128 | (c & 63))) & 0xff]; |
|
|
} else if (c >= 0xd800 && c < 0xe000) { |
|
|
c = (c & 1023) + 64; |
|
|
d = str.charCodeAt(i++) & 1023; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ (240 | ((c >> 8) & 7))) & 0xff]; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ (128 | ((c >> 2) & 63))) & 0xff]; |
|
|
crc = |
|
|
(crc >>> 8) ^ table[(crc ^ (128 | ((d >> 6) & 15) | (c & 3))) & 0xff]; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ (128 | (d & 63))) & 0xff]; |
|
|
} else { |
|
|
crc = (crc >>> 8) ^ table[(crc ^ (224 | ((c >> 12) & 15))) & 0xff]; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ (128 | ((c >> 6) & 63))) & 0xff]; |
|
|
crc = (crc >>> 8) ^ table[(crc ^ (128 | (c & 63))) & 0xff]; |
|
|
} |
|
|
} |
|
|
return crc ^ -1; |
|
|
} |
|
|
CRC32.table = table; |
|
|
CRC32.bstr = crc32_bstr; |
|
|
CRC32.buf = crc32_buf; |
|
|
CRC32.str = crc32_str; |
|
|
}); |
|
|
|
|
|
var uint8 = new Uint8Array(4); |
|
|
var int32 = new Int32Array(uint8.buffer); |
|
|
var uint32 = new Uint32Array(uint8.buffer); |
|
|
|
|
|
function extractChunks(data) { |
|
|
if (data[0] !== 0x89) throw new Error("Invalid .png file header"); |
|
|
if (data[1] !== 0x50) throw new Error("Invalid .png file header"); |
|
|
if (data[2] !== 0x4e) throw new Error("Invalid .png file header"); |
|
|
if (data[3] !== 0x47) throw new Error("Invalid .png file header"); |
|
|
if (data[4] !== 0x0d) |
|
|
throw new Error( |
|
|
"Invalid .png file header: possibly caused by DOS-Unix line ending conversion?" |
|
|
); |
|
|
if (data[5] !== 0x0a) |
|
|
throw new Error( |
|
|
"Invalid .png file header: possibly caused by DOS-Unix line ending conversion?" |
|
|
); |
|
|
if (data[6] !== 0x1a) throw new Error("Invalid .png file header"); |
|
|
if (data[7] !== 0x0a) |
|
|
throw new Error( |
|
|
"Invalid .png file header: possibly caused by DOS-Unix line ending conversion?" |
|
|
); |
|
|
|
|
|
var ended = false; |
|
|
var chunks = []; |
|
|
var idx = 8; |
|
|
|
|
|
while (idx < data.length) { |
|
|
|
|
|
|
|
|
uint8[3] = data[idx++]; |
|
|
uint8[2] = data[idx++]; |
|
|
uint8[1] = data[idx++]; |
|
|
uint8[0] = data[idx++]; |
|
|
|
|
|
|
|
|
var length = uint32[0] + 4; |
|
|
var chunk = new Uint8Array(length); |
|
|
chunk[0] = data[idx++]; |
|
|
chunk[1] = data[idx++]; |
|
|
chunk[2] = data[idx++]; |
|
|
chunk[3] = data[idx++]; |
|
|
|
|
|
|
|
|
var name = |
|
|
String.fromCharCode(chunk[0]) + |
|
|
String.fromCharCode(chunk[1]) + |
|
|
String.fromCharCode(chunk[2]) + |
|
|
String.fromCharCode(chunk[3]); |
|
|
|
|
|
|
|
|
if (!chunks.length && name !== "IHDR") { |
|
|
throw new Error("IHDR header missing"); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (name === "IEND") { |
|
|
ended = true; |
|
|
chunks.push({ |
|
|
name: name, |
|
|
data: new Uint8Array(0), |
|
|
}); |
|
|
|
|
|
break; |
|
|
} |
|
|
|
|
|
|
|
|
for (var i = 4; i < length; i++) { |
|
|
chunk[i] = data[idx++]; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint8[3] = data[idx++]; |
|
|
uint8[2] = data[idx++]; |
|
|
uint8[1] = data[idx++]; |
|
|
uint8[0] = data[idx++]; |
|
|
|
|
|
var crcActual = int32[0]; |
|
|
var crcExpect = CRC32.buf(chunk); |
|
|
if (crcExpect !== crcActual) { |
|
|
throw new Error( |
|
|
"CRC values for " + |
|
|
name + |
|
|
" header do not match, PNG file is likely corrupted" |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var chunkData = new Uint8Array(chunk.buffer.slice(4)); |
|
|
|
|
|
chunks.push({ |
|
|
name: name, |
|
|
data: chunkData, |
|
|
}); |
|
|
} |
|
|
|
|
|
if (!ended) { |
|
|
throw new Error(".png file ended prematurely: no IEND header was found"); |
|
|
} |
|
|
|
|
|
return chunks; |
|
|
} |
|
|
|
|
|
function decode(data) { |
|
|
if (data.data && data.name) { |
|
|
data = data.data; |
|
|
} |
|
|
|
|
|
var naming = true; |
|
|
var text = ""; |
|
|
var name = ""; |
|
|
|
|
|
for (var i = 0; i < data.length; i++) { |
|
|
var code = data[i]; |
|
|
|
|
|
if (naming) { |
|
|
if (code) { |
|
|
name += String.fromCharCode(code); |
|
|
} else { |
|
|
naming = false; |
|
|
} |
|
|
} else { |
|
|
if (code) { |
|
|
text += String.fromCharCode(code); |
|
|
} else { |
|
|
throw new Error( |
|
|
"Invalid NULL character found. 0x00 character is not permitted in tEXt content" |
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
return { |
|
|
keyword: name, |
|
|
text: text, |
|
|
}; |
|
|
} |
|
|
|
|
|
const inputEvent = new Event("input"); |
|
|
const changeEvent = new Event("change"); |
|
|
let shadowRoot = null; |
|
|
let version_more_16 = null; |
|
|
let result = {}; |
|
|
let png_info_blob = {}; |
|
|
|
|
|
const readNovelAITag = async (file) => { |
|
|
let chunks = []; |
|
|
let textChunks = []; |
|
|
try { |
|
|
const buf = await file.arrayBuffer(); |
|
|
chunks = extractChunks(new Uint8Array(buf)); |
|
|
textChunks = chunks.filter(function (chunk) { |
|
|
return chunk.name === "tEXt" || chunk.name === "iTXt"; |
|
|
}); |
|
|
textChunks = textChunks.map(function (chunk) { |
|
|
if (chunk.name === "iTXt") { |
|
|
let data = chunk.data.filter((x) => x != 0x0); |
|
|
let txt = new TextDecoder().decode(data); |
|
|
return { |
|
|
keyword: "信息", |
|
|
text: txt.slice(10), |
|
|
}; |
|
|
} |
|
|
return decode(chunk.data); |
|
|
}); |
|
|
return textChunks; |
|
|
} catch (err) { |
|
|
console.error(err); |
|
|
} finally { |
|
|
chunks = null; |
|
|
textChunks = null; |
|
|
} |
|
|
return []; |
|
|
}; |
|
|
|
|
|
|
|
|
async function convertDomImageToBlob(imageElement) { |
|
|
const imageUrl = imageElement.src; |
|
|
|
|
|
return await readStoragePng(imageUrl); |
|
|
} |
|
|
|
|
|
|
|
|
async function readStoragePng(dataURI) { |
|
|
var byteString = atob(dataURI.split(",")[1]); |
|
|
|
|
|
|
|
|
var mimeString = dataURI.split(",")[0].split(":")[1].split(";")[0]; |
|
|
|
|
|
|
|
|
var blob = new Blob( |
|
|
[ |
|
|
new Uint8Array(byteString.length).map(function (_, i) { |
|
|
return byteString.charCodeAt(i); |
|
|
}), |
|
|
], |
|
|
{ type: mimeString } |
|
|
); |
|
|
|
|
|
return blob; |
|
|
} |
|
|
|
|
|
|
|
|
let imgStorage=(img)=>{ |
|
|
localStorage.setItem("png_info_img", img.src); |
|
|
} |
|
|
|
|
|
let delayPng_info = function () { |
|
|
return new Promise((resolve) => { |
|
|
this.shadowRoot = document.querySelector("gradio-app"); |
|
|
const observer = new MutationObserver((mutations) => { |
|
|
mutations.forEach((mutation) => { |
|
|
|
|
|
if ( |
|
|
mutation.addedNodes.length && |
|
|
mutation.addedNodes[0].id === "pnginfo_image" |
|
|
) { |
|
|
|
|
|
observer.disconnect(); |
|
|
|
|
|
resolve(mutation.addedNodes[0]); |
|
|
} |
|
|
}); |
|
|
}); |
|
|
observer.observe(this.shadowRoot, { childList: true, subtree: true }); |
|
|
}); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function isElementRendered(el) { |
|
|
const style = window.getComputedStyle(el); |
|
|
|
|
|
if (style.getPropertyValue('display') === 'none') { |
|
|
return false; |
|
|
} |
|
|
|
|
|
|
|
|
if (el.offsetWidth <= 0 || el.offsetHeight <= 0) { |
|
|
return false; |
|
|
} |
|
|
|
|
|
return true; |
|
|
} |
|
|
|
|
|
let delay_png_change = function (png_info) { |
|
|
return new Promise((resolve) => { |
|
|
|
|
|
const observer = new MutationObserver((mutations) => { |
|
|
mutations.forEach((mutation) => { |
|
|
|
|
|
if ( |
|
|
png_info.querySelector("img") |
|
|
) { |
|
|
|
|
|
observer.disconnect(); |
|
|
|
|
|
resolve(png_info.querySelector("img")); |
|
|
} |
|
|
}); |
|
|
}); |
|
|
observer.observe(png_info, { childList: true, subtree: true }); |
|
|
}); |
|
|
}; |
|
|
|
|
|
let delay_png_downloaded = function (downloadNode) { |
|
|
return new Promise((resolve) => { |
|
|
const observer = new MutationObserver((mutations) => { |
|
|
mutations.forEach((mutation) => { |
|
|
if ( |
|
|
downloadNode.querySelector("#txt2img_gallery > div.grid-wrap > div") |
|
|
) { |
|
|
|
|
|
observer.disconnect(); |
|
|
resolve(document.querySelector("#txt2img_gallery > div.grid-wrap > div >button >img")); |
|
|
} |
|
|
}); |
|
|
}); |
|
|
observer.observe(downloadNode, { childList: true, subtree: true }); |
|
|
}); |
|
|
}; |
|
|
|
|
|
let delay_tab_click = function () { |
|
|
return new Promise((resolve) => { |
|
|
|
|
|
if(this.shadowRoot.querySelectorAll('#mode_img2img button')[2]) |
|
|
{ |
|
|
console.log('点击类读取') |
|
|
resolve(this.shadowRoot.querySelectorAll('#mode_img2img button')[2]); |
|
|
} |
|
|
this.shadowRoot = document.querySelector("gradio-app"); |
|
|
const observer = new MutationObserver((mutations) => { |
|
|
mutations.forEach((mutation) => { |
|
|
|
|
|
if ( |
|
|
this.shadowRoot.querySelectorAll('#mode_img2img button')[2] |
|
|
) { |
|
|
|
|
|
observer.disconnect(); |
|
|
|
|
|
resolve(this.shadowRoot.querySelectorAll('#mode_img2img button')[2]); |
|
|
} |
|
|
}); |
|
|
}); |
|
|
observer.observe(this.shadowRoot, { childList: true, subtree: true }); |
|
|
}); |
|
|
}; |
|
|
|
|
|
let delay_canvas = function () { |
|
|
return new Promise((resolve) => { |
|
|
|
|
|
|
|
|
if(this.shadowRoot.querySelector("#img2maskimg > div.svelte-rlgzoo.fixed-height > div > div:nth-child(2)")) |
|
|
{ |
|
|
console.log('点击类读取') |
|
|
resolve(this.shadowRoot.querySelector("#img2maskimg > div.svelte-rlgzoo.fixed-height > div > div:nth-child(2)")); |
|
|
} |
|
|
|
|
|
this.shadowRoot = document.querySelector("gradio-app"); |
|
|
const observer = new MutationObserver((mutations) => { |
|
|
mutations.forEach((mutation) => { |
|
|
|
|
|
if ( |
|
|
this.shadowRoot.querySelector("#img2maskimg > div.svelte-rlgzoo.fixed-height > div > div:nth-child(2)")&&this.shadowRoot.querySelector("#img2maskimg > div.svelte-rlgzoo.fixed-height > div > div:nth-child(2)").children[6]&&this.shadowRoot.querySelector("#img2maskimg > div.svelte-rlgzoo.fixed-height > div > div:nth-child(2)").children[6].style.display!=='none' |
|
|
) { |
|
|
|
|
|
observer.disconnect(); |
|
|
|
|
|
resolve(this.shadowRoot.querySelector("#img2maskimg > div.svelte-rlgzoo.fixed-height > div > div:nth-child(2)")); |
|
|
} |
|
|
}); |
|
|
}); |
|
|
observer.observe(this.shadowRoot, { childList: true, subtree: true }); |
|
|
}); |
|
|
}; |
|
|
|
|
|
|
|
|
let txt2ImgFormFill = () => { |
|
|
shadowRoot=this.shadowRoot |
|
|
let result = this.result; |
|
|
const inputEvent = new Event("input"); |
|
|
const changeEvent = new Event("change", { |
|
|
bubbles: true, |
|
|
}); |
|
|
shadowRoot.querySelector("#tabs .tab-nav").children[0].click(); |
|
|
if(!!this.version_more_16 && !!result.Hiresupscaler && !shadowRoot.querySelector("#txt2img_hr > div.label-wrap.open")){ |
|
|
shadowRoot.querySelector("#txt2img_hr > div.label-wrap").click(); |
|
|
} |
|
|
if(!!result.Clipskip){ |
|
|
shadowRoot.querySelectorAll( |
|
|
"#setting_CLIP_stop_at_last_layers input" |
|
|
)[0].value = Number(result.Clipskip); |
|
|
shadowRoot |
|
|
.querySelectorAll("#setting_CLIP_stop_at_last_layers input")[0] |
|
|
.dispatchEvent(inputEvent); |
|
|
|
|
|
shadowRoot.querySelectorAll( |
|
|
"#setting_CLIP_stop_at_last_layers input" |
|
|
)[1].value = Number(result.Clipskip||2); |
|
|
shadowRoot |
|
|
.querySelectorAll("#setting_CLIP_stop_at_last_layers input")[1] |
|
|
.dispatchEvent(inputEvent); |
|
|
} |
|
|
shadowRoot.querySelector("#txt2img_prompt textarea").value = result.prompt; |
|
|
shadowRoot |
|
|
.querySelector("#txt2img_prompt textarea") |
|
|
.dispatchEvent(inputEvent); |
|
|
|
|
|
shadowRoot.querySelector("#txt2img_neg_prompt textarea").value = |
|
|
result.negativePrompt; |
|
|
shadowRoot |
|
|
.querySelector("#txt2img_neg_prompt textarea") |
|
|
.dispatchEvent(inputEvent); |
|
|
|
|
|
shadowRoot.querySelectorAll("#txt2img_steps input")[0].value = Number( |
|
|
result.Steps |
|
|
); |
|
|
shadowRoot |
|
|
.querySelectorAll("#txt2img_steps input")[0] |
|
|
.dispatchEvent(inputEvent); |
|
|
|
|
|
shadowRoot.querySelectorAll("#txt2img_steps input")[1].value = Number( |
|
|
result.Steps |
|
|
); |
|
|
shadowRoot |
|
|
.querySelectorAll("#txt2img_steps input")[1] |
|
|
.dispatchEvent(inputEvent); |
|
|
|
|
|
shadowRoot.querySelector(`[value="${result.Sampler}"]`).checked = true; |
|
|
shadowRoot |
|
|
.querySelector(`[value="${result.Sampler}"]`) |
|
|
.dispatchEvent(changeEvent); |
|
|
|
|
|
shadowRoot.querySelectorAll("#txt2img_width input")[0].value = Number( |
|
|
result.Size.split("x")[0] |
|
|
); |
|
|
shadowRoot |
|
|
.querySelectorAll("#txt2img_width input")[0] |
|
|
.dispatchEvent(inputEvent); |
|
|
|
|
|
shadowRoot.querySelectorAll("#txt2img_width input")[1].value = Number( |
|
|
result.Size.split("x")[0] |
|
|
); |
|
|
shadowRoot |
|
|
.querySelectorAll("#txt2img_width input")[1] |
|
|
.dispatchEvent(inputEvent); |
|
|
|
|
|
shadowRoot.querySelectorAll("#txt2img_height input")[0].value = Number( |
|
|
result.Size.split("x")[1] |
|
|
); |
|
|
shadowRoot |
|
|
.querySelectorAll("#txt2img_height input")[0] |
|
|
.dispatchEvent(inputEvent); |
|
|
|
|
|
shadowRoot.querySelectorAll("#txt2img_height input")[1].value = Number( |
|
|
result.Size.split("x")[1] |
|
|
); |
|
|
shadowRoot |
|
|
.querySelectorAll("#txt2img_height input")[1] |
|
|
.dispatchEvent(inputEvent); |
|
|
|
|
|
shadowRoot.querySelector("#txt2img_seed input").value = Number(result.Seed); |
|
|
shadowRoot.querySelector("#txt2img_seed input").dispatchEvent(inputEvent); |
|
|
|
|
|
|
|
|
|
|
|
const mousevent = new MouseEvent("mousedown", { |
|
|
view: window, |
|
|
bubbles: true, |
|
|
cancelable: true, |
|
|
}); |
|
|
const focus = new MouseEvent("focus", { |
|
|
view: window, |
|
|
bubbles: true, |
|
|
cancelable: true, |
|
|
}); |
|
|
|
|
|
if(!this.version_more_16){ |
|
|
if (!!result.Hiresupscaler) { |
|
|
|
|
|
shadowRoot.querySelector("#txt2img_enable_hr input").checked =true |
|
|
shadowRoot.querySelector("#txt2img_enable_hr input").dispatchEvent(changeEvent); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const hr_upscaler_element = document.querySelector( |
|
|
'#txt2img_hr_upscaler > label > div > div.wrap-inner> div > input' |
|
|
); |
|
|
hr_upscaler_element.dispatchEvent(focus); |
|
|
|
|
|
queueMicrotask(() => { |
|
|
const Hiresupscaler_list_elem = shadowRoot.querySelector( |
|
|
`[data-value="${result.Hiresupscaler || "None"}"]` |
|
|
); |
|
|
Hiresupscaler_list_elem.dispatchEvent(mousevent); |
|
|
}); |
|
|
|
|
|
|
|
|
const hr_sampler_element = document.querySelector( |
|
|
"#hr_sampler > label > div > div.wrap-inner> div > input" |
|
|
) |
|
|
|
|
|
if(!!hr_sampler_element){ |
|
|
hr_sampler_element.dispatchEvent(focus); |
|
|
queueMicrotask(() => { |
|
|
|
|
|
const Hiressampler_list_elem = shadowRoot.querySelector( |
|
|
`[data-value="${result. Hiressampler || "Use same sampler"}"]` |
|
|
); |
|
|
Hiressampler_list_elem.dispatchEvent(mousevent); |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const hr_checkpoint_element = document.querySelector( |
|
|
"#hr_checkpoint > label > div > div.wrap-inner > div > input" |
|
|
) |
|
|
|
|
|
if(!!hr_checkpoint_element){ |
|
|
hr_checkpoint_element.dispatchEvent(focus); |
|
|
queueMicrotask(() => { |
|
|
|
|
|
var Hirescheckpoint=result.Hirescheckpoint |
|
|
|
|
|
const Hirescheckpoint_list_elem = document.querySelector( |
|
|
`[data-value="${Hirescheckpoint || "Use same checkpoint"}"]` |
|
|
); |
|
|
try { |
|
|
Hirescheckpoint_list_elem.dispatchEvent(mousevent); |
|
|
} catch (error) { |
|
|
console.error(`出错了,可能没有指定的ckpt:${Hirescheckpoint}`); |
|
|
} |
|
|
}); |
|
|
} |
|
|
|
|
|
if (!!result.Hiresupscaler) { |
|
|
shadowRoot.querySelectorAll("#txt2img_hires_steps input")[0].value = |
|
|
Number(result.Hiressteps) || 0; |
|
|
shadowRoot |
|
|
.querySelectorAll("#txt2img_hires_steps input")[0] |
|
|
.dispatchEvent(inputEvent); |
|
|
|
|
|
shadowRoot.querySelectorAll("#txt2img_hires_steps input")[1].value = |
|
|
Number(result.Hiressteps) || 0; |
|
|
shadowRoot |
|
|
.querySelectorAll("#txt2img_hires_steps input")[1] |
|
|
.dispatchEvent(inputEvent); |
|
|
|
|
|
shadowRoot.querySelectorAll("#txt2img_denoising_strength input")[0].value = |
|
|
Number(result.Denoisingstrength) || 0; |
|
|
shadowRoot |
|
|
.querySelectorAll("#txt2img_denoising_strength input")[0] |
|
|
.dispatchEvent(inputEvent); |
|
|
|
|
|
shadowRoot.querySelectorAll("#txt2img_denoising_strength input")[1].value = |
|
|
Number(result.Denoisingstrength) || 0; |
|
|
shadowRoot |
|
|
.querySelectorAll("#txt2img_denoising_strength input")[1] |
|
|
.dispatchEvent(inputEvent); |
|
|
|
|
|
shadowRoot.querySelectorAll("#txt2img_hr_scale input")[0].value = |
|
|
Number(result.Hiresupscale) || 1; |
|
|
shadowRoot |
|
|
.querySelectorAll("#txt2img_hr_scale input")[0] |
|
|
.dispatchEvent(inputEvent); |
|
|
|
|
|
shadowRoot.querySelectorAll("#txt2img_hr_scale input")[1].value = |
|
|
Number(result.Hiresupscale) || 1; |
|
|
shadowRoot |
|
|
.querySelectorAll("#txt2img_hr_scale input")[1] |
|
|
.dispatchEvent(inputEvent); |
|
|
|
|
|
if(!!shadowRoot.querySelector("#hires_prompt > label > textarea")){ |
|
|
shadowRoot.querySelector("#hires_prompt > label > textarea").value = |
|
|
result.HiresPrompt; |
|
|
shadowRoot |
|
|
.querySelector("#hires_prompt > label > textarea") |
|
|
.dispatchEvent(inputEvent); |
|
|
} |
|
|
if(!!shadowRoot.querySelector("#hires_neg_prompt > label > textarea")){ |
|
|
shadowRoot.querySelector("#hires_neg_prompt > label > textarea").value = |
|
|
result.HiresNegativePrompt; |
|
|
shadowRoot |
|
|
.querySelector("#hires_neg_prompt > label > textarea") |
|
|
.dispatchEvent(inputEvent); |
|
|
} |
|
|
} |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
let img2ImgFormFill = () => { |
|
|
let result = this.result; |
|
|
const inputEvent = new Event("input"); |
|
|
const changeEvent = new Event("change", { |
|
|
bubbles: true, |
|
|
}); |
|
|
this.shadowRoot.querySelector("#tabs .tab-nav").children[1].click(); |
|
|
this.shadowRoot.querySelectorAll('#mode_img2img button')[0].click() |
|
|
if(!!result.Clipskip){ |
|
|
this.shadowRoot.querySelectorAll('#setting_CLIP_stop_at_last_layers input')[0].value = Number(result.Clipskip) |
|
|
this.shadowRoot.querySelectorAll('#setting_CLIP_stop_at_last_layers input')[0].dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelectorAll('#setting_CLIP_stop_at_last_layers input')[1].value = Number(result.Clipskip) |
|
|
this.shadowRoot.querySelectorAll('#setting_CLIP_stop_at_last_layers input')[1].dispatchEvent(inputEvent); |
|
|
} |
|
|
|
|
|
|
|
|
this.shadowRoot.querySelector('#img2img_prompt textarea').value = result.prompt |
|
|
this.shadowRoot.querySelector('#img2img_prompt textarea').dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelector('#img2img_neg_prompt textarea').value = result.negativePrompt |
|
|
this.shadowRoot.querySelector('#img2img_neg_prompt textarea').dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelectorAll('#img2img_steps input')[0].value = Number(result.Steps) |
|
|
this.shadowRoot.querySelectorAll('#img2img_steps input')[0].dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelectorAll('#img2img_steps input')[1].value = Number(result.Steps) |
|
|
this.shadowRoot.querySelectorAll('#img2img_steps input')[1].dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelectorAll(`[value="${result.Sampler}"]`)[1].checked = true; |
|
|
this.shadowRoot.querySelectorAll(`[value="${result.Sampler}"]`)[1].dispatchEvent(changeEvent) |
|
|
|
|
|
this.shadowRoot.querySelectorAll('#img2img_width input')[0].value = Number(result.Size.split('x')[0]) |
|
|
this.shadowRoot.querySelectorAll('#img2img_width input')[0].dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelectorAll('#img2img_width input')[1].value = Number(result.Size.split('x')[0]) |
|
|
this.shadowRoot.querySelectorAll('#img2img_width input')[1].dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelectorAll('#img2img_height input')[0].value = Number(result.Size.split('x')[1]) |
|
|
this.shadowRoot.querySelectorAll('#img2img_height input')[0].dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelectorAll('#img2img_height input')[1].value = Number(result.Size.split('x')[1]) |
|
|
this.shadowRoot.querySelectorAll('#img2img_height input')[1].dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelector('#img2img_seed input').value = Number(result.Seed) |
|
|
this.shadowRoot.querySelector('#img2img_seed input').dispatchEvent(inputEvent); |
|
|
|
|
|
const file = new File([this.png_info_blob], 'example.png'); |
|
|
const dataTransfer = new DataTransfer(); |
|
|
dataTransfer.items.add(file); |
|
|
const fileList = dataTransfer.files; |
|
|
this.shadowRoot.querySelector("#img2img_image input").files = fileList; |
|
|
this.shadowRoot.querySelector('#img2img_image input').dispatchEvent(changeEvent); |
|
|
}; |
|
|
|
|
|
|
|
|
let inpaintTabFormFill=async ()=> { |
|
|
let result = this.result; |
|
|
const inputEvent = new Event("input"); |
|
|
const changeEvent = new Event("change", { |
|
|
bubbles: true, |
|
|
}); |
|
|
|
|
|
let screenWidth = window.screen.width; |
|
|
|
|
|
|
|
|
let inpaintButton=await delay_tab_click() |
|
|
inpaintButton.onclick=async ()=>{ |
|
|
let temp=await delay_canvas() |
|
|
temp.classList.remove('wrap', 'svelte-yigbas'); |
|
|
temp.querySelectorAll('canvas').forEach(e => e.style.height = ''); |
|
|
temp.querySelectorAll('canvas').forEach(e => {e.style.width = '100%';console.log(e.style.width)}); |
|
|
} |
|
|
|
|
|
this.shadowRoot.querySelector("#tabs .tab-nav").children[1].click(); |
|
|
this.shadowRoot.querySelectorAll('#mode_img2img button')[2].click() |
|
|
if(!!result.Clipskip) { |
|
|
this.shadowRoot.querySelectorAll('#setting_CLIP_stop_at_last_layers input')[0].value = Number(result.Clipskip) |
|
|
this.shadowRoot.querySelectorAll('#setting_CLIP_stop_at_last_layers input')[0].dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelectorAll('#setting_CLIP_stop_at_last_layers input')[1].value = Number(result.Clipskip) |
|
|
this.shadowRoot.querySelectorAll('#setting_CLIP_stop_at_last_layers input')[1].dispatchEvent(inputEvent); |
|
|
} |
|
|
this.shadowRoot.querySelector('#img2img_prompt textarea').value = result.prompt |
|
|
this.shadowRoot.querySelector('#img2img_prompt textarea').dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelector('#img2img_neg_prompt textarea').value = result.negativePrompt |
|
|
this.shadowRoot.querySelector('#img2img_neg_prompt textarea').dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelectorAll('#img2img_steps input')[0].value = Number(result.Steps) |
|
|
this.shadowRoot.querySelectorAll('#img2img_steps input')[0].dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelectorAll('#img2img_steps input')[1].value = Number(result.Steps) |
|
|
this.shadowRoot.querySelectorAll('#img2img_steps input')[1].dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelectorAll(`[value="${result.Sampler}"]`)[1].checked = true; |
|
|
this.shadowRoot.querySelectorAll(`[value="${result.Sampler}"]`)[1].dispatchEvent(changeEvent) |
|
|
|
|
|
this.shadowRoot.querySelectorAll('#img2img_width input')[0].value = Number(result.Size.split('x')[0]) |
|
|
this.shadowRoot.querySelectorAll('#img2img_width input')[0].dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelectorAll('#img2img_width input')[1].value = Number(result.Size.split('x')[0]) |
|
|
this.shadowRoot.querySelectorAll('#img2img_width input')[1].dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelectorAll('#img2img_height input')[0].value = Number(result.Size.split('x')[1]) |
|
|
this.shadowRoot.querySelectorAll('#img2img_height input')[0].dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelectorAll('#img2img_height input')[1].value = Number(result.Size.split('x')[1]) |
|
|
this.shadowRoot.querySelectorAll('#img2img_height input')[1].dispatchEvent(inputEvent); |
|
|
|
|
|
this.shadowRoot.querySelector('#img2img_seed input').value = Number(result.Seed) |
|
|
this.shadowRoot.querySelector('#img2img_seed input').dispatchEvent(inputEvent); |
|
|
|
|
|
const file = new File([this.png_info_blob], 'example.png'); |
|
|
const dataTransfer = new DataTransfer(); |
|
|
dataTransfer.items.add(file); |
|
|
const fileList = dataTransfer.files; |
|
|
this.shadowRoot.querySelector("#img2maskimg input").files = fileList; |
|
|
this.shadowRoot.querySelector('#img2maskimg input').dispatchEvent(changeEvent); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function png_info_edit() { |
|
|
let png_info = await delayPng_info(); |
|
|
this.version_more_16 =(Number(this.shadowRoot.querySelector("#footer > div.versions > a").innerText.replace(/\D/g, '')) >= 160) |
|
|
this.result = JSON.parse(localStorage.getItem("tempPngInfo")) || {}; |
|
|
if (this.result.fillType === "txt2img") { |
|
|
txt2ImgFormFill(); |
|
|
} |
|
|
if (this.result.fillType === "img2img") { |
|
|
img2ImgFormFill(); |
|
|
} |
|
|
if (this.result.fillType === "inpaint_tab") { |
|
|
inpaintTabFormFill(); |
|
|
} |
|
|
const changeEvent = new Event("change", { |
|
|
}); |
|
|
|
|
|
|
|
|
png_info.addEventListener("change", async (e) => { |
|
|
|
|
|
const png_info_img = await delay_png_change(png_info); |
|
|
try{imgStorage(png_info_img)} |
|
|
catch(e){console.log('图太大。将不会被保存到本地,')} |
|
|
finally{ |
|
|
let png_info_blob = await convertDomImageToBlob(png_info_img); |
|
|
this.png_info_blob = png_info_blob; |
|
|
let res = await readNovelAITag(png_info_blob); |
|
|
if(!res.length){ |
|
|
this.shadowRoot.querySelector("#txt2img_tab").parentNode.parentNode.children[2].innerText ="这不是一张stablediffusion图片" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
else{ |
|
|
|
|
|
this.shadowRoot.querySelector("#txt2img_tab").parentNode.parentNode.children[2].innerText = res[0].text |
|
|
} |
|
|
|
|
|
const result = {}; |
|
|
|
|
|
let tempRes=res[0].text |
|
|
result.prompt = res[0].text.match(/(.+)(?=(\nNegative prompt))/s)? |
|
|
res[0].text.match(/(.+)(?=(\nNegative prompt))/s)[0].trim():res[0].text.match(/(.+)(?=(\nSteps))/s)[0].trim() |
|
|
result.negativePrompt = res[0].text.match(/(?<=Negative prompt:)(.*)(?=\nSteps:)/s)? |
|
|
res[0].text.match(/(?<=Negative prompt:)(.*)(?=\nSteps:)/s)[0]:"" |
|
|
|
|
|
let HiresPrompt = res[0].text.match(/(?<=Hires prompt: )(.*?)(?=(?!Hires negative prompt) Hires upscale|Hires negative prompt)/s)? |
|
|
res[0].text.match(/(?<=Hires prompt: )(.*?)(?=(?!Hires negative prompt), Hires upscale|, Hires negative prompt)/s)[0]:"" |
|
|
|
|
|
result.HiresPrompt=HiresPrompt.includes(",")?HiresPrompt.replace(/^"|"$/g, "").replace(/\\\\/g,"\\"):HiresPrompt |
|
|
|
|
|
let HiresNegativePrompt =res[0].text.match(/(?<=Hires negative prompt:)(.*)(?=Hires upscale)/s)? |
|
|
res[0].text.match(/(?<=Hires negative prompt: )(.*)(?=, Hires upscale[^r])/s)[0].trim():"" |
|
|
result.HiresNegativePrompt=HiresNegativePrompt.includes(",")?HiresNegativePrompt.replace(/^"|"$/g, "").replace(/\\\\/g,"\\"):HiresNegativePrompt |
|
|
|
|
|
tempRes=tempRes.replace(`${result.prompt}`,"").replace(`\nNegative prompt: ${result.negativePrompt}`,"") |
|
|
.replace(` Hires prompt: ${HiresPrompt},`,"").replace(` Hires negative prompt: ${HiresNegativePrompt}, `,"") |
|
|
|
|
|
let resArr = tempRes.trim().split(","); |
|
|
|
|
|
resArr.forEach((e) => { |
|
|
try{result[e.split(":")[0].replace(/\s+/g, "")] = e.split(":")[1]. |
|
|
replace(/<comma>/g, ",").replace(/<maohao>/g, ":").trim();} |
|
|
catch(err){ |
|
|
console.log(err+"e") |
|
|
} |
|
|
}); |
|
|
|
|
|
this.result = result; |
|
|
|
|
|
|
|
|
this.shadowRoot.querySelector("#txt2img_tab").onclick = () => { |
|
|
this.result.fillType = "txt2img"; |
|
|
localStorage.setItem("tempPngInfo", JSON.stringify(this.result)); |
|
|
txt2ImgFormFill(); |
|
|
}; |
|
|
|
|
|
this.shadowRoot.querySelector("#tab_pnginfo #img2img_tab").onclick = |
|
|
() => { |
|
|
this.result.fillType = "img2img"; |
|
|
localStorage.setItem("tempPngInfo", JSON.stringify(this.result)); |
|
|
img2ImgFormFill(); |
|
|
}; |
|
|
|
|
|
this.shadowRoot.querySelector("#tab_pnginfo #inpaint_tab").onclick = |
|
|
() => { |
|
|
this.result.fillType = "inpaint_tab"; |
|
|
localStorage.setItem("tempPngInfo", JSON.stringify(this.result)); |
|
|
inpaintTabFormFill(); |
|
|
}; |
|
|
} |
|
|
}); |
|
|
|
|
|
png_info.querySelector("#pnginfo_image > div.image-container > div ").addEventListener("drop",()=>{ |
|
|
if(document.querySelector("#pnginfo_image > div.image-container > div > div > button:nth-child(2)")) |
|
|
png_info.querySelector("#pnginfo_image > div.image-container > div > div > button:nth-child(2)").click() |
|
|
png_info.dispatchEvent(changeEvent) |
|
|
}) |
|
|
} |
|
|
|
|
|
document.addEventListener("DOMContentLoaded", async () => { |
|
|
|
|
|
if(localStorage.getItem("png_info_img")) |
|
|
this.png_info_blob = await readStoragePng( |
|
|
localStorage.getItem("png_info_img") |
|
|
); |
|
|
|
|
|
png_info_edit(); |
|
|
|
|
|
}); |
|
|
})() |
|
|
|