1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
var observer,elementosNaPagina=[];let ref_cap_busca={};window.onload=e=>{let t=new Audio("https://js.livro.online/moan-quarto/Interruptor.mp3"),n=metadados.livroUrl,a=["#fff","antiquewhite","url('https://js.livro.online/moan-quarto/olga-thelavart-HZm2XR0whdw-unsplash_P.jpg')","url('https://js.livro.online/moan-quarto/paper-g5d2cae661_1280_Pixabay_user_geralt.jpg')"],o=0,r=document.querySelector("body"),l=document.getElementById("quarto-content"),i=document.querySelector(".page-navigation"),s=document.getElementById("quarto-sidebar"),c=document.getElementById("quarto-margin-sidebar"),p=document.querySelectorAll(".sidebar-item-container"),d=document.querySelectorAll("span.chapter-number"),m=document.getElementById("toc-title"),f=document.querySelector(".quarto-navbar-tools"),g=!1,u=document.querySelector("#papel"),h=document.querySelector("main");var y=document.createElement("div");function v(e,t){let n=document.createElement("button"),a=document.createElement("img");return a.src=e,n.appendChild(a),n.addEventListener("click",function(){t()}),n}y.id="moan-menu-texto";let $=document.querySelector("header"),E=window.getComputedStyle(u,null).getPropertyValue("font-size"),C=E.split("p"),b=C[0];function L(){let e=localStorage.getItem("livro.online@"+n+".config"),t=localStorage.getItem("quarto-color-scheme"),r=!1;r="default"!=t;let l=JSON.parse(e);e&&(l[0]&&G(l[0]),l[1]&&(o=l[1],u.style.background=a[l[1]],g&&!r&&i&&(i.style.background=a[l[1]]),r&&u.style.removeProperty("background")),l[2]&&(g=l[2])&&!r&&Q())}function q(e,t){let a=localStorage.getItem("livro.online@"+n+".config");if(a){let o=JSON.parse(a),r;switch(e){case"fonte":o[0]=t,r=JSON.stringify(o),localStorage.setItem("livro.online@"+n+".config",r);break;case"papel":o[1]=t,r=JSON.stringify(o),localStorage.setItem("livro.online@"+n+".config",r);break;case"luz_apagada":o[2]=t,r=JSON.stringify(o),localStorage.setItem("livro.online@"+n+".config",r)}}else{let l=[],i;switch(e){case"fonte":l[0]=t,i=JSON.stringify(l),localStorage.setItem("livro.online@"+n+".config",i);break;case"papel":l[1]=t,i=JSON.stringify(l),localStorage.setItem("livro.online@"+n+".config",i);break;case"fundo":l[2]=t,i=JSON.stringify(l),localStorage.setItem("livro.online@"+n+".config",i)}}}L();let z=document.createElement("script");z.src="https://js.livro.online/bibliotecas_de_terceiros/qrcode.min.js",document.body.appendChild(z);let S=document.createElement("div");S.id="modal",S.className="modal",S.style.display="none";let k=document.createElement("div");k.className="modal-content";let I=document.createElement("span");I.className="close",I.innerHTML="×",I.style.fontSize="20px";let x=document.createElement("div"),_=document.createElement("p");_.innerHTML="<strong>Refer\xeancia</strong>";let P=document.createElement("span");P.id="ref",x.appendChild(_),x.appendChild(P);let N=document.createElement("div"),j=document.createElement("p");j.innerHTML="<strong>Link</strong>";let w=document.createElement("span");w.id="link",N.appendChild(j),N.appendChild(w);let R=document.createElement("p");R.innerHTML="<strong>QR Code</strong>";let H=document.createElement("div");H.id="qrcode_container";let M=document.createElement("div"),A=document.createElement("p");A.innerHTML="<strong>Como Citar</strong>";let T=document.createElement("span");T.innerHTML="Veja <a href='/index.html#como-citar'>aqui</a> como citar este livro.",M.appendChild(A),M.appendChild(T);let V=document.createElement("div"),B=document.createElement("p");B.innerHTML="<strong>Vers\xe3o Impressa</strong>";let D=document.createElement("span");function F(){let e=window.getComputedStyle(y,null).getPropertyValue("font-size"),t=window.getComputedStyle($,null).getPropertyValue("font-size"),n=parseInt(window.getComputedStyle(u,null).getPropertyValue("font-size").split("p")[0])-2;u.style.fontSize=`${n}px`,y.style.fontSize=e,$.style.fontSize=t,q("fonte",n)}function G(e){let t=window.getComputedStyle(y,null).getPropertyValue("font-size"),n=window.getComputedStyle($,null).getPropertyValue("font-size");if(void 0!==e)u.style.fontSize=`${e}px`,y.style.fontSize=t,$.style.fontSize=n;else{let a=parseInt(window.getComputedStyle(u,null).getPropertyValue("font-size").split("p")[0])+2;u.style.fontSize=`${a}px`,y.style.fontSize=t,$.style.fontSize=n,q("fonte",a)}}function U(){u.style.fontSize=b+"px",q("fonte",b)}function O(){if(r.classList.contains("quarto-dark")){alert("Voc\xea precisa desabilitar o modo escuro para poder alterar o papel.");return}(o+=1)>a.length-1&&(o=0),u.style.background=a[o],q("papel",o),g&&i&&(i.style.background=a[o])}function J(){l.classList.remove("luz_apagada"),i&&i.style.removeProperty("background"),s.style.removeProperty("color"),s.classList.remove("luz_apagada"),p.forEach(e=>{e.style.removeProperty("color")}),d.forEach(e=>{"H1"===e.parentNode.nodeName.toUpperCase()||e.parentNode.classList.contains("nav-page-text")||e.style.removeProperty("color")}),c.style.removeProperty("color"),m&&m.style.removeProperty("color"),g=!1}function Q(){l.classList.add("luz_apagada"),i&&(i.style.backgroundColor=a[o]),u.style.background=a[o],s.style.color="#fff",s.classList.add("luz_apagada"),p.forEach(e=>{e.style.color="#fff"}),d.forEach(e=>{"H1"===e.parentNode.nodeName.toUpperCase()||e.parentNode.classList.contains("nav-page-text")||(e.style.color="#fff")}),c.style.color="#fff",m&&(m.style.color="#fff"),g=!0}function X(){if(r.classList.contains("quarto-dark")){alert("Voc\xea precisa desabilitar o modo escuro para o estado da luz de fundo.");return}g?(u.style.background=a[o],t.play(),J(),q("luz_apagada",!1)):(u.style.background=a[o],t.play(),Q(),q("luz_apagada",!0))}D.innerHTML="Veja <a href='/index.html#vers\xe3o-impressa'>aqui</a> onde comprar.",V.appendChild(B),V.appendChild(D),k.appendChild(I),k.appendChild(x),k.appendChild(N),k.appendChild(R),k.appendChild(H),k.appendChild(M),k.appendChild(V),S.appendChild(k),document.body.appendChild(S),y.appendChild(v("https://js.livro.online/moan-quarto/text_decrease_FILL0_wght400_GRAD0_opsz24.svg",F)),y.appendChild(v("https://js.livro.online/moan-quarto/text_increase_FILL0_wght400_GRAD0_opsz24.svg",G)),y.appendChild(v("https://js.livro.online/moan-quarto/format_clear_FILL0_wght400_GRAD0_opsz24.svg",U)),y.appendChild(v("https://js.livro.online/moan-quarto/note_FILL0_wght400_GRAD0_opsz24.svg",O)),y.appendChild(v("https://js.livro.online/moan-quarto/emoji_objects_FILL0_wght400_GRAD0_opsz24.svg",X)),h.insertBefore(y,h.firstChild);let Z={attributes:!0,attributeFilter:["class"]};function K(e,t){for(let n of e)"attributes"===n.type&&"class"===n.attributeName&&(r.classList.contains("quarto-dark")?(J(),u.style.removeProperty("background")):L())}let W=new MutationObserver(K);W.observe(r,Z);var Y=document.createElement("div");Y.className="referencias_capitulo";var ee=document.createElement("div");ee.className="cont_ref";var et=document.createElement("span");et.id="Paginacao",ee.appendChild(et),Y.appendChild(ee);var en=document.createElement("input");en.id="busca_ref",en.className="buscar_ref",en.setAttribute("placeholder","Refer\xeancia..."),en.style.backgroundImage='url("https://js.livro.online/moan-quarto/search_FILL0_wght400_GRAD0_opsz24.svg")',en.style.backgroundRepeat="no-repeat",en.style.backgroundPosition="5px center",en.style.paddingLeft="25px",Y.appendChild(en);let ea=document.createElement("button");ea.className="pegarLink";let eo=document.createElement("span");eo.style.display="flex",eo.style.flexDirection="column",eo.style.alignItems="center";let er=document.createElement("img");er.src="https://js.livro.online/moan-quarto/link_FILL0_wght400_GRAD0_opsz24.svg",eo.appendChild(er);let el=document.createTextNode("link");eo.appendChild(el),ea.appendChild(eo),Y.appendChild(ea),ea.addEventListener("click",e$),document.body.appendChild(Y);let ei=document.getElementById("busca_ref");if(f){var es=document.createElement("a");es.className="quarto-navigation-tool px-1",es.href="https://editora.livro.online",es.title="Editora Moan";var ec=document.createElement("img");ec.src="https://js.livro.online/moan-quarto/LogoRegistroALTII_min.png",ec.alt="Editora",es.appendChild(ec);var ep=document.createElement("a");ep.className="quarto-navigation-tool px-1",ep.href="https://livro.online/livros",ep.title="Mais livros gratuitos...";var ed=document.createElement("img");ed.src="https://js.livro.online/moan-quarto/import_contacts_FILL0_wght400_GRAD0_opsz24.svg",ed.alt="Livros",ed.width=28,ed.height=28,ep.appendChild(ed),f.insertBefore(ep,f.firstChild),f.insertBefore(es,f.firstChild)}function em(e){let t=e.length,n=0,a=new Promise(a=>{0===t&&a("lista vazia"),e.forEach(e=>{n++,e.isIntersecting&&elementosNaPagina.push(e),n===t&&0!=elementosNaPagina.length&&a("lista pronta")})}),o=new Promise(e=>{e(elementosNaPagina.sort(function(e,t){let n=e.target.id.split("P"),a=t.target.id.split("P");return parseInt(n[1])<parseInt(a[1])?-1:parseInt(n[1])>parseInt(a[1])?1:void 0}))});a.then(e=>{"lista pronta"===e?o.then(e=>{let t=e.length-1;e[0].target.id===e[t].target.id?et.innerHTML=`<span id='PaginacaoInicio'>${e[0].target.id}</span>`:et.innerHTML=`<span id='PaginacaoInicio'>${e[0].target.id}</span> a <span id='PaginacaoFim'> ${e[t].target.id}</span>`}).catch(e=>console.log("Erro na lista: "+e)):"lista vazia"===e&&(console.log("N\xe3o tenho Unidade"),et.innerHTML="...")}).catch(e=>console.log("Erro: "+e))}window.addEventListener("scroll",()=>{elementosNaPagina=[],eg(),console.log("Observador ativado")});let ef={root:null,rootMargin:"0px",threshold:.01,delay:1e3,trackVisibility:!0};function eg(){observer&&observer.disconnect();var e=Array.from(u.querySelectorAll(".unidade"));0!==e.length&&(observer=new IntersectionObserver(em,ef),e.map(e=>observer.observe(e)))}function eu(e){return e.replace(/[&<>"']/g,"")}function eh(){let e=eu(ei.value),t=e.toUpperCase(),n=t.split("P"),a=n[0],o=ref_cap_busca[a];if(!o){console.log("Refer\xeancia n\xe3o encontrada"),alert("Refer\xeancia que come\xe7a com "+a+" \xe9 inv\xe1lida neste livro.");return}window.location.href="/"+o+"#"+t}function ey(e,t){document.getElementById("ref").textContent=e,document.getElementById("link").textContent=t;let n=document.getElementById("modal");n.style.display="block";let a=document.getElementById("qrcode_container");a.innerHTML="";let o=t.match(/:\/\/([^/]+)\/(.+)/),r=o[2];console.log("Verificando: "+r),r="https://livro.online/qr-code/?livro="+(r=(r=r.replace(/\//g,"--")).replace(/#/g,"__")),new QRCode(a,{text:r,colorDark:"#000000",colorLight:"#ffffff",correctLevel:QRCode.CorrectLevel.H})}function ev(e){let t=0;for(;t<10;t++){if(e&&(e.classList.contains("unidade")||e.classList.contains("unidade_silenciosa")))return e.id;e=e.parentElement?e.parentElement:e}}function e$(){let e;if(window.getSelection?e=window.getSelection():document.selection&&(e=document.selection.createRange()),""===e.toString()){alert("Selecione um texto primeiro...");return}let t=window.getSelection().anchorNode.parentElement,n=window.getSelection().focusNode.parentElement;if(t&&n){let a=ev(t),o=ev(n),r=window.location.href,l=new URL(r);l.search="",l.hash="";let i=l.href;if(a===o){let s=`${i}${a?"#"+a:""}`,c=a;c&&""!==c.trim()?P.style.fontSize="30px":(c="Elemento sem refer\xeancia direta",P.style.fontSize="14px"),ey(c,s)}else if(a<o){let p=`${i}${a?"#"+a:"#"+o}`,d=a;d&&""!==d.trim()?P.style.fontSize="30px":(d="Elemento sem refer\xeancia direta",P.style.fontSize="14px"),ey(d,p)}else{let m=`${i}${o?"#"+o:"#"+a}`,f=o;f&&""!==f.trim()?P.style.fontSize="30px":(f="Elemento sem refer\xeancia direta",P.style.fontSize="14px"),ey(f,m)}}}eg(),ei.addEventListener("focus",()=>{fetch("ref_capitulos.json").then(e=>{if(!e.ok)throw Error("N\xe3o foi poss\xedvel carregar o arquivo JSON.");return e.json()}).then(e=>{console.log(e),ref_cap_busca=e}).catch(e=>{console.error(e)})}),ei.addEventListener("keydown",e=>{("Enter"===e.key||13===e.keyCode)&&(e.preventDefault(),eh())}),document.querySelector(".close").addEventListener("click",function(){let e=document.getElementById("modal");e.style.display="none"});let eE=/Ainda não disponível/i;fetch("/postos-de-venda.json").then(e=>e.json()).then(e=>{if(!eE.test(Object.keys(e)[0])){let t=document.createElement("div");t.className="versao-impressa-compre";let n=document.createElement("h2");n.textContent="Est\xe1 gostando?",t.appendChild(n);let a=document.createElement("span");a.textContent="Considere ajudar, comprando uma c\xf3pia f\xedsica deste livro.",t.appendChild(a);let o=document.createElement("ul"),r=/não disponível/i;for(let l in e)if(!r.test(l)){let i=document.createElement("li"),s=document.createElement("a");s.href=e[l],s.textContent=l,i.appendChild(s),o.appendChild(i)}t.appendChild(o),c.appendChild(t)}}).catch(e=>{console.error("Erro ao carregar o arquivo postos-de-venda.json:",e)})}; |