Skip to content

Commit 9491b69

Browse files
committed
updated lite (+1 squashed commits)
Squashed commits: [36a56d8] updated lite
1 parent c6f7603 commit 9491b69

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

klite.embd

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Current version indicated by LITEVER below.
1212
-->
1313

1414
<script id="init-config">
15-
const LITEVER = 272;
15+
const LITEVER = 273;
1616
const urlParams = new URLSearchParams(window.location.search);
1717
var localflag = urlParams.get('local'); //this will be replaced automatically in embedded kcpp
1818
const STORAGE_PREFIX = (localflag?"e_":"")+"kaihordewebui_";
@@ -3205,7 +3205,6 @@ Current version indicated by LITEVER below.
32053205
var bold_regex = new RegExp(/\*\*(\S[^*]+\S)\*\*/g); //the fallback regex
32063206
var temp_scenario = null;
32073207
var last_token_budget = ""; //to display token limits
3208-
var last_known_filename = "saved_story.json";
32093208
var last_used_saveslot = -1; //used for corpo mode quicksave
32103209
var backup_localmodeport = 5001; //sometimes we reattempt a different port, this stores a backup
32113210
var localmodeport = 5001;
@@ -3343,6 +3342,7 @@ Current version indicated by LITEVER below.
33433342
speech_synth: 0, //0 is disabled, 1000 is xtts
33443343
xtts_voice: "female_calm",
33453344
kcpp_tts_voice: "kobo",
3345+
oai_tts_voice: "alloy",
33463346
kcpp_tts_json: "",
33473347
beep_on: false,
33483348
notify_on: false,
@@ -3373,6 +3373,7 @@ Current version indicated by LITEVER below.
33733373
save_images: true,
33743374
save_remote_images: false,
33753375
prompt_for_savename: false,
3376+
last_known_filename: "saved_story.json",
33763377
case_sensitive_wi: false,
33773378
last_selected_preset: 0,
33783379
gui_type_story: 0, //0=standard, 1=messenger, 2=aesthetic, 3=corpo
@@ -4240,7 +4241,7 @@ Current version indicated by LITEVER below.
42404241
let loadedsettings = JSON.parse(loadedsettingsjson);
42414242
//see if persist is enabled
42424243
if (loadedsettings && loadedsettings.persist_session) {
4243-
import_compressed_story(loadedstorycompressed,true); //use the same compressed format as shared stories and import it
4244+
import_compressed_story(loadedstorycompressed,true,false); //use the same compressed format as shared stories and import it
42444245
import_props_into_object(localsettings,loadedsettings);
42454246
console.log("Loaded local settings and story");
42464247

@@ -5232,7 +5233,7 @@ Current version indicated by LITEVER below.
52325233
}
52335234
return story;
52345235
}
5235-
function import_compressed_story(cstoryjson,force_load_settngs) { //attempts to load story from compressed json, in KAI format
5236+
function import_compressed_story(cstoryjson,force_load_settngs,save_after_loading=true) { //attempts to load story from compressed json, in KAI format
52365237
console.log("Importing shared story...");
52375238

52385239
var story = decompress_story(cstoryjson);
@@ -5299,7 +5300,7 @@ Current version indicated by LITEVER below.
52995300
});
53005301
}
53015302

5302-
kai_json_load(story, force_load_settngs);
5303+
kai_json_load(story, force_load_settngs, false, save_after_loading);
53035304

