2022-10-19 16:20:05 +02:00
|
|
|
const PLUGIN_API_VERSION = "1.0"
|
|
|
|
|
|
|
|
const PLUGINS = {
|
|
|
|
/**
|
|
|
|
* Register new buttons to show on each output image.
|
2023-04-27 19:56:56 +02:00
|
|
|
*
|
2022-10-19 16:20:05 +02:00
|
|
|
* Example:
|
2022-10-19 17:51:19 +02:00
|
|
|
* PLUGINS['IMAGE_INFO_BUTTONS'].push({
|
2022-10-19 16:20:05 +02:00
|
|
|
* text: 'Make a Similar Image',
|
|
|
|
* on_click: function(origRequest, image) {
|
|
|
|
* let newTaskRequest = getCurrentUserRequest()
|
|
|
|
* newTaskRequest.reqBody = Object.assign({}, origRequest, {
|
|
|
|
* init_image: image.src,
|
|
|
|
* prompt_strength: 0.7,
|
|
|
|
* seed: Math.floor(Math.random() * 10000000)
|
|
|
|
* })
|
|
|
|
* newTaskRequest.seed = newTaskRequest.reqBody.seed
|
|
|
|
* createTask(newTaskRequest)
|
2022-10-19 16:40:45 +02:00
|
|
|
* },
|
|
|
|
* filter: function(origRequest, image) {
|
|
|
|
* // this is an optional function. return true/false to show/hide the button
|
|
|
|
* // if this function isn't set, the button will always be visible
|
|
|
|
* return true
|
2022-10-19 16:20:05 +02:00
|
|
|
* }
|
2022-10-19 17:51:19 +02:00
|
|
|
* })
|
2022-10-19 16:20:05 +02:00
|
|
|
*/
|
2022-11-23 04:04:20 +01:00
|
|
|
IMAGE_INFO_BUTTONS: [],
|
2023-02-08 17:26:55 +01:00
|
|
|
GET_PROMPTS_HOOK: [],
|
2022-12-06 12:34:08 +01:00
|
|
|
MODIFIERS_LOAD: [],
|
|
|
|
TASK_CREATE: [],
|
|
|
|
OUTPUTS_FORMATS: new ServiceContainer(
|
2023-04-27 19:56:56 +02:00
|
|
|
function png() {
|
|
|
|
return (reqBody) => new SD.RenderTask(reqBody)
|
|
|
|
},
|
|
|
|
function jpeg() {
|
|
|
|
return (reqBody) => new SD.RenderTask(reqBody)
|
|
|
|
},
|
|
|
|
function webp() {
|
|
|
|
return (reqBody) => new SD.RenderTask(reqBody)
|
|
|
|
}
|
2023-04-28 12:20:44 +02:00
|
|
|
),
|
2022-12-06 12:34:08 +01:00
|
|
|
}
|
|
|
|
PLUGINS.OUTPUTS_FORMATS.register = function(...args) {
|
|
|
|
const service = ServiceContainer.prototype.register.apply(this, args)
|
2023-04-27 19:56:56 +02:00
|
|
|
if (typeof outputFormatField !== "undefined") {
|
2022-12-06 12:34:08 +01:00
|
|
|
const newOption = document.createElement("option")
|
|
|
|
newOption.setAttribute("value", service.name)
|
|
|
|
newOption.innerText = service.name
|
|
|
|
outputFormatField.appendChild(newOption)
|
|
|
|
}
|
|
|
|
return service
|
2022-10-19 16:20:05 +02:00
|
|
|
}
|
2022-10-19 16:57:06 +02:00
|
|
|
|
2022-12-06 12:34:08 +01:00
|
|
|
function loadScript(url) {
|
2023-04-27 19:56:56 +02:00
|
|
|
const script = document.createElement("script")
|
2022-12-06 12:34:08 +01:00
|
|
|
const promiseSrc = new PromiseSource()
|
2023-04-27 19:56:56 +02:00
|
|
|
script.addEventListener("error", () => promiseSrc.reject(new Error(`Script "${url}" couldn't be loaded.`)))
|
|
|
|
script.addEventListener("load", () => promiseSrc.resolve(url))
|
|
|
|
script.src = url + "?t=" + Date.now()
|
2022-10-19 16:57:06 +02:00
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
console.log("loading script", url)
|
2022-12-06 12:34:08 +01:00
|
|
|
document.head.appendChild(script)
|
2022-10-19 16:57:06 +02:00
|
|
|
|
2022-12-06 12:34:08 +01:00
|
|
|
return promiseSrc.promise
|
|
|
|
}
|
|
|
|
|
|
|
|
async function loadUIPlugins() {
|
|
|
|
try {
|
2023-04-27 19:56:56 +02:00
|
|
|
const res = await fetch("/get/ui_plugins")
|
2022-12-06 12:34:08 +01:00
|
|
|
if (!res.ok) {
|
|
|
|
console.error(`Error HTTP${res.status} while loading plugins list. - ${res.statusText}`)
|
|
|
|
return
|
2022-10-19 16:57:06 +02:00
|
|
|
}
|
2022-12-06 12:34:08 +01:00
|
|
|
const plugins = await res.json()
|
|
|
|
const loadingPromises = plugins.map(loadScript)
|
|
|
|
return await Promise.allSettled(loadingPromises)
|
2022-10-19 18:04:40 +02:00
|
|
|
} catch (e) {
|
2023-04-27 19:56:56 +02:00
|
|
|
console.log("error fetching plugin paths", e)
|
2022-10-19 16:57:06 +02:00
|
|
|
}
|
|
|
|
}
|