Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > Kobo Reader

Notices

Reply
 
Thread Tools Search this Thread
Old 08-10-2025, 06:16 PM   #1
LPolder
Junior Member
LPolder began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Aug 2025
Device: Kobo Libra 2
kepub - running Javascript

Hi all,
I want to run the following script in my page, but it crashes because kobo sees the "<" sign as the start of a tag (i think)

Quote:
<script type="text/javascript">
function updateTimeText() {
const now = new Date();
const hour = now.getHours();
let greeting;

if (hour < 12) {
greeting = "Good morning!";
} else if (hour < 18) {
greeting = "Good afternoon!";
} else {
greeting = "Good night!";
}
document.getElementById("weathertime").textContent = greeting + " it is now " + now.toLocaleTimeString();
}
</script>
It does not seem to replace the text on my page with the correct greeting and time, what am i doing wrong? Adding the //<![CDATA[ tags doesn't seem to change anything.

it does work on an ereader in my browser
LPolder is offline   Reply With Quote
Old 08-11-2025, 12:59 PM   #2
neclepsio
Member
neclepsio began at the beginning.
 
Posts: 18
Karma: 10
Join Date: Oct 2024
Device: Kobo Libra Colour
"Kobo’s eInk and Desktop platforms have limited support for JavaScript, and do not support interactive JavaScript elements." (https://github.com/kobolabs/epub-spe...script-support)

I think what you are trying to do is simply not supported, especially if you call updateTimeText using an interactive element.
neclepsio is offline   Reply With Quote
Advert
Old 08-11-2025, 01:28 PM   #3
LPolder
Junior Member
LPolder began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Aug 2025
Device: Kobo Libra 2
I am not calling the function using an interactive element, but am calling it later in the script. I did the same with the following function, and that one works:
Quote:
function rollDice(){return Math.floor(6*Math.random())+1};
I agree that the JS support is limited, but I'm just trying to figure out how limited exactly, and how to escape the "<" sign
LPolder is offline   Reply With Quote
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
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript serrafa Sigil 2 12-22-2023 09:02 AM
Running calibre.exe --shutdown-running-calibre does *NOT* terminate the E-book Viewer MReader67 Calibre 4 06-12-2023 01:53 PM
How to get Calibre 3 running on Raspberry Pi 3 running Raspbian Jessie? fivestones Calibre 6 01-25-2018 09:41 PM
Creating epub/kepub books (docx→epub/kepub via MS Word→Calibre) SJC-Caron ePub 18 04-21-2016 11:10 AM
Is there a way to import kepub to calibre/convert a kepub to other formats? Major General Library Management 9 04-08-2014 10:00 PM


All times are GMT -4. The time now is 09:23 AM.


MobileRead.com is a privately owned, operated and funded community.