Event for checking if new page is opened

I’m building a plugin for password protecting and encrypting Logseq files in place. The docs are pretty limited, but I guess that’s to be expected as the tool’s still developing.

I have two questions, actually. One, how could my plugin be notified when a new file is opened - so that I could decrypt it? Similarly, how can I be notified when it’s closed to encrypt it?

Even better, is there a way to just replace the test of the editor without saving the document on file immediately?

Question 2: how could I store settings for the document and the user? For example, at a document level, I need to store whether to encrypt this file or not, and at a user level, I need to store the user’s password.