2022-10-31 04:21:39 +01:00
|
|
|
"use strict" // Opt in to a restricted variant of JavaScript
|
|
|
|
|
2022-11-09 10:51:41 +01:00
|
|
|
const EXT_REGEX = /(?:\.([^.]+))?$/
|
|
|
|
const TEXT_EXTENSIONS = ['txt', 'json']
|
|
|
|
const IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'bmp', 'tiff', 'tif', 'tga']
|
|
|
|
|
2022-11-04 01:34:12 +01:00
|
|
|
function parseBoolean(stringValue) {
|
|
|
|
if (typeof stringValue === 'boolean') {
|
|
|
|
return stringValue
|
|
|
|
}
|
|
|
|
if (typeof stringValue === 'number') {
|
|
|
|
return stringValue !== 0
|
|
|
|
}
|
|
|
|
if (typeof stringValue !== 'string') {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
switch(stringValue?.toLowerCase()?.trim()) {
|
|
|
|
case "true":
|
|
|
|
case "yes":
|
2022-11-05 18:33:38 +01:00
|
|
|
case "on":
|
2022-11-04 01:34:12 +01:00
|
|
|
case "1":
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case "false":
|
|
|
|
case "no":
|
2022-11-05 18:33:38 +01:00
|
|
|
case "off":
|
2022-11-04 01:34:12 +01:00
|
|
|
case "0":
|
|
|
|
case null:
|
|
|
|
case undefined:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
return Boolean(JSON.parse(stringValue));
|
|
|
|
} catch {
|
|
|
|
return Boolean(stringValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-31 04:21:39 +01:00
|
|
|
const TASK_MAPPING = {
|
|
|
|
prompt: { name: 'Prompt',
|
|
|
|
setUI: (prompt) => {
|
|
|
|
promptField.value = prompt
|
|
|
|
},
|
|
|
|
readUI: () => promptField.value,
|
|
|
|
parse: (val) => val
|
|
|
|
},
|
|
|
|
negative_prompt: { name: 'Negative Prompt',
|
|
|
|
setUI: (negative_prompt) => {
|
|
|
|
negativePromptField.value = negative_prompt
|
|
|
|
},
|
|
|
|
readUI: () => negativePromptField.value,
|
|
|
|
parse: (val) => val
|
|
|
|
},
|
|
|
|
width: { name: 'Width',
|
|
|
|
setUI: (width) => {
|
2022-10-31 04:35:42 +01:00
|
|
|
const oldVal = widthField.value
|
2022-10-31 04:21:39 +01:00
|
|
|
widthField.value = width
|
2022-10-31 04:35:42 +01:00
|
|
|
if (!widthField.value) {
|
|
|
|
widthField.value = oldVal
|
|
|
|
}
|
2022-10-31 04:21:39 +01:00
|
|
|
},
|
|
|
|
readUI: () => parseInt(widthField.value),
|
|
|
|
parse: (val) => parseInt(val)
|
|
|
|
},
|
|
|
|
height: { name: 'Height',
|
|
|
|
setUI: (height) => {
|
2022-10-31 04:35:42 +01:00
|
|
|
const oldVal = heightField.value
|
2022-10-31 04:21:39 +01:00
|
|
|
heightField.value = height
|
2022-10-31 04:35:42 +01:00
|
|
|
if (!heightField.value) {
|
|
|
|
heightField.value = oldVal
|
|
|
|
}
|
2022-10-31 04:21:39 +01:00
|
|
|
},
|
|
|
|
readUI: () => parseInt(heightField.value),
|
|
|
|
parse: (val) => parseInt(val)
|
|
|
|
},
|
|
|
|
seed: { name: 'Seed',
|
|
|
|
setUI: (seed) => {
|
|
|
|
if (!seed) {
|
|
|
|
randomSeedField.checked = true
|
2022-11-03 08:03:50 +01:00
|
|
|
seedField.disabled = true
|
2022-10-31 04:21:39 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
randomSeedField.checked = false
|
2022-11-03 08:03:50 +01:00
|
|
|
seedField.disabled = false
|
2022-10-31 04:21:39 +01:00
|
|
|
seedField.value = seed
|
|
|
|
},
|
|
|
|
readUI: () => (randomSeedField.checked ? Math.floor(Math.random() * 10000000) : parseInt(seedField.value)),
|
|
|
|
parse: (val) => parseInt(val)
|
|
|
|
},
|
|
|
|
num_inference_steps: { name: 'Steps',
|
|
|
|
setUI: (num_inference_steps) => {
|
|
|
|
numInferenceStepsField.value = num_inference_steps
|
|
|
|
},
|
|
|
|
readUI: () => parseInt(numInferenceStepsField.value),
|
|
|
|
parse: (val) => parseInt(val)
|
|
|
|
},
|
|
|
|
guidance_scale: { name: 'Guidance Scale',
|
|
|
|
setUI: (guidance_scale) => {
|
|
|
|
guidanceScaleField.value = guidance_scale
|
2022-11-02 15:53:48 +01:00
|
|
|
updateGuidanceScaleSlider()
|
2022-10-31 04:21:39 +01:00
|
|
|
},
|
|
|
|
readUI: () => parseFloat(guidanceScaleField.value),
|
|
|
|
parse: (val) => parseFloat(val)
|
|
|
|
},
|
|
|
|
prompt_strength: { name: 'Prompt Strength',
|
|
|
|
setUI: (prompt_strength) => {
|
|
|
|
promptStrengthField.value = prompt_strength
|
2022-11-02 15:53:48 +01:00
|
|
|
updatePromptStrengthSlider()
|
2022-10-31 04:21:39 +01:00
|
|
|
},
|
|
|
|
readUI: () => parseFloat(promptStrengthField.value),
|
|
|
|
parse: (val) => parseFloat(val)
|
|
|
|
},
|
|
|
|
|
|
|
|
init_image: { name: 'Initial Image',
|
|
|
|
setUI: (init_image) => {
|
|
|
|
initImagePreview.src = init_image
|
|
|
|
},
|
|
|
|
readUI: () => initImagePreview.src,
|
|
|
|
parse: (val) => val
|
|
|
|
},
|
|
|
|
mask: { name: 'Mask',
|
|
|
|
setUI: (mask) => {
|
|
|
|
inpaintingEditor.setImg(mask)
|
|
|
|
maskSetting.checked = Boolean(mask)
|
|
|
|
},
|
|
|
|
readUI: () => (maskSetting.checked ? inpaintingEditor.getImg() : undefined),
|
|
|
|
parse: (val) => val
|
|
|
|
},
|
|
|
|
|
|
|
|
use_face_correction: { name: 'Use Face Correction',
|
|
|
|
setUI: (use_face_correction) => {
|
2022-11-04 01:34:12 +01:00
|
|
|
useFaceCorrectionField.checked = parseBoolean(use_face_correction)
|
2022-10-31 04:21:39 +01:00
|
|
|
},
|
|
|
|
readUI: () => useFaceCorrectionField.checked,
|
2022-11-04 01:34:12 +01:00
|
|
|
parse: (val) => parseBoolean(val)
|
2022-10-31 04:21:39 +01:00
|
|
|
},
|
|
|
|
use_upscale: { name: 'Use Upscaling',
|
|
|
|
setUI: (use_upscale) => {
|
2022-11-04 01:34:51 +01:00
|
|
|
const oldVal = upscaleModelField.value
|
2022-10-31 04:21:39 +01:00
|
|
|
upscaleModelField.value = use_upscale
|
2022-11-04 01:34:51 +01:00
|
|
|
if (upscaleModelField.value) { // Is a valid value for the field.
|
|
|
|
useUpscalingField.checked = true
|
2022-11-08 14:16:55 +01:00
|
|
|
upscaleModelField.disabled = false
|
2022-11-04 01:34:51 +01:00
|
|
|
} else { // Not a valid value, restore the old value and disable the filter.
|
2022-11-08 14:16:55 +01:00
|
|
|
upscaleModelField.disabled = true
|
2022-11-04 01:34:51 +01:00
|
|
|
upscaleModelField.value = oldVal
|
|
|
|
useUpscalingField.checked = false
|
|
|
|
}
|
2022-10-31 04:21:39 +01:00
|
|
|
},
|
|
|
|
readUI: () => (useUpscalingField.checked ? upscaleModelField.value : undefined),
|
|
|
|
parse: (val) => val
|
|
|
|
},
|
|
|
|
sampler: { name: 'Sampler',
|
|
|
|
setUI: (sampler) => {
|
|
|
|
samplerField.value = sampler
|
|
|
|
},
|
|
|
|
readUI: () => samplerField.value,
|
|
|
|
parse: (val) => val
|
|
|
|
},
|
|
|
|
use_stable_diffusion_model: { name: 'Stable Diffusion model',
|
|
|
|
setUI: (use_stable_diffusion_model) => {
|
2022-10-31 04:35:42 +01:00
|
|
|
const oldVal = stableDiffusionModelField.value
|
2022-10-31 04:41:26 +01:00
|
|
|
|
2022-11-03 08:04:21 +01:00
|
|
|
let pathIdx = use_stable_diffusion_model.lastIndexOf('/') // Linux, Mac paths
|
|
|
|
if (pathIdx < 0) {
|
|
|
|
pathIdx = use_stable_diffusion_model.lastIndexOf('\\') // Windows paths.
|
|
|
|
}
|
2022-10-31 04:41:26 +01:00
|
|
|
if (pathIdx >= 0) {
|
|
|
|
use_stable_diffusion_model = use_stable_diffusion_model.slice(pathIdx + 1)
|
|
|
|
}
|
2022-11-01 09:52:42 +01:00
|
|
|
const modelExt = '.ckpt'
|
|
|
|
if (use_stable_diffusion_model.endsWith(modelExt)) {
|
|
|
|
use_stable_diffusion_model = use_stable_diffusion_model.slice(0, use_stable_diffusion_model.length - modelExt.length)
|
2022-10-31 04:41:26 +01:00
|
|
|
}
|
|
|
|
|
2022-10-31 04:21:39 +01:00
|
|
|
stableDiffusionModelField.value = use_stable_diffusion_model
|
2022-10-31 04:41:26 +01:00
|
|
|
|
2022-10-31 04:35:42 +01:00
|
|
|
if (!stableDiffusionModelField.value) {
|
|
|
|
stableDiffusionModelField.value = oldVal
|
|
|
|
}
|
2022-10-31 04:21:39 +01:00
|
|
|
},
|
|
|
|
readUI: () => stableDiffusionModelField.value,
|
|
|
|
parse: (val) => val
|
|
|
|
},
|
|
|
|
|
|
|
|
numOutputsParallel: { name: 'Parallel Images',
|
|
|
|
setUI: (numOutputsParallel) => {
|
|
|
|
numOutputsParallelField.value = numOutputsParallel
|
|
|
|
},
|
|
|
|
readUI: () => parseInt(numOutputsParallelField.value),
|
|
|
|
parse: (val) => val
|
|
|
|
},
|
|
|
|
|
|
|
|
use_cpu: { name: 'Use CPU',
|
|
|
|
setUI: (use_cpu) => {
|
|
|
|
useCPUField.checked = use_cpu
|
|
|
|
},
|
|
|
|
readUI: () => useCPUField.checked,
|
|
|
|
parse: (val) => val
|
|
|
|
},
|
|
|
|
turbo: { name: 'Turbo',
|
|
|
|
setUI: (turbo) => {
|
|
|
|
turboField.checked = turbo
|
|
|
|
},
|
|
|
|
readUI: () => turboField.checked,
|
|
|
|
parse: (val) => Boolean(val)
|
|
|
|
},
|
|
|
|
use_full_precision: { name: 'Use Full Precision',
|
|
|
|
setUI: (use_full_precision) => {
|
|
|
|
useFullPrecisionField.checked = use_full_precision
|
|
|
|
},
|
|
|
|
readUI: () => useFullPrecisionField.checked,
|
|
|
|
parse: (val) => Boolean(val)
|
|
|
|
},
|
|
|
|
|
|
|
|
stream_image_progress: { name: 'Stream Image Progress',
|
|
|
|
setUI: (stream_image_progress) => {
|
|
|
|
streamImageProgressField.checked = (parseInt(numOutputsTotalField.value) > 50 ? false : stream_image_progress)
|
|
|
|
},
|
|
|
|
readUI: () => streamImageProgressField.checked,
|
|
|
|
parse: (val) => Boolean(val)
|
|
|
|
},
|
|
|
|
show_only_filtered_image: { name: 'Show only the corrected/upscaled image',
|
|
|
|
setUI: (show_only_filtered_image) => {
|
|
|
|
showOnlyFilteredImageField.checked = show_only_filtered_image
|
|
|
|
},
|
|
|
|
readUI: () => showOnlyFilteredImageField.checked,
|
|
|
|
parse: (val) => Boolean(val)
|
|
|
|
},
|
|
|
|
output_format: { name: 'Output Format',
|
|
|
|
setUI: (output_format) => {
|
|
|
|
outputFormatField.value = output_format
|
|
|
|
},
|
|
|
|
readUI: () => outputFormatField.value,
|
|
|
|
parse: (val) => val
|
|
|
|
},
|
|
|
|
save_to_disk_path: { name: 'Save to disk path',
|
|
|
|
setUI: (save_to_disk_path) => {
|
|
|
|
saveToDiskField.checked = Boolean(save_to_disk_path)
|
|
|
|
diskPathField.value = save_to_disk_path
|
|
|
|
},
|
|
|
|
readUI: () => diskPathField.value,
|
|
|
|
parse: (val) => val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function restoreTaskToUI(task) {
|
|
|
|
if ('numOutputsTotal' in task) {
|
|
|
|
numOutputsTotalField.value = task.numOutputsTotal
|
|
|
|
}
|
|
|
|
if ('seed' in task) {
|
|
|
|
randomSeedField.checked = false
|
|
|
|
seedField.value = task.seed
|
|
|
|
}
|
|
|
|
if (!('reqBody' in task)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for (const key in TASK_MAPPING) {
|
|
|
|
if (key in task.reqBody) {
|
|
|
|
TASK_MAPPING[key].setUI(task.reqBody[key])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-31 06:13:04 +01:00
|
|
|
function readUI() {
|
2022-10-31 06:02:23 +01:00
|
|
|
const reqBody = {}
|
|
|
|
for (const key in TASK_MAPPING) {
|
|
|
|
reqBody[key] = TASK_MAPPING[key].readUI()
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
'numOutputsTotal': parseInt(numOutputsTotalField.value),
|
|
|
|
'seed': TASK_MAPPING['seed'].readUI(),
|
|
|
|
'reqBody': reqBody
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-31 04:21:39 +01:00
|
|
|
const TASK_TEXT_MAPPING = {
|
|
|
|
width: 'Width',
|
|
|
|
height: 'Height',
|
|
|
|
seed: 'Seed',
|
|
|
|
num_inference_steps: 'Steps',
|
|
|
|
guidance_scale: 'Guidance Scale',
|
|
|
|
prompt_strength: 'Prompt Strength',
|
|
|
|
use_face_correction: 'Use Face Correction',
|
|
|
|
use_upscale: 'Use Upscaling',
|
|
|
|
sampler: 'Sampler',
|
|
|
|
negative_prompt: 'Negative Prompt',
|
|
|
|
use_stable_diffusion_model: 'Stable Diffusion model'
|
|
|
|
}
|
|
|
|
const afterPromptRe = /^\s*Width\s*:\s*\d+\s*(?:\r\n|\r|\n)+\s*Height\s*:\s*\d+\s*(\r\n|\r|\n)+Seed\s*:\s*\d+\s*$/igm
|
|
|
|
function parseTaskFromText(str) {
|
|
|
|
const taskReqBody = {}
|
|
|
|
|
|
|
|
// Prompt
|
|
|
|
afterPromptRe.lastIndex = 0
|
2022-10-31 06:01:56 +01:00
|
|
|
const match = afterPromptRe.exec(str)
|
2022-10-31 04:21:39 +01:00
|
|
|
if (match) {
|
|
|
|
let prompt = str.slice(0, match.index)
|
|
|
|
str = str.slice(prompt.length)
|
|
|
|
taskReqBody.prompt = prompt.trim()
|
|
|
|
console.log('Prompt:', taskReqBody.prompt)
|
|
|
|
}
|
|
|
|
for (const key in TASK_TEXT_MAPPING) {
|
|
|
|
const name = TASK_TEXT_MAPPING[key];
|
|
|
|
let val = undefined
|
2022-11-08 14:14:11 +01:00
|
|
|
|
|
|
|
const reName = new RegExp(`${name}\\ *:\\ *(.*)(?:\\r\\n|\\r|\\n)*`, 'igm')
|
|
|
|
const match = reName.exec(str);
|
|
|
|
if (match) {
|
|
|
|
str = str.slice(0, match.index) + str.slice(match.index + match[0].length)
|
|
|
|
val = match[1]
|
2022-10-31 04:21:39 +01:00
|
|
|
}
|
2022-11-08 14:14:11 +01:00
|
|
|
if (val !== undefined) {
|
2022-10-31 04:21:39 +01:00
|
|
|
taskReqBody[key] = TASK_MAPPING[key].parse(val.trim())
|
|
|
|
console.log(TASK_MAPPING[key].name + ':', taskReqBody[key])
|
|
|
|
if (!str) {
|
2022-10-31 06:01:56 +01:00
|
|
|
break
|
2022-10-31 04:21:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Object.keys(taskReqBody).length <= 0) {
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
const task = { reqBody: taskReqBody }
|
|
|
|
if ('seed' in taskReqBody) {
|
|
|
|
task.seed = taskReqBody.seed
|
|
|
|
}
|
|
|
|
return task
|
|
|
|
}
|
|
|
|
|
|
|
|
async function readFile(file, i) {
|
|
|
|
const fileContent = (await file.text()).trim()
|
|
|
|
|
|
|
|
// JSON File.
|
|
|
|
if (fileContent.startsWith('{') && fileContent.endsWith('}')) {
|
|
|
|
try {
|
|
|
|
const task = JSON.parse(fileContent)
|
|
|
|
restoreTaskToUI(task)
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(`file[${i}]:${file.name} - File couldn't be parsed.`, e)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Normal txt file.
|
|
|
|
const task = parseTaskFromText(fileContent)
|
|
|
|
if (task) {
|
|
|
|
restoreTaskToUI(task)
|
|
|
|
} else {
|
|
|
|
console.warn(`file[${i}]:${file.name} - File couldn't be parsed.`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function dropHandler(ev) {
|
|
|
|
console.log('Content dropped...')
|
2022-11-08 13:44:26 +01:00
|
|
|
let items = []
|
2022-10-31 04:21:39 +01:00
|
|
|
|
|
|
|
if (ev?.dataTransfer?.items) { // Use DataTransferItemList interface
|
2022-11-08 13:44:26 +01:00
|
|
|
items = Array.from(ev.dataTransfer.items)
|
|
|
|
items = items.filter(item => item.kind === 'file')
|
|
|
|
items = items.map(item => item.getAsFile())
|
2022-10-31 04:21:39 +01:00
|
|
|
} else if (ev?.dataTransfer?.files) { // Use DataTransfer interface
|
2022-11-08 13:44:26 +01:00
|
|
|
items = Array.from(ev.dataTransfer.files)
|
|
|
|
}
|
|
|
|
|
2022-11-09 10:51:41 +01:00
|
|
|
items.forEach(item => {item.file_ext = EXT_REGEX.exec(item.name.toLowerCase())[1]})
|
|
|
|
|
|
|
|
let text_items = items.filter(item => TEXT_EXTENSIONS.includes(item.file_ext))
|
|
|
|
let image_items = items.filter(item => IMAGE_EXTENSIONS.includes(item.file_ext))
|
2022-11-08 13:44:26 +01:00
|
|
|
|
2022-11-09 10:51:41 +01:00
|
|
|
if (image_items.length > 0 && ev.target == initImageSelector) {
|
|
|
|
return // let the event bubble up, so that the Init Image filepicker can receive this
|
2022-10-31 04:21:39 +01:00
|
|
|
}
|
2022-11-09 10:51:41 +01:00
|
|
|
|
|
|
|
ev.preventDefault() // Prevent default behavior (Prevent file/content from being opened)
|
|
|
|
text_items.forEach(readFile)
|
2022-10-31 04:21:39 +01:00
|
|
|
}
|
|
|
|
function dragOverHandler(ev) {
|
|
|
|
console.log('Content in drop zone')
|
|
|
|
|
|
|
|
// Prevent default behavior (Prevent file/content from being opened)
|
|
|
|
ev.preventDefault()
|
|
|
|
|
|
|
|
ev.dataTransfer.dropEffect = "copy"
|
|
|
|
|
|
|
|
let img = new Image()
|
|
|
|
img.src = location.host + '/media/images/favicon-32x32.png'
|
|
|
|
ev.dataTransfer.setDragImage(img, 16, 16)
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener("drop", dropHandler)
|
|
|
|
document.addEventListener("dragover", dragOverHandler)
|
2022-10-31 06:02:23 +01:00
|
|
|
|
2022-11-03 08:10:31 +01:00
|
|
|
const TASK_REQ_NO_EXPORT = [
|
|
|
|
"use_cpu",
|
|
|
|
"turbo",
|
|
|
|
"use_full_precision",
|
|
|
|
"save_to_disk_path"
|
|
|
|
]
|
|
|
|
|
2022-11-14 01:23:04 +01:00
|
|
|
// Retrieve clipboard content and try to parse it
|
|
|
|
async function pasteFromClipboard() {
|
|
|
|
//const text = await navigator.clipboard.readText()
|
|
|
|
let text = await navigator.clipboard.readText();
|
|
|
|
text=text.trim();
|
|
|
|
if (text.startsWith('{') && text.endsWith('}')) {
|
|
|
|
try {
|
|
|
|
const task = JSON.parse(text)
|
|
|
|
restoreTaskToUI(task)
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(`Clipboard JSON couldn't be parsed.`, e)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// Normal txt file.
|
|
|
|
const task = parseTaskFromText(text)
|
|
|
|
if (task) {
|
|
|
|
restoreTaskToUI(task)
|
|
|
|
} else {
|
|
|
|
console.warn(`Clipboard content - File couldn't be parsed.`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adds a copy and a paste icon if the browser grants permission to write to clipboard.
|
2022-10-31 06:02:23 +01:00
|
|
|
function checkWriteToClipboardPermission (result) {
|
|
|
|
if (result.state == "granted" || result.state == "prompt") {
|
|
|
|
const resetSettings = document.getElementById('reset-image-settings')
|
2022-11-14 01:23:04 +01:00
|
|
|
|
|
|
|
// COPY ICON
|
2022-10-31 06:02:23 +01:00
|
|
|
const copyIcon = document.createElement('i')
|
2022-11-09 09:13:43 +01:00
|
|
|
copyIcon.className = 'fa-solid fa-clipboard section-button'
|
2022-10-31 06:02:23 +01:00
|
|
|
copyIcon.innerHTML = `<span class="simple-tooltip right">Copy Image Settings</span>`
|
|
|
|
copyIcon.addEventListener('click', (event) => {
|
|
|
|
event.stopPropagation()
|
2022-11-17 06:19:22 +01:00
|
|
|
// Add css class 'active'
|
|
|
|
copyIcon.classList.add('active')
|
|
|
|
// In 1000 ms remove the 'active' class
|
|
|
|
asyncDelay(1000).then(() => copyIcon.classList.remove('active'))
|
2022-11-03 08:10:31 +01:00
|
|
|
const uiState = readUI()
|
|
|
|
TASK_REQ_NO_EXPORT.forEach((key) => delete uiState.reqBody[key])
|
2022-11-05 18:35:09 +01:00
|
|
|
if (uiState.reqBody.init_image && !IMAGE_REGEX.test(uiState.reqBody.init_image)) {
|
|
|
|
delete uiState.reqBody.init_image
|
|
|
|
delete uiState.reqBody.prompt_strength
|
|
|
|
}
|
2022-11-03 08:10:31 +01:00
|
|
|
navigator.clipboard.writeText(JSON.stringify(uiState, undefined, 4))
|
2022-10-31 06:02:23 +01:00
|
|
|
})
|
|
|
|
resetSettings.parentNode.insertBefore(copyIcon, resetSettings)
|
2022-11-14 01:23:04 +01:00
|
|
|
|
|
|
|
// PASTE ICON
|
|
|
|
const pasteIcon = document.createElement('i')
|
|
|
|
pasteIcon.className = 'fa-solid fa-paste section-button'
|
|
|
|
pasteIcon.innerHTML = `<span class="simple-tooltip right">Paste Image Settings</span>`
|
|
|
|
pasteIcon.addEventListener('click', (event) => {
|
|
|
|
event.stopPropagation()
|
2022-11-17 06:19:22 +01:00
|
|
|
// Add css class 'active'
|
|
|
|
pasteIcon.classList.add('active')
|
|
|
|
// In 1000 ms remove the 'active' class
|
|
|
|
asyncDelay(1000).then(() => pasteIcon.classList.remove('active'))
|
2022-11-14 01:23:04 +01:00
|
|
|
pasteFromClipboard()
|
|
|
|
})
|
|
|
|
resetSettings.parentNode.insertBefore(pasteIcon, resetSettings)
|
2022-10-31 06:02:23 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-14 01:23:04 +01:00
|
|
|
|
|
|
|
// Determine which access we have to the clipboard. Clipboard access is only available on localhost or via TLS.
|
2022-10-31 06:02:23 +01:00
|
|
|
navigator.permissions.query({ name: "clipboard-write" }).then(checkWriteToClipboardPermission, (e) => {
|
|
|
|
if (e instanceof TypeError && typeof navigator?.clipboard?.writeText === 'function') {
|
|
|
|
// Fix for firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1560373
|
|
|
|
checkWriteToClipboardPermission({state:"granted"})
|
|
|
|
}
|
|
|
|
})
|