scripture-viewer/BibleServerCli/data/www/printable/index.html

181 lines
6.5 KiB
HTML
Raw Normal View History

2023-11-11 15:20:14 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scripture Viewer</title>
<link rel="stylesheet" href="./bulma.min.css" media="only screen">
<link rel="stylesheet" href="./print.css">
</head>
<body>
<div class="screen-only">
2023-11-11 16:20:58 +00:00
<textarea id="text" class="textarea" placeholder="Place your bible, book, chapter or verse urls here"></textarea>
2023-11-11 15:20:14 +00:00
<button id="btn" class="button is-primary">Print</button>
2023-11-11 16:20:58 +00:00
<button class="button" onclick="show_modal()">Add</button>
<p>NOTE: Print in context menu does not work, use either the Print button on the page, CTRL+P or Command+P</p>
<div id="add_modal" class="modal">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Add a bible, book, chapter or verse<br>Use the x or Cancel<br> when adding single verses</p>
<button class="delete" onclick="modalClose()" aria-label="close"></button>
</header>
<section class="modal-card-body">
<iframe src="./" id="iframe" frameborder="0"></iframe>
</section>
<footer class="modal-card-foot">
<button onclick="modalAdd()" class="button is-success">Add</button>
<button onclick="modalClose()" class="button">Cancel</button>
</footer>
</div>
</div>
2023-11-11 15:20:14 +00:00
</div>
<h1 id="title" class="print-only"></h1>
<ul id="verses" class="print-only">
</ul>
<script>
2023-11-11 16:20:58 +00:00
const add_modal = document.getElementById('add_modal');
const iframe = document.getElementById('iframe');
2023-11-11 15:20:14 +00:00
const title = document.getElementById('title');
title.innerText = `Created on ${window.location.href}`;
const text=document.getElementById('text');
2023-11-11 16:20:58 +00:00
const btn = document.getElementById('btn');
2023-11-11 15:20:14 +00:00
const verses = document.getElementById('verses');
btn.onclick = async(e)=>{
await BeforePrint();
2023-11-11 16:20:58 +00:00
2023-11-11 15:20:14 +00:00
window.print();
2023-11-11 16:20:58 +00:00
2023-11-11 15:20:14 +00:00
};
2023-11-11 16:20:58 +00:00
2023-11-11 15:20:14 +00:00
async function GetVerses(bible,book,chapter)
{
if(chapter === -1) return await GetBook(bible,book);
var res=await fetch(`./api/v1/GetVerses?bible=${encodeURIComponent(bible)}&book=${encodeURIComponent(book)}&chapter=${chapter}`);
return await res.json();
}
async function GetVerse(bible,book,chapter,verse)
{
if(verse === -1) return await GetVerses(bible,book,chapter);
var res=await fetch(`./api/v1/GetVerse?bible=${encodeURIComponent(bible)}&book=${encodeURIComponent(book)}&chapter=${chapter}&verse=${verse}`);
return [await res.json()];
}
async function GetBook(bible,book)
{
if(book === '') return GetBible(bible);
var res=await fetch(`./api/v1/GetChapterCount?bible=${encodeURIComponent(bible)}&book=${encodeURIComponent(book)}`);
var json = await res.json();
var list=[];
for(i = 0; i< json;i++)
{
list=list.concat(await GetVerses(bible,book,i+1));
}
return list;
}
async function GetBible(bible)
{
if(bible === '') return [];
var res=await fetch(`./api/v1/GetBooks?bible=${encodeURIComponent(bible)}`);
var json = await res.json();
var list=[];
for(const book of json.Books)
{
list=list.concat(await GetBook(bible,book));
}
return list;
}
async function BeforePrint()
{
2023-11-11 16:20:58 +00:00
2023-11-11 15:20:14 +00:00
verses.innerHTML="";
for(const line of text.value.split(/\r\n|\r|\n/g))
{
try{
var url=new URL(line);
var bible=url.searchParams.get("bible") ?? '';
var book = url.searchParams.get('book') ?? '';
var chapter = parseInt(url.searchParams.get('chapter') ?? '-1');
var verse = url.hash.replace('#verse-','');
var verseNo = parseInt(verse === '' ? '-1' : verse);
for(const verse of await GetVerse(bible,book,chapter,verseNo))
{
console.dir(verse);
var d=document.createElement('li');
var hdr=document.createElement('h3');
hdr.innerText = verse.reference;
d.appendChild(hdr);
var p = document.createElement('p');
p.innerText = verse.text;
d.appendChild(p);
d.appendChild(document.createElement('br'));
verses.appendChild(d);
}
}catch(ex)
{
}
}
2023-11-11 16:20:58 +00:00
}
function addurl(e)
{
if(!e.includes('?'))
{
alert("Must be bible, book, chapter or verse");
return;
2023-11-11 15:20:14 +00:00
}
2023-11-11 16:20:58 +00:00
var l = "";
for(const line of text.value.split(/\r\n|\r|\n/g))
{
if(line.length > 0)
l += `${line}\n`;
}
l += `${e}`;
text.value = l;
2023-11-11 15:20:14 +00:00
}
2023-11-11 16:20:58 +00:00
function show_modal()
{
iframe.contentWindow.location.href = './';
iframe.onload = ()=>{
iframe.contentWindow.addVerse = (e)=>{
addurl(e);
};
};
add_modal.classList.add('is-active');
}
function modalClose()
{
add_modal.classList.remove('is-active');
}
function modalAdd()
{
addurl(iframe.contentWindow.location.href);
add_modal.classList.remove('is-active');
}
window.onkeydown = async function(e){
if(e.ctrlKey && e.keyCode == 'P'.charCodeAt(0)){
e.preventDefault();
//your printing code
await BeforePrint();
window.print();
}
}
2023-11-11 15:20:14 +00:00
</script>
</body>
</html>