If this .js stores the data in the ebook, does that mean that it changes the ebook? If it is a DRMed ebook, which means it is encrypted, how are they going to accomplish this?

They are probably using html local storage. This is an html 5 feature that allows data to be stored to a database locally. It is supported by modern browsers and probably also works in some browser-based e-reader software.