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.
|
|
|
|
*
|
|
|
|
* 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(
|
|
|
|
function png() { return (reqBody) => new SD.RenderTask(reqBody) }
|
|
|
|
, function jpeg() { return (reqBody) => new SD.RenderTask(reqBody) }
|
2023-02-19 04:37:34 +01:00
|
|
|
, function webp() { return (reqBody) => new SD.RenderTask(reqBody) }
|
2022-12-06 12:34:08 +01:00
|
|
|
),
|
|
|
|
}
|
|
|
|
PLUGINS.OUTPUTS_FORMATS.register = function(...args) {
|
|
|
|
const service = ServiceContainer.prototype.register.apply(this, args)
|
|
|
|
if (typeof outputFormatField !== 'undefined') {
|
|
|
|
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) {
|
|
|
|
const script = document.createElement('script')
|
|
|
|
const promiseSrc = new PromiseSource()
|
|
|
|
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
|
|
|
|
2022-12-06 12:34:08 +01:00
|
|
|
console.log('loading script', url)
|
|
|
|
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 {
|
|
|
|
const res = await fetch('/get/ui_plugins')
|
|
|
|
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) {
|
|
|
|
console.log('error fetching plugin paths', e)
|
2022-10-19 16:57:06 +02:00
|
|
|
}
|
|
|
|
}
|