|
5267 | 5267 |
|
5268 | 5268 | function save_file_button(use_existing_save=false) //for triggering an optional popup. if use save is true, assume temp obj is set
|
5269 | 5269 | {
|
| 5270 | + warn_on_quit = false; |
5270 | 5271 | const save_file = function()
|
5271 | 5272 | {
|
5272 | 5273 | if(!use_existing_save)
|
|
8294 | 8295 |
|
8295 | 8296 | const slotwrite = function()
|
8296 | 8297 | {
|
| 8298 | + warn_on_quit = false; |
8297 | 8299 | inputBox("Enter a label for this Browser Storage Slot data","Enter a label",savename,defaultsavename,()=>{
|
8298 | 8300 | let userinput = getInputBoxValue();
|
8299 | 8301 | if(userinput.trim()=="")
|
|
9846 | 9848 | regexreplace_data = [];
|
9847 | 9849 | placeholder_tags_data = [];
|
9848 | 9850 | }
|
| 9851 | + warn_on_quit = false; |
9849 | 9852 | render_gametext(save); //necessary to trigger an autosave to wipe out current story in case they exit browser after newgame.
|
9850 | 9853 | }
|
9851 | 9854 |
|
|
10015 | 10018 | }
|
10016 | 10019 | }
|
10017 | 10020 |
|
| 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 | + |
10018 | 10031 | function handle_escape_button(event)
|
10019 | 10032 | {
|
10020 | 10033 | if(is_popup_open())
|
|
10034 | 10047 | function handle_typing(event) {
|
10035 | 10048 | var event = event || window.event;
|
10036 | 10049 | var charCode = event.keyCode || event.which;
|
| 10050 | + warn_on_quit = true; |
10037 | 10051 |
|
10038 | 10052 | if (!event.shiftKey && (charCode == 13||(charCode == 10 && event.ctrlKey))) {
|
10039 | 10053 | let willsubmit = (document.getElementById("entersubmit").checked ? true : false);
|
|
10567 | 10581 | }
|
10568 | 10582 | }
|
10569 | 10583 |
|
10570 |
| - function submit_generation() { |
10571 |
| - |
| 10584 | + function submit_generation() |
| 10585 | + { |
| 10586 | + warn_on_quit = true; |
10572 | 10587 | let newgen = document.getElementById("input_text").value;
|
10573 | 10588 |
|
10574 | 10589 | //apply regex transforms
|
|
13459 | 13474 | {
|
13460 | 13475 | const isSupported = typeof window.getSelection !== "undefined";
|
13461 | 13476 | if (isSupported) {
|
| 13477 | + warn_on_quit = true; |
13462 | 13478 | const selection = window.getSelection();
|
13463 | 13479 | if(selection.focusNode!=null && selection.focusNode.parentElement!=null
|
13464 | 13480 | && selection.focusNode.parentElement.classList.contains("txtchunk"))
|
|
14577 | 14593 | {
|
14578 | 14594 | var event = event || window.event;
|
14579 | 14595 | var charCode = event.keyCode || event.which;
|
| 14596 | + warn_on_quit = true; |
14580 | 14597 |
|
14581 | 14598 | if (!event.shiftKey && charCode == 13) {
|
14582 | 14599 | let willsubmit = (document.getElementById("entersubmit").checked ? true : false);
|
|
15056 | 15073 |
|
15057 | 15074 | console.log("Clear story");
|
15058 | 15075 | if (!document.getElementById("btnsend").disabled && pending_response_id == "" && gametext_arr.length > 0) {
|
| 15076 | + warn_on_quit = true; |
15059 | 15077 | last_reply_was_empty = false;
|
15060 | 15078 | while(gametext_arr.length > 0)
|
15061 | 15079 | {
|
|
15082 | 15100 | }
|
15083 | 15101 | function btn_back() {
|
15084 | 15102 | if (!document.getElementById("btnsend").disabled && pending_response_id == "" && gametext_arr.length > 0) {
|
| 15103 | + warn_on_quit = true; |
15085 | 15104 | last_reply_was_empty = false;
|
15086 | 15105 | retry_preserve_last = false;
|
15087 | 15106 | if(retry_prev_text.length>0)
|
|
15105 | 15124 |
|
15106 | 15125 | console.log("Redo All story");
|
15107 | 15126 | if (!document.getElementById("btnsend").disabled && pending_response_id == "" && redo_arr.length > 0) {
|
| 15127 | + warn_on_quit = true; |
15108 | 15128 | last_reply_was_empty = false;
|
15109 | 15129 | retry_preserve_last = false;
|
15110 | 15130 | while(redo_arr.length > 0)
|
|
15127 | 15147 | }
|
15128 | 15148 | function btn_redo() {
|
15129 | 15149 | if (!document.getElementById("btnsend").disabled && pending_response_id == "") {
|
| 15150 | + warn_on_quit = true; |
15130 | 15151 | if (redo_arr.length > 0) {
|
15131 | 15152 | last_reply_was_empty = false;
|
15132 | 15153 | retry_preserve_last = false;
|
|
15146 | 15167 | function btn_retry() {
|
15147 | 15168 | if (!document.getElementById("btnsend").disabled && pending_response_id == "" && (gametext_arr.length > 1 ||
|
15148 | 15169 | (gametext_arr.length > 0 && (current_memory != "" || current_anote != "")))) {
|
| 15170 | + warn_on_quit = true; |
15149 | 15171 | last_reply_was_empty = false;
|
15150 | 15172 | let boxtextstash = document.getElementById("input_text").value;
|
15151 | 15173 | document.getElementById("input_text").value = "";
|
|
15851 | 15873 |
|
15852 | 15874 | </head>
|
15853 | 15875 |
|
15854 |
| -<body id="outerbody" class="" onkeydown="handle_escape_button(event)"> |
| 15876 | +<body id="outerbody" class="" onkeydown="handle_escape_button(event)" onbeforeunload="return handle_quit()"> |
15855 | 15877 |
|
15856 | 15878 | <div id="maincontainer" class="adaptivecontainer maincontainer">
|
15857 | 15879 | <div id="outerbodybg"></div>
|
|
0 commit comments