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

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 03-03-2023, 11:09 AM   #1
salmobytes
Junior Member
salmobytes began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Apr 2022
Location: •••••••
Device: pixel3xl
javascript in epub

This is a development question.
I'm an experienced developer in other contexts, but entirely new to epub.
I'm writing a Python utility to convert my website to epub3
I am finally getting output epubs that validate with epubcheck.
Error free.

I start with HTML fragments scraped from a website.
make a recursive list of all links on all pages, as a text file in sequential order
Loop through that link list line by line and make calls to python codes using ebookLib,
that make a new epub. (epub3 fwiw)

The epub I get fails with errors if anything like:

loading="lazy" (css)
onClick="bigImage(this)" (javascript)

...remain in the HTML fragments.
I get an epub that does validate if I strip all that stuff first.

Is there a way to configure something in content.opf perhaps, so that js and css stuff would not have to be stripped? The error I get for that stuff is
ERROR(OPF-014): The property 'scripted' should be declared in the OPF file.

How would I declare it?

I don't expect javascript to work inside an epub reader. But it wold be handy if I did not have to strip it out.


Do any epub readers support any subset of javascript in the epub?
salmobytes is offline   Reply With Quote
Old 03-03-2023, 11:33 AM   #2
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 34,229
Karma: 144198474
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Forma, Clara HD, Lenovo M8 FHD, Paperwhite 4, Tolino epos
JS is supported in epub3 but not epub2. And even in epub3, only a relatively small subset is of real use. As for adding scripted in the opf file? You need to add a properties="scripted" in the appropriate places. See the example below:

Code:
<item href="Text/File_with_script.xhtml" id="File_with_script.xhtml" media-type="application/xhtml+xml" properties="scripted"/>
DNSB is offline   Reply With Quote
Advert
Old 03-03-2023, 04:24 PM   #3
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,527
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by salmobytes View Post
Is there a way to configure something in content.opf perhaps, so that js and css stuff would not have to be stripped? The error I get for that stuff is
ERROR(OPF-014): The property 'scripted' should be declared in the OPF file.

How would I declare it?
You can do that easily by working with Sigil. Once loaded the epub3 under Sigil. put your scripts in the folder "Misc" and your .css stylesheets in the folder "Styles". After, do right click on the .xhtml files that will content your scripts and css styles and select the command "Link Stylesheets..." and "Link Javascripts...". Sigil itself will write all the neccessary things in the .opf file.
On the other hand, also you can select the command "Tools/Epub3 Tools/Update Manifiest Properties" and all the changes will be made on the .opf file.


Quote:
I don't expect javascript to work inside an epub reader. But it wold be handy if I did not have to strip it out.
In fact, the javascripts will work nice inside an epub3. All ereaders I know that suppor epub3, they support javascript. And with it you can do practically anything: creating, deleting, hiding, showing paragraphs, modifying styles, changing css rules, etc., etc., etc.

Quote:
Do any epub readers support any subset of javascript in the epub?
ADE 4.5x, Thorium (for Linux and Windows), Koodo Reader (for Linux and Windows), Foliate (Linux), Sigil and its plugins Readium, Bibi Reader and EpubJS Reader, Calibre Viewer and Calibre Editor, EpubReader (for Chrome and Firefox), ePUB Reader (for Chrome and Firefox), PocketBook, Gitden Reader, Reasily, Lithium, Aldiko Next, Overdrive, Bluefire Reader, BookFusion, Infinity Reader (all Android apps). All this programs and apps support javascript practically "in totum".
RbnJrg is offline   Reply With Quote
Old 03-04-2023, 05:17 AM   #4
Quoth
the rook, bossing Never.
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 10,649
Karma: 83693763
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper11
I know some people are fans of epub3, evangelists for it, but:
1) Only a subset of Javascript works on epub3.
2) Only a tiny number of apps fully support epub3
3) The majority of physical ereaders have very little or no epub3 support.
4) The majority of physical ereaders (inc Kindle) have little or no javascript support
5) A real ebook doesn't need any Javascript shouldn't use any.
6) Javascript execution creates a possible malware vector.

Quote:
ADE 4.5x, Thorium (for Linux and Windows), Koodo Reader (for Linux and Windows), Foliate (Linux), Sigil and its plugins Readium, Bibi Reader and EpubJS Reader, Calibre Viewer and Calibre Editor, EpubReader (for Chrome and Firefox), ePUB Reader (for Chrome and Firefox), PocketBook, Gitden Reader, Reasily, Lithium, Aldiko Next, Overdrive, Bluefire Reader, BookFusion, Infinity Reader (all Android apps). All this programs and apps support javascript practically "in totum".
Some of these are used by a minority of people reading.

If you really need interactive (the reason for Javascript) consider a framework to produce iOS and Android apps. This of course can't sell via the ebook stores that sell about 99% of ebooks, but most of those won't distribute ebooks with Javascript (Amazon).

