Writing a value to a .js file within the resource folder

Hi All,

I would really appreciate anyone’s help with the following as I’m struggling to know if it can be done easily and how to go about it. I’m trying to create a chapters already read logger within my project.

I have an external file in Hype resources folder “readlog.js”

contents are this:

ReadLog = {
Book: 'Chap1'
}

Within my Hype project I have an onSceneLoad function:

const getData = document.querySelector('.JSData--read');
	getData.innerHTML = ReadLog.Book ;

I am able to read the values of “Book” as (“Chap1”) into a .innerHTML text field within my project.

But what I would also like to do is to update/change the values of “Book” in the “readlog.js” file.

I’m assuming that because the .js file is within the hype environment at runtime it can still be edited dynamically.

Also because I have a lot of chapters to log, I would prefer to edit a saved file within resources.

If anyone can provide an example file of writing to a .js file that would be really helpful.

If it cannot be done, what would be the best solution? local.storage or writing to .txt file or other?

Thanks

Mrk

Hype output is regular HTML5 and cannot (out of the box) write to the file system (local/remote). You can do all the things a sand boxed HTML5 applications can do and some fancy stuff a PWA allows you to do (using some JS) but I’d recommend using local storage as you want to remember what the individual user has read.

There is also an extension that helps in scoping the storage to a Hype widget, page or domain. But in many cases (specially single widget Hype-Projects it isn’t needed)

A few more methods of working with data in your resource library, but I think Max’s solution is what you want:

Thanks, MaxZieb

For the reply and the heads up. I will try to do it using localStorage.

Mark

Thanks, Daniel

Very helpful links to help me understand other methods more.

Thank you

Mark