View Single Post
Old 03-19-2015, 03:22 AM   #25
EbokJunkie
Addict
EbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blue
 
Posts: 230
Karma: 13495
Join Date: Feb 2009
Location: SoCal
Device: Kindle 3, Kindle PW, Pocketbook 301+, Pocketbook Touch, Sony 950, 350
The following script (based on Kovid's suggestion of testing chapter title presence on screen) works as expected in command line:
Code:
<script>
function IsChapter(){
	chapter = document.getElementsByClassName(\"h2a\");
	var nc = chapter.length; 
	while(nc--){
	    var br = chapter[nc].getBoundingClientRect();
	    var on_current_page = br.left + 20 > window.pageXOffset && br.right - 20 < window.pageXOffset + window.innerWidth; 
	    if (on_current_page==true) {
		document.getElementById(\"header\").style.display = \"none\";
	    }
        }
}
IsChapter()
</script>
In my example html class name for all chapter titles was "h2a".
User must dig out and substitute book specific class name for "h2a".
Header template id name must be "header".

Example of simple header template combined with javascript code (valid for CLI):

Code:
   --pdf-header-template "<div id="header" style="font-size:x-small"><p style="text-align:right"><span class="even_page">_AUTHOR_</span><span class="odd_page"><i>_TITLE_</i></span></p></div><script>function IsChapter(){chapter = document.getElementsByClassName(\"h2a\");var nc = chapter.length; while(nc--){    var br = chapter[nc].getBoundingClientRect();var on_current_page = br.left + 20 > window.pageXOffset && br.right - 20 < window.pageXOffset + window.innerWidth; if (on_current_page==true) {document.getElementById(\"header\").style.display = \"none\";}}}IsChapter();</script>"

Last edited by EbokJunkie; 03-19-2015 at 02:08 PM.
EbokJunkie is offline   Reply With Quote