moan-quarto/leitor-web.min.js

1 line
12 KiB
JavaScript

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