Require single quotes

This commit is contained in:
valadaptive
2023-12-02 13:04:51 -05:00
parent a06f1e8ad6
commit a37f874e38
76 changed files with 4135 additions and 4134 deletions

View File

@ -1,7 +1,7 @@
import { callPopup, chat_metadata, eventSource, event_types, generateQuietPrompt, getCurrentChatId, getRequestHeaders, getThumbnailUrl } from "../script.js";
import { saveMetadataDebounced } from "./extensions.js";
import { registerSlashCommand } from "./slash-commands.js";
import { stringFormat } from "./utils.js";
import { callPopup, chat_metadata, eventSource, event_types, generateQuietPrompt, getCurrentChatId, getRequestHeaders, getThumbnailUrl } from '../script.js';
import { saveMetadataDebounced } from './extensions.js';
import { registerSlashCommand } from './slash-commands.js';
import { stringFormat } from './utils.js';
const BG_METADATA_KEY = 'custom_background';
const LIST_METADATA_KEY = 'chat_backgrounds';
@ -66,7 +66,7 @@ function highlightLockedBackground() {
return;
}
$(`.bg_example`).each(function () {
$('.bg_example').each(function () {
const url = $(this).data('url');
if (url === lockedBackground) {
$(this).addClass('locked');
@ -116,15 +116,15 @@ function setCustomBackground() {
const file = chat_metadata[BG_METADATA_KEY];
// bg already set
if (document.getElementById("bg_custom").style.backgroundImage == file) {
if (document.getElementById('bg_custom').style.backgroundImage == file) {
return;
}
$("#bg_custom").css("background-image", file);
$('#bg_custom').css('background-image', file);
}
function unsetCustomBackground() {
$("#bg_custom").css("background-image", 'none');
$('#bg_custom').css('background-image', 'none');
}
function onSelectBackgroundClick() {
@ -152,12 +152,12 @@ function onSelectBackgroundClick() {
return;
}
const bgFile = $(this).attr("bgfile");
const bgFile = $(this).attr('bgfile');
const backgroundUrl = getBackgroundPath(bgFile);
// Fetching to browser memory to reduce flicker
fetch(backgroundUrl).then(() => {
$("#bg1").css("background-image", relativeBgImage);
$('#bg1').css('background-image', relativeBgImage);
setBackground(bgFile);
}).catch(() => {
console.log('Background could not be set: ' + backgroundUrl);
@ -258,7 +258,7 @@ async function onDeleteBackgroundClick(e) {
const bgToDelete = $(this).closest('.bg_example');
const url = bgToDelete.data('url');
const isCustom = bgToDelete.attr('custom') === 'true';
const confirm = await callPopup("<h3>Delete the background?</h3>", 'confirm');
const confirm = await callPopup('<h3>Delete the background?</h3>', 'confirm');
const bg = bgToDelete.attr('bgfile');
if (confirm) {
@ -299,7 +299,7 @@ async function onDeleteBackgroundClick(e) {
}
}
const autoBgPrompt = `Pause your roleplay and choose a location ONLY from the provided list that is the most suitable for the current scene. Do not output any other text:\n{0}`;
const autoBgPrompt = 'Pause your roleplay and choose a location ONLY from the provided list that is the most suitable for the current scene. Do not output any other text:\n{0}';
async function autoBackgroundCommand() {
/** @type {HTMLElement[]} */
@ -326,21 +326,21 @@ async function autoBackgroundCommand() {
}
export async function getBackgrounds() {
const response = await fetch("/getbackgrounds", {
method: "POST",
const response = await fetch('/getbackgrounds', {
method: 'POST',
headers: getRequestHeaders(),
body: JSON.stringify({
"": "",
'': '',
}),
});
if (response.ok === true) {
const getData = await response.json();
//background = getData;
//console.log(getData.length);
$("#bg_menu_content").children('div').remove();
$('#bg_menu_content').children('div').remove();
for (const bg of getData) {
const template = getBackgroundFromTemplate(bg, false);
$("#bg_menu_content").append(template);
$('#bg_menu_content').append(template);
}
}
}
@ -351,7 +351,7 @@ export async function getBackgrounds() {
* @returns {string} URL of the background
*/
function getUrlParameter(block) {
return $(block).closest(".bg_example").data("url");
return $(block).closest('.bg_example').data('url');
}
/**
@ -377,8 +377,8 @@ function getBackgroundFromTemplate(bg, isCustom) {
async function setBackground(bg) {
jQuery.ajax({
type: "POST", //
url: "/setbackground", //
type: 'POST', //
url: '/setbackground', //
data: JSON.stringify({
bg: bg,
}),
@ -386,8 +386,8 @@ async function setBackground(bg) {
},
cache: false,
dataType: "json",
contentType: "application/json",
dataType: 'json',
contentType: 'application/json',
//processData: false,
success: function (html) { },
error: function (jqXHR, exception) {
@ -398,8 +398,8 @@ async function setBackground(bg) {
}
async function delBackground(bg) {
await fetch("/delbackground", {
method: "POST",
await fetch('/delbackground', {
method: 'POST',
headers: getRequestHeaders(),
body: JSON.stringify({
bg: bg,
@ -408,7 +408,7 @@ async function delBackground(bg) {
}
function onBackgroundUploadSelected() {
const form = $("#form_bg_download").get(0);
const form = $('#form_bg_download').get(0);
if (!(form instanceof HTMLFormElement)) {
console.error('form_bg_download is not a form');
@ -426,8 +426,8 @@ function onBackgroundUploadSelected() {
*/
function uploadBackground(formData) {
jQuery.ajax({
type: "POST",
url: "/downloadbackground",
type: 'POST',
url: '/downloadbackground',
data: formData,
beforeSend: function () {
},
@ -436,7 +436,7 @@ function uploadBackground(formData) {
processData: false,
success: async function (bg) {
setBackground(bg);
$("#bg1").css("background-image", `url("${getBackgroundPath(bg)}"`);
$('#bg1').css('background-image', `url("${getBackgroundPath(bg)}"`);
await getBackgrounds();
highlightNewBackground(bg);
},
@ -460,9 +460,9 @@ function highlightNewBackground(bg) {
function onBackgroundFilterInput() {
const filterValue = String($(this).val()).toLowerCase();
$("#bg_menu_content > div").each(function () {
$('#bg_menu_content > div').each(function () {
const $bgContent = $(this);
if ($bgContent.attr("title").toLowerCase().includes(filterValue)) {
if ($bgContent.attr('title').toLowerCase().includes(filterValue)) {
$bgContent.show();
} else {
$bgContent.hide();
@ -473,16 +473,16 @@ function onBackgroundFilterInput() {
export function initBackgrounds() {
eventSource.on(event_types.CHAT_CHANGED, onChatChanged);
eventSource.on(event_types.FORCE_SET_BACKGROUND, forceSetBackground);
$(document).on("click", '.bg_example', onSelectBackgroundClick);
$(document).on('click', '.bg_example', onSelectBackgroundClick);
$(document).on('click', '.bg_example_lock', onLockBackgroundClick);
$(document).on('click', '.bg_example_unlock', onUnlockBackgroundClick);
$(document).on('click', '.bg_example_edit', onRenameBackgroundClick);
$(document).on("click", '.bg_example_cross', onDeleteBackgroundClick);
$(document).on("click", '.bg_example_copy', onCopyToSystemBackgroundClick);
$('#auto_background').on("click", autoBackgroundCommand);
$("#add_bg_button").on('change', onBackgroundUploadSelected);
$("#bg-filter").on("input", onBackgroundFilterInput);
registerSlashCommand('lockbg', onLockBackgroundClick, ['bglock'], " locks a background for the currently selected chat", true, true);
$(document).on('click', '.bg_example_cross', onDeleteBackgroundClick);
$(document).on('click', '.bg_example_copy', onCopyToSystemBackgroundClick);
$('#auto_background').on('click', autoBackgroundCommand);
$('#add_bg_button').on('change', onBackgroundUploadSelected);
$('#bg-filter').on('input', onBackgroundFilterInput);
registerSlashCommand('lockbg', onLockBackgroundClick, ['bglock'], ' locks a background for the currently selected chat', true, true);
registerSlashCommand('unlockbg', onUnlockBackgroundClick, ['bgunlock'], ' unlocks a background for the currently selected chat', true, true);
registerSlashCommand('autobg', autoBackgroundCommand, ['bgauto'], ' automatically changes the background based on the chat context using the AI request prompt', true, true);
}