Help! Conditional handling for "prevent edit" plugin?

Dear javascript folks, and perhaps @linonetwo in particular:

My “customers” (students) really should NOT see a “Do you really want to close/leave???” warning. They’re not editing, and there’s nothing for them to save, so it’s distracting.

I happily installed the prevent-edit plugin to solve this problem. The core of the thing is super-simple (though the plugin has readme and other plugin stuff):

exports.startup = function() {
  $tw.unloadTasks = $tw.unloadTasks.filter(task => !task.toString().includes('confirmationMessage'));
}

Recently I’ve gotten burned a few times in a row; I’ve lost serious author-mode work because of completely accidental tab-closures (errant key-strokes, mouse-clicks that land “behind” where I think I’m clicking, etc.).

So, javascript-savvy folks: How do I hack prevent-edit so that it CHECKS whether the wiki is in read-only mode, and prevents the alert ONLY IF wiki is in read-only mode?

In other words, I want to KEEP the alert (preventing accidental closure with unsaved work), just when:

  • $:/config/utility/IsReaderMode has value no
  • Or: $:/status/IsLoggedIn has value yes would be equivalent for me, in practice.

Many thanks in advance!

I will try to look in whatever spare time I can squeeze out during municipal and school budget season. But first, two questions:

  • Do you view the wiki in the same manner the students do? Or are there differences, such as between them seeing it over the web versus you viewing and editing from the file system?

  • Is readerMode static for a session or do you have a way to toggle it on and off in a running wiki?

1 Like

It’s all TiddlyHost. (I dwell in TiddlyHost. Long live TiddlyHost!)

So I’m logged in when I edit (which is one of the cues that disactivates readOnly when the page loads), but everyone involved (students and I) are accessing over http:// at all times. .

When I’m in “reality-check” mode, accessing student view on a secondary browser without logging in first, I do have ways to toggle off the readOnly status for css purposes (to troubleshoot by accessing edit-mode GUI and system tiddlers that are otherwise suppressed), but I never attempt to log in “retroactively” in order to save from a session that launched as readOnly.

I believe $:/status/IsLoggedIn is set when the wiki loads, and I don’t generally change that. At any rate, I’d be plenty happy with a solution that keeps the “You might lose changes!” alert just for edit sessions that are properly initiated under the logged-in umbrella.

(When do I accidentally load the url without having logged in, I can tell immediately because there are so many visual cues, including a page-background color that differs based on whether I’m logged in. So even though I can in theory load the page in my main browser account without logging in, I never accidentally commence edits thinking that I’m logged in.)