Added Easy addition to prompt_shortcus

pull/55/head
kyxsune 2023-01-14 14:37:22 -05:00
parent fbfcecec5e
commit ab9ddf086e
2 changed files with 27 additions and 4 deletions

View File

@ -343,6 +343,15 @@
<div class="sp-tab-page" id="sp-prompts-library-tab-page"> <div class="sp-tab-page" id="sp-prompts-library-tab-page">
<sp-label slot="label">Prompt Shortcut: a single word that represent a prompt</sp-label> <sp-label slot="label">Prompt Shortcut: a single word that represent a prompt</sp-label>
<div class="">
<sp-label slot="label">Key for new prompt shortcut</sp-label>
<sp-textarea id="KeyPromptShortcut" placeholder="to be replaced" value=""></sp-textarea>
</div>
<div class="">
<sp-label slot="label">Value for new prompt shortcut</sp-label>
<sp-textarea id="ValuePromptShortcut" placeholder="to be replaced with" value=""></sp-textarea>
<button class="btnSquare" id="btnUpdatePromptShortcut">Add to Prompt Shortcut</button>
</div>
<div class=""> <div class="">
<sp-textarea id="taPromptShortcut" placeholder="prompt shortcut" value=""></sp-textarea> <sp-textarea id="taPromptShortcut" placeholder="prompt shortcut" value=""></sp-textarea>

View File

@ -2503,13 +2503,28 @@ document.getElementById('btnLoadPromptShortcut').addEventListener('click',async
}) })
document.getElementById('btnUpdatePromptShortcut').addEventListener('click',async function(){
try{
prompt_shortcut = await sdapi.loadPromptShortcut()
var newKey = document.getElementById('KeyPromptShortcut').value
var newValue = document.getElementById('ValuePromptShortcut').value
console.log(newKey)
console.log(newValue)
prompt_shortcut[newKey] = newValue
var JSONInPrettyFormat = JSON.stringify(prompt_shortcut, undefined, 4);
console.log(JSONInPrettyFormat)
document.getElementById('taPromptShortcut').value = JSONInPrettyFormat
}catch(e){
console.warn(`loadPromptShortcut warning: ${e}`)
}
})
document document
.getElementById('btnSavePromptShortcut') .getElementById('btnSavePromptShortcut')
.addEventListener('click', async function () { .addEventListener('click', async function () {
try { try {
const r1 = await dialog_box.prompt( const r1 = await dialog_box.prompt(
'Are you sure you want to save prompt shortcut?', 'Are you sure you want to save prompt shortcut?',
"This will override your old prompt shortcut file, you can't undo this operation", "This will override your old prompt shortcut file, you can't undo this operation",
@ -2522,8 +2537,6 @@ document
/* Yes */ /* Yes */
console.log("Save") console.log("Save")
prompt_shortcut_string = document.getElementById('taPromptShortcut').value prompt_shortcut_string = document.getElementById('taPromptShortcut').value
let prompt_shortcut = JSON.parse(prompt_shortcut_string) let prompt_shortcut = JSON.parse(prompt_shortcut_string)
@ -2542,6 +2555,7 @@ document
}) })
// Hi res fix stuff // Hi res fix stuff
var hr_models = [ var hr_models = [