/* Scoped minimal styling (override with theme CSS if desired) */
.book-viewer-box-_post_name_{ border:1px solid #e0e0e0; padding:18px; border-radius:10px; background:#fff; box-shadow:0 2px 6px rgba(0,0,0,0.05); direction:rtl; text-align:right; margin:20px 0; }
.book-viewer-box-_post_name_ .book-title{ font-size:20px; margin:0 0 10px; color:#222; }
.book-viewer-box-_post_name_ .book-meta{ list-style:none; padding:0; margin:0 0 12px; font-size:14px; color:#444; }
.book-viewer-box-_post_name_ .book-meta li{ margin:4px 0; }
.book-viewer-box-_post_name_ .book-actions{ margin:12px 0; display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.bv-btn{ display:inline-block; padding:10px 16px; border-radius:6px; text-decoration:none; color:#fff; font-weight:600; cursor:pointer; }
.bv-download{ background:#0073aa; }
.bv-read{ background:#28a745; }
.bv-archive{ background:transparent; color:#0073aa; text-decoration:underline; padding:0; font-weight:600; }
/* Responsive iframe wrapper (1:1.4 ~ good for PDF on mobile) */
.bv-iframe-wrap{ width:100%; max-width:100%; margin-top:12px; display:block; }
.bv-iframe-inner{ position:relative; padding-top:66%; /* aspect ratio */ }
.bv-iframe-inner iframe{ position:absolute; top:0; left:0; width:100%; height:100%; border:1px solid #d0d0d0; border-radius:6px; }
@media (min-width:768px){ .bv-iframe-inner{ padding-top:56%; } }
(function(){
var uniq = "_post_name_";
var readBtn = document.getElementById("bv-read-" + uniq);
var dlBtn = document.getElementById("bv-dl-" + uniq);
var wrap = document.getElementById("bv-wrap-" + uniq);
var iframe = document.getElementById("bv-iframe-" + uniq);// Robust connectivity tester: loads a tiny resource from archive.org
function testArchiveOrg(timeoutMs) {
timeoutMs = timeoutMs || 3000;
return new Promise(function(resolve){
var done = false;
var img = new Image();
var timer = setTimeout(function(){
if (!done) { done = true; resolve(false); }
}, timeoutMs);img.onload = function(){
if (!done) { done = true; clearTimeout(timer); resolve(true); }
};
img.onerror = function(){
if (!done) { done = true; clearTimeout(timer); resolve(false); }
};
// cache-buster
img.src = "https://archive.org/favicon.ico?cb=" + Date.now();
});
}// When user clicks Read -> test and load appropriate iframe (direct or proxy)
readBtn.addEventListener("click", function(e){
e.preventDefault();
// disable button to prevent double clicks
readBtn.disabled = true;
readBtn.style.opacity = "0.6";// show the wrapper immediately (so users see something is happening)
wrap.style.display = "block";testArchiveOrg(3000).then(function(isOk){
if (isOk) {
iframe.src = readBtn.getAttribute("data-direct-iframe");
// ensure download points to direct
dlBtn.href = readBtn.getAttribute("data-direct-download");
} else {
iframe.src = readBtn.getAttribute("data-proxy-iframe");
dlBtn.href = readBtn.getAttribute("data-proxy-download");
}
});
});// For download: check quickly and open direct/proxy (non-blocking)
dlBtn.addEventListener("click", function(e){
e.preventDefault();
dlBtn.disabled = true;
dlBtn.style.opacity = "0.6";// Run quick test and open the appropriate URL
testArchiveOrg(2000).then(function(isOk){
var url = isOk ? dlBtn.getAttribute("data-direct") : dlBtn.getAttribute("data-proxy");
// open in new tab
window.open(url, "_blank");
// restore button after small delay
setTimeout(function(){ dlBtn.disabled = false; dlBtn.style.opacity = ""; }, 1200);
});
});
})();