diff --git a/klite.embd b/klite.embd
index 735ea8f7f..17ee55c55 100644
--- a/klite.embd
+++ b/klite.embd
@@ -4120,7 +4120,9 @@ Current version indicated by LITEVER below.
indexeddb_load("story",""),
indexeddb_load("bgimg",""),
indexeddb_load("savedcustomcss",""),
- ]).then(([loadedsettingsjson, loadedstorycompressed, loadedbackgroundimg, currcss]) => {
+ indexeddb_load("savedusermod",""),
+ indexeddb_load("usermodprops",""),
+ ]).then(([loadedsettingsjson, loadedstorycompressed, loadedbackgroundimg, currcss, currmod, modpropsstr]) => {
try
{
if (loadedsettingsjson != null && loadedsettingsjson != "" && loadedstorycompressed != null && loadedstorycompressed != "") {
@@ -4195,6 +4197,31 @@ Current version indicated by LITEVER below.
window.history.replaceState(null, null, window.location.pathname);
}
+ //load custom mods
+ let resetmod = urlParams.get('resetmod');
+ if (currmod && currmod != "" && !resetmod && modpropsstr)
+ {
+ try {
+ let parsedprops = JSON.parse(modpropsstr);
+ if(parsedprops.persist)
+ {
+ console.log("Applying user mod on startup.");
+ var userModScript = new Function(currmod);
+ userModScript();
+ console.log("User mod applied.");
+ }
+ } catch (e) {
+ console.log("Failed to apply mod.");
+ }
+ }
+ else if(resetmod)
+ {
+ console.log("Custom Mod reset.")
+ indexeddb_save("savedusermod", "");
+ indexeddb_save("usermodprops", "");
+ window.history.replaceState(null, null, window.location.pathname);
+ }
+
} catch (e) {
console.log("Discarded invalid local save: " + e);
loadok = false;
@@ -13414,9 +13441,23 @@ Current version indicated by LITEVER below.
function apply_user_mod()
{
indexeddb_load("savedusermod","").then(currmod=>{
- inputBoxOkCancel("Here, you can apply third-party mod scripts shared by other users.
Caution: This mod will have full access to your story and API keys, so only run third-party mods that you trust! For security, mods must always be manually applied every time.
Want to start modding? Click here to load a simple example mod.","Apply Third-Party Mod",currmod,"Paste Mod Script Here",()=>{
+ indexeddb_load("usermodprops","").then(modpropsstr=>{
+ let applyonstart = false;
+ try
+ {
+ if (modpropsstr) {
+ let parsedprops = JSON.parse(modpropsstr);
+ if (parsedprops.persist) {
+ applyonstart = true;
+ }
+ }
+ } catch (e) { }
+ let txt = `Here, you can apply third-party mod scripts shared by other users.
Caution: This mod will have full access to your story and API keys, so only run third-party mods that you trust!
Mods must always be manually applied every time unless 'Apply Mod On Startup' is selected. If a startup mod breaks KoboldAI Lite, add ?resetmod=1 to the url to uninstall it.
Want to start modding? Click here to load a simple example mod.