53045305
} else {
53055306
msgbox("Could not import from URL or TextData. Is it valid?");
@@ -6025,7 +6026,7 @@ Current version indicated by LITEVER below.
60256026
const matchedlw = match.match(/^[ \t]*/);
60266027
const leadingWhitespace = matchedlw ? matchedlw[0] : '';
60276028
content = unescape_html(content);
6028-
if(content.match(/^\${1,}$/)) //only dollar signs, just return
6029+
if(content.replace(/\s+/g, '').match(/^\${1,}$/)) //only dollar signs, just return
60296030
{
60306031
return match;
60316032
}
@@ -6034,7 +6035,16 @@ Current version indicated by LITEVER below.
60346035
input = input.replace(/(?:^|[^\\])\$(\S[^$\n]*?\S)\$(?!\d)/g, (match, p1) => {
60356036
let content = p1;
60366037
content = unescape_html(content);
6037-
if(content.match(/^\${1,}$/)) //only dollar signs, just return
6038+
if(content.replace(/\s+/g, '').match(/^\${1,}$/)) //only dollar signs, just return
6039+
{
6040+
return match;
6041+
}
6042+
return " "+temml.renderToString(content); // render LaTeX content
6043+
});
6044+
input = input.replace(/(?:^|[^\\])\$ (\S[^$\n$]*?\S) \$(?!\d)/g, (match, p1) => { //special version that handles a single space on both sides
6045+
let content = p1;
6046+
content = unescape_html(content);
6047+
if(content.replace(/\s+/g, '').match(/^\${1,}$/)) //only dollar signs, just return
60386048
{
60396049
return match;
60406050
}
@@ -6043,7 +6053,7 @@ Current version indicated by LITEVER below.
60436053
input = input.replace(/(^\\begin\{math\}\n([\s\S]*?)\n\\end\{math\}$|^\\begin\{equation\}\n([\s\S]*?)\n\\end\{equation\}$)/gm, (match, p1, p2, p3) => { //match math eqns
60446054
let content = p2 || p3;
60456055
content = unescape_html(content);
6046-
if(content.match(/^\${1,}$/)) //only dollar signs, just return
6056+
if(content.replace(/\s+/g, '').match(/^\${1,}$/)) //only dollar signs, just return
60476057
{
60486058
return match;
60496059
}
@@ -6151,7 +6161,10 @@ Current version indicated by LITEVER below.
61516161
md = md.replace(/<\/code\><\/pre\>\n<pre\><code\>/g, "\n");
61526162
if(renderLatex)
61536163
{
6164+
//to aid the latex renderer, we temporarily add newlines between some blocks
6165+
md = md.replace(/<\/li><li>/gm, "</li>\n<li>");
61546166
md = replaceLatex(md);
6167+
md = md.replace(/<\/li>\n<li>/gm, "</li><li>");
61556168
}
61566169
md = md.replace(/<\/ul>\n/gm, "</ul>").replace(/<\/ol>\n/gm, "</ol>");
61576170
md = md.replace(/\\([`_~\*\+\-\.\^\\\<\>\(\)\[\]])/gm, "$1");
@@ -7459,19 +7472,20 @@ Current version indicated by LITEVER below.
74597472
{
74607473
save_file_obj = generate_savefile(localsettings.save_images, localsettings.export_settings, localsettings.export_settings);
74617474
}
7462-
saveFileGeneric(last_known_filename, JSON.stringify(save_file_obj), "application/json");
7475+
saveFileGeneric(localsettings.last_known_filename, JSON.stringify(save_file_obj), "application/json");
74637476
}
74647477

74657478
if(localsettings.prompt_for_savename)
74667479
{
7467-
inputBox("Enter a Filename","Save File",last_known_filename,"Input Filename", ()=>{
7480+
inputBox("Enter a Filename","Save File",localsettings.last_known_filename,"Input Filename", ()=>{
74687481
let userinput = getInputBoxValue();
74697482
if (userinput != null && userinput.trim()!="") {
7470-
last_known_filename = userinput.trim();
7471-
if(!last_known_filename.toLowerCase().includes(".json"))
7483+
let tmp = userinput.trim();
7484+
if(!tmp.toLowerCase().includes(".json"))
74727485
{
7473-
last_known_filename += ".json";
7486+
tmp += ".json";
74747487
}
7488+
localsettings.last_known_filename = tmp;
74757489
save_file();
74767490
}
74777491
},false);
@@ -7623,7 +7637,7 @@ Current version indicated by LITEVER below.
76237637
//quick sanity check. if prompt does not exist, this is not a KAI save.
76247638
kai_json_load(new_loaded_storyobj,false);
76257639
if (selectedFilename && selectedFilename != "") {
7626-
last_known_filename = selectedFilename;
7640+
localsettings.last_known_filename = selectedFilename;
76277641
}
76287642
} else {
76297643
//check for tavernai fields
@@ -7753,7 +7767,7 @@ Current version indicated by LITEVER below.
77537767
return is_kai;
77547768
}
77557769

7756-
function kai_json_load(storyobj, force_load_settings, ignore_multiplayer_sync)
7770+
function kai_json_load(storyobj, force_load_settings, ignore_multiplayer_sync=false, save_after_loading=true)
77577771
{
77587772
//either show popup or just proceed to load
77597773
handle_advload_popup((localsettings.show_advanced_load && !force_load_settings),()=>
@@ -8109,7 +8123,7 @@ Current version indicated by LITEVER below.
81098123
toggle_invert_colors();
81108124
toggle_sidepanel_mode();
81118125
update_for_sidepanel();
8112-
render_gametext(true);
8126+
render_gametext(save_after_loading);
81138127
if(!ignore_multiplayer_sync) //we don't want an infinite loop
81148128
{
81158129
sync_multiplayer(true);
@@ -12902,6 +12916,7 @@ Current version indicated by LITEVER below.
1290212916
document.getElementById("ttsselect").innerHTML = ttshtml;
1290312917
document.getElementById("ttsselect").value = localsettings.speech_synth;
1290412918
document.getElementById("kcpp_tts_voice").value = localsettings.kcpp_tts_voice;
12919+
document.getElementById("oai_tts_voice").value = localsettings.oai_tts_voice;
1290512920
kcpp_tts_json = localsettings.kcpp_tts_json;
1290612921
toggle_tts_mode();
1290712922
document.getElementById("beep_on").checked = localsettings.beep_on;
@@ -13434,6 +13449,7 @@ Current version indicated by LITEVER below.
1343413449
localsettings.speech_synth = document.getElementById("ttsselect").value;
1343513450
localsettings.xtts_voice = document.getElementById("xtts_voices").value;
1343613451
localsettings.kcpp_tts_voice = document.getElementById("kcpp_tts_voice").value;
13452+
localsettings.oai_tts_voice = document.getElementById("oai_tts_voice").value?document.getElementById("oai_tts_voice").value:defaultsettings.oai_tts_voice;
1343713453
localsettings.kcpp_tts_json = kcpp_tts_json;
1343813454
localsettings.beep_on = (document.getElementById("beep_on").checked?true:false);
1343913455
localsettings.notify_on = (document.getElementById("notify_on").checked?true:false);
@@ -14384,12 +14400,12 @@ Current version indicated by LITEVER below.
1438414400
interrogation_db = {};
1438514401
completed_imgs_meta = {};
1438614402
localsettings.adventure_switch_mode = 0;
14403+
localsettings.last_known_filename = defaultsettings.last_known_filename;
1438714404
prev_hl_chunk = null;
1438814405
gametext_focused = false;
1438914406
last_token_budget = "";
1439014407
groupchat_removals = [];
1439114408
welcome = "";
14392-
last_known_filename = "saved_story.json";
1439314409
is_impersonate_user = false;
1439414410
voice_is_processing = false;
1439514411
recentSearchQueries = [];

0 commit comments

Comments
 (0)