Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/bin/cyoa/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Restart the story by clearing session storage and reloading page
function restartStory() {

try {
const key = "Saved Session"; // found in browser storage
sessionStorage.removeItem(key);
} catch (err) {
console.warn("Could not clear Harlowe session storage:", err);
}
location.reload();

}
//
// allow iterating through passage links with space and selecting with enter
document.body.onkeydown = function(e) {
if (e.key == " " ||
Expand All @@ -7,6 +20,13 @@ document.body.onkeydown = function(e) {
e.preventDefault();

const links = Array.from(document.querySelectorAll("tw-link"));

// Reached the end, so restart
if(links.length === 0) {
restartStory();
return;
}

const selected = document.querySelector(":focus") || links[0];

const ix = links.indexOf(selected);
Expand All @@ -17,13 +37,6 @@ document.body.onkeydown = function(e) {

// handle "r" for restart
if (e.key === "r" || e.key === "R") {
e.preventDefault();
try {
const key = "Saved Session"; // found in browser storage
sessionStorage.removeItem(key);
} catch (err) {
console.warn("Could not clear Harlowe session storage:", err);
}
location.reload();
restartStory();
}
}