I've Aldiko, Bluefire, Lithum and Pocket Book on Android. I've about 500 bought ebooks (since 2013 and from four stores) and about 5,000 PD ebooks (since about 2002). Not a single ebook has Javascript. Not a single ebook was delivered or downloaded in epub3.

Last edited by Quoth; 03-04-2023 at 05:22 AM.
Quoth is offline   Reply With Quote
Old 03-04-2023, 09:25 AM   #5
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,527
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by Quoth View Post
I know some people are fans of epub3, evangelists for it, but:
1) Only a subset of Javascript works on epub3.
How do you know that if you never used javascript?

Quote:
2) Only a tiny number of apps fully support epub3
That's not true. All apps and programs that support epub3, they support javascript.

Quote:
3) The majority of physical ereaders have very little or no epub3 support.
They are not readers for epub3 and here we are speaking about epub3. But are you saying, for example, that tablets based on e-ink, where you can load any android app that support epub3 (for example, PocketBook, Reasily, Gitden Reader, Aldiko Next, Lithium, BlueFire -an extraordinary app-, etc., etc.) are not physical ereaders? You are living only in the world of Kindle and Kobo but there is live beyond them.

Quote:
4) The majority of physical ereaders (inc Kindle) have little or no javascript support.
As I said, here we are speaking about epub3. Read my previous answer.

Quote:
5) A real ebook doesn't need any Javascript shouldn't use any.
As you don't know anything about epub3 and javascript. then you shouldn't speak about what you don't know. Try to get the following layout with an epub2:

Click image for larger version

Name:	Poetry.png
Views:	162
Size:	89.6 KB
ID:	200085

with a bigger font-size:

Click image for larger version

Name:	Poetry2.png
Views:	128
Size:	57.8 KB
ID:	200093

You won't be able. And no matter the user change the font-size, the layout is maintained by the script. Below anyone can check the respective epub3 with the respective script to get that layout. The possibilities of epub2 to work with poetry are very poor compared with epub3 plus javascript.

Poetry Test.epub

And try to get with an epub2 the following animations usefull in children's books:

Text Animations.epub

And watch the following .xhtml code:

Code:
<h1>TITULUS*HIC*EST</h1>

<p class="start">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ac tellus nunc. Phasellus imperdiet leo metus, et gravida lacus. Donec metus ligula, elementum at pellentesque pellentesque, suscipit ac nunc. Etiam lobortis, massa ac aliquam auctor, augue nisl sagittis urna, at dapibus tellus erat ullamcorper ligula. Praesent orci dui, pulvinar id convallis a, faucibus non mauris.</p>
How can you give that specific code the following format (under epub2)?

Click image for larger version

Name:	nthEverything.png
Views:	122
Size:	56.5 KB
ID:	200090

Under epub2, you should have to add a lot of additional code to get something similar. In the epub3 I attach below, you can see how easy is to get those effects with javascript.

nthEverything Test.epub

Of course, I'm not writting all this to try to convence you; I write this in order that anyone that is reading this thread can judge by itself if are true your statements.

Quote:
6) Javascript execution creates a possible malware vector.
You don't know what are you saying. So, vendors of epub3 won't check anything before selling a book.

Quote:
Some of these are used by a minority of people reading.
How do you know? Are you God? You are projecting your own feelings and prejudices onto the rest of the world.

Quote:
If you really need interactive (the reason for Javascript)...
This is a proof of how little you know about javascript and epub3. You think that javascript is only useful for interactive things. BIG MISTAKE. Javascript is usefull to format an ebook with a minimun of effort. to work less and give the user a better reading experience (with a richer format; watch the poetry layout).

Quote:
I've Aldiko, Bluefire, Lithum and Pocket Book on Android. I've about 500 bought ebooks (since 2013 and from four stores) and about 5,000 PD ebooks (since about 2002). Not a single ebook has Javascript. Not a single ebook was delivered or downloaded in epub3.
In other words, you are the measure of all things. If something doesn't happen to you, it doesn't exist; if you don't like something, then it doesn't work. Epub2 is an obsolete format, that's the reality, and for comfort, or because you don't know how to do things any other way, you stick to it.

Again, try to get the poetry layout I uploaded with an epub2. And I have a lot of cases more than I don't want to publish here (I have my secrets) that are able to demonstrate the power of javascript. But for now what I posted is enough.

Last edited by RbnJrg; 03-04-2023 at 10:22 AM.
RbnJrg is offline   Reply With Quote
Advert
Old 03-04-2023, 10:38 AM   #6
Quoth
the rook, bossing Never.
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 10,649
Karma: 83693763
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper11
Animations are for APPS not ebooks.

And I do know about javascript.

I do know about multimedia design & websites, inc server side code. More than 20 years experience.

I know about writing apps, desktop programs and video production.

