Skip to content

Commit 79368e9

Browse files
ConcedoConcedo
Concedo
authored and
Concedo
committed
added unsaved changes prompt
1 parent b845996 commit 79368e9

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

index.html

+25-3
Original file line numberDiff line numberDiff line change
@@ -5267,6 +5267,7 @@
52675267

52685268
function save_file_button(use_existing_save=false) //for triggering an optional popup. if use save is true, assume temp obj is set
52695269
{
5270+
warn_on_quit = false;
52705271
const save_file = function()
52715272
{
52725273
if(!use_existing_save)
@@ -8294,6 +8295,7 @@
82948295

82958296
const slotwrite = function()
82968297
{
8298+
warn_on_quit = false;
82978299
inputBox("Enter a label for this Browser Storage Slot data","Enter a label",savename,defaultsavename,()=>{
82988300
let userinput = getInputBoxValue();
82998301
if(userinput.trim()=="")
@@ -9846,6 +9848,7 @@
98469848
regexreplace_data = [];
98479849
placeholder_tags_data = [];
98489850
}
9851+
warn_on_quit = false;
98499852
render_gametext(save); //necessary to trigger an autosave to wipe out current story in case they exit browser after newgame.
98509853
}
98519854

@@ -10015,6 +10018,16 @@
1001510018
}
1001610019
}
1001710020

10021+
var warn_on_quit = false;
10022+
function handle_quit()
10023+
{
10024+
if(warn_on_quit)
10025+
{
10026+
return "Unsaved changes will be lost!"; //the actual message will not be shown in new browsers
10027+
}
10028+
return undefined;
10029+
}
10030+
1001810031
function handle_escape_button(event)
1001910032
{
1002010033
if(is_popup_open())
@@ -10034,6 +10047,7 @@
1003410047
function handle_typing(event) {
1003510048
var event = event || window.event;
1003610049
var charCode = event.keyCode || event.which;
10050+
warn_on_quit = true;
1003710051

1003810052
if (!event.shiftKey && (charCode == 13||(charCode == 10 && event.ctrlKey))) {
1003910053
let willsubmit = (document.getElementById("entersubmit").checked ? true : false);
@@ -10567,8 +10581,9 @@
1056710581
}
1056810582
}
1056910583

10570-
function submit_generation() {
10571-
10584+
function submit_generation()
10585+
{
10586+
warn_on_quit = true;
1057210587
let newgen = document.getElementById("input_text").value;
1057310588

1057410589
//apply regex transforms
@@ -13459,6 +13474,7 @@
1345913474
{
1346013475
const isSupported = typeof window.getSelection !== "undefined";
1346113476
if (isSupported) {
13477+
warn_on_quit = true;
1346213478
const selection = window.getSelection();
1346313479
if(selection.focusNode!=null && selection.focusNode.parentElement!=null
1346413480
&& selection.focusNode.parentElement.classList.contains("txtchunk"))
@@ -14577,6 +14593,7 @@
1457714593
{
1457814594
var event = event || window.event;
1457914595
var charCode = event.keyCode || event.which;
14596+
warn_on_quit = true;
1458014597

1458114598
if (!event.shiftKey && charCode == 13) {
1458214599
let willsubmit = (document.getElementById("entersubmit").checked ? true : false);
@@ -15056,6 +15073,7 @@
1505615073

1505715074
console.log("Clear story");
1505815075
if (!document.getElementById("btnsend").disabled && pending_response_id == "" && gametext_arr.length > 0) {
15076+
warn_on_quit = true;
1505915077
last_reply_was_empty = false;
1506015078
while(gametext_arr.length > 0)
1506115079
{
@@ -15082,6 +15100,7 @@
1508215100
}
1508315101
function btn_back() {
1508415102
if (!document.getElementById("btnsend").disabled && pending_response_id == "" && gametext_arr.length > 0) {
15103+
warn_on_quit = true;
1508515104
last_reply_was_empty = false;
1508615105
retry_preserve_last = false;
1508715106
if(retry_prev_text.length>0)
@@ -15105,6 +15124,7 @@
1510515124

1510615125
console.log("Redo All story");
1510715126
if (!document.getElementById("btnsend").disabled && pending_response_id == "" && redo_arr.length > 0) {
15127+
warn_on_quit = true;
1510815128
last_reply_was_empty = false;
1510915129
retry_preserve_last = false;
1511015130
while(redo_arr.length > 0)
@@ -15127,6 +15147,7 @@
1512715147
}
1512815148
function btn_redo() {
1512915149
if (!document.getElementById("btnsend").disabled && pending_response_id == "") {
15150+
warn_on_quit = true;
1513015151
if (redo_arr.length > 0) {
1513115152
last_reply_was_empty = false;
1513215153
retry_preserve_last = false;
@@ -15146,6 +15167,7 @@
1514615167
function btn_retry() {
1514715168
if (!document.getElementById("btnsend").disabled && pending_response_id == "" && (gametext_arr.length > 1 ||
1514815169
(gametext_arr.length > 0 && (current_memory != "" || current_anote != "")))) {
15170+
warn_on_quit = true;
1514915171
last_reply_was_empty = false;
1515015172
let boxtextstash = document.getElementById("input_text").value;
1515115173
document.getElementById("input_text").value = "";
@@ -15851,7 +15873,7 @@
1585115873

1585215874
</head>
1585315875

15854-
<body id="outerbody" class="" onkeydown="handle_escape_button(event)">
15876+
<body id="outerbody" class="" onkeydown="handle_escape_button(event)" onbeforeunload="return handle_quit()">
1585515877

1585615878
<div id="maincontainer" class="adaptivecontainer maincontainer">
1585715879
<div id="outerbodybg"></div>

0 commit comments

Comments
 (0)