Thread: Libra 2 kepub - running Javascript
View Single Post
Old 08-11-2025, 02:58 PM   #4
LPolder
Junior Member
LPolder began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Aug 2025
Device: Kobo Libra 2
I have it working, right now it does use the
//<![CDATA[ tags and I splice the date instead of the getHours(). I also do not use toLocaleTimeString. Besides this I simplified some other stuff and took out some other function. It's almost like the epub has a timeout when stuff takes too long. But I'm happy this works and I hope this helps anyone:

Quote:
function startup() {
var dt = new Date()
var t = dt.toTimeString().slice(0, 8);
var h = t.slice(0,2);
var greeting = "Hello!";
if (h < 12){
greeting = "Good Morning!";
} else if (h< 18) {
greeting = "Good afternoon!";
} else {
greeting = "Good evening";
}
document.getElementById("greeting").textContent = greeting;
}

document.addEventListener("DOMContentLoaded", startup);

this shows a different greeting based on the system time of the ereader
LPolder is offline   Reply With Quote