Once you add animation or interaction or video or sound, it's no longer a book. It's best done as an app and not pretending to be a book.

Poetry works fine in epub2.

Javascript is a stupid lazy way to do static layout, which is all an ebook should have.


We have different definitions of what an eBook is.

But stop being insulting just because you are an avid promoter of the epub3 spec.

The OP and title is about "javascript in epub". My point is that most ebook sales and most physical ereaders and the store apps don't have javascript. If javascript is really needed it's not a real ebook. Sure you can use epub3. Good luck on selling that with working javascript in the major selling ebook stores compared with better features in an iOS and Android app.

Last edited by Quoth; 03-04-2023 at 10:47 AM.
Quoth is offline   Reply With Quote
Old 03-04-2023, 06:37 PM   #7
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,527
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by Quoth View Post
Animations are for APPS not ebooks.
Words said by someone who knows nothing about the subject.

Quote:
And I do know about javascript.
Really? Well, you hide it very well. If you really know about javascript, then you would not think how you do. On the other hand, I know about epub2, and I can say that is an obsolete format.

Quote:
I do know about multimedia design & websites, inc server side code. More than 20 years experience.
But you know nothing about epub3 and javascript (althought you say otherwise). And here we are speaking about epub3 and javascript. On the other hand, I build ebooks from the time of the .lit format, so more than 20 years of experience. Moreover, I can asure you that I know about epub2 (epub two, not epub3) more than you.

Quote:
I know about writing apps, desktop programs and video production.
But you don't know anything about epub3 and javascript, and here we are speaking about epub3 and javascript.

Quote:
Once you add animation or interaction or video or sound, it's no longer a book. It's best done as an app and not pretending to be a book.
As I said in my previous post, epub3 and javascript is for working less and giving the user a better reading experience. Again you do the same mistake; you think that javascript in only for interaction. BIG MISTAKE.

Quote:
Poetry works fine in epub2.
Really? I don't want your words, I want FACTS. "Res, non verba". I want to see your epub2 mimicing the format of my epub3 with javascript. Please, I beg you; show us that you can imitate my epub3 layout for poetry with your epub2.

Quote:
Javascript is a stupid lazy way to do static layout, which is all an ebook should have.
Since you don't know anything about javascript and epub3, at least, you should have the humility not to comment on what you ignore.

Quote:
We have different definitions of what an eBook is.
It seems that for you an ebook is something similar to what someone can type on a typewriter.

Quote:
But stop being insulting just because you are an avid promoter of the epub3 spec.
No, no, no. I am not insulting you; just I say that you are speaking about a subject that you ignore. Instead of that, because you want to limit yourself to epub2, you also want to limit others by saying things that are not true. It's okey if you want to stick with epub2, but to do that, don't say that epub3 is bad or not usefull. With only the selectors that epub3 has, let epub2 totally obsolete. And if you add javascript to that, the possibilities are almost limitless.

Quote:
The OP and title is about "javascript in epub"
What you wrote is a proof that you don't know anything about the subject. Javascript is only for epub3, so here we are speaking about epub3 and javascript.

Quote:
If javascript is really needed it's not a real ebook.
That said by someone who know nothing about epub3 and javascript. More humility on your part please.

Stick to epub2 if you wish, but you won't be able to stop the advance of the epub3 format. Sooner rather than later you will have to dedicate time to learn about the subject that now you are boldly writing.

And please don't forget to post your epub2 that mimics the layout of my epub3 with javascript regarding poetry. I look forward to seeing that wonder.
RbnJrg is offline   Reply With Quote
Old 03-09-2023, 04:13 PM   #8
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 73,510
Karma: 126422064
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
I tried the nthEverything.epub on my Libra 2 and it did not work. It did not work in the Calibre viewer. It did work in the Calibre editor preview.
JSWolf is offline   Reply With Quote
Old 03-10-2023, 08:40 AM   #9
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,527
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by JSWolf View Post
I tried the nthEverything.epub on my Libra 2 and it did not work. It did not work in the Calibre viewer. It did work in the Calibre editor preview.
Yes, you are right. As I said, I have my secrets It's neccesary to employ some things more in order to get the effect you can get with the script and that it works everywhere. It took to me a lot of time to know how to adapt scripts for epub3 and for now, I am not going to do public the procedure for this particular case. Sorry and please, don't get it wrong.
RbnJrg 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 in ePub. Vijay ePub 22 12-28-2023 09:43 AM
Aura {A1} epub 3.0 renderer javascript support? pluma Kobo Reader 1 01-13-2017 03:53 PM
Hints for javascript in epub ? fxp33 Kobo Developer's Corner 6 08-09-2014 01:18 PM
Javascript in ePub Techno4 ePub 9 11-05-2012 12:50 PM
epub et javascript zelda_pinwheel Software 9 12-09-2010 04:56 PM


All times are GMT -4. The time now is 11:07 PM.


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