From 5bdc8dd4a99e36f187f8897d0e2ec21140348645 Mon Sep 17 00:00:00 2001 From: Rafael Tavares Juliani Date: Thu, 1 Feb 2024 23:20:06 -0300 Subject: [PATCH] =?UTF-8?q?Ajuste=20para=20as=20refer=C3=AAncias=20dos=20m?= =?UTF-8?q?odelos=20antigos=20funcionarem=20na=20busca?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- leitor-web.js | 32 ++++++++++++++++++++++++++------ leitor-web.min.js | 2 +- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/leitor-web.js b/leitor-web.js index 75b86be..7779846 100644 --- a/leitor-web.js +++ b/leitor-web.js @@ -866,7 +866,7 @@ buscaRefInput.addEventListener('focus', () => { fetch('/'+livroUrl+'/ref_capitulos.json') .then(response => { if (!response.ok) { - throw new Error('Não foi possível carregar o arquivo JSON.'); + throw new Error('Não foi possível carregar o arquivo JSON com as referências.'); } return response.json(); // Converte a resposta em JSON }) @@ -894,13 +894,27 @@ function buscar_referencia(modelo_referencia_antigo){ let sanitized_ref = removeSpecialCharacters(ref); - const ref_maiuscula = sanitized_ref.toUpperCase(); + let ref_buscada, marcador_capitulo, urlCap; - const refArr = ref_maiuscula.split('P'); + if (modelo_referencia_antigo){ - const marcador_capitulo = refArr[0]; + ref_buscada = sanitized_ref; - const urlCap = ref_cap_busca[marcador_capitulo]; + marcador_capitulo = sanitized_ref[0]; + + urlCap = ref_cap_busca[marcador_capitulo]; + + } else { + + ref_buscada = sanitized_ref.toUpperCase(); // Transforma em maiúsculas + + const refArr = ref_buscada.split('P'); + + marcador_capitulo = refArr[0]; + + urlCap = ref_cap_busca[marcador_capitulo]; + + } if (!urlCap) { console.log('Referência não encontrada'); @@ -908,7 +922,7 @@ function buscar_referencia(modelo_referencia_antigo){ return; } - const caminho_a_seguir = '/'+livroUrl+'/' + urlCap + '#' + ref_maiuscula; + const caminho_a_seguir = '/'+livroUrl+'/' + urlCap + '#' + ref_buscada; window.location.href = caminho_a_seguir; @@ -919,7 +933,13 @@ function buscar_referencia(modelo_referencia_antigo){ buscaRefInput.addEventListener('keydown', (event) => { if (event.key === 'Enter' || event.keyCode === 13) { event.preventDefault(); // Impede que o formulário seja enviado (se aplicável) + if (typeof modelo_antigo !== 'undefined' && modelo_antigo === true) { + // A variável modelo_antigo existe e é true + modelo_referencia_antigo = true; + } + buscar_referencia(modelo_referencia_antigo); + } }); diff --git a/leitor-web.min.js b/leitor-web.min.js index 644e390..276322c 100644 --- a/leitor-web.min.js +++ b/leitor-web.min.js @@ -1 +1 @@ -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="Refer\xeancia";let P=document.createElement("span");P.id="ref",x.appendChild(_),x.appendChild(P);let N=document.createElement("div"),j=document.createElement("p");j.innerHTML="Link";let w=document.createElement("span");w.id="link",N.appendChild(j),N.appendChild(w);let R=document.createElement("p");R.innerHTML="QR Code";let H=document.createElement("div");H.id="qrcode_container";let M=document.createElement("div"),A=document.createElement("p");A.innerHTML="Como Citar";let T=document.createElement("span");T.innerHTML=`Veja aqui como citar este livro.`,M.appendChild(A),M.appendChild(T);let V=document.createElement("div"),B=document.createElement("p");B.innerHTML="Vers\xe3o Impressa";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 aqui 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: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=`${e[0].target.id}`:et.innerHTML=`${e[0].target.id} a ${e[t].target.id}`}).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(),a=t.split("P"),o=a[0],r=ref_cap_busca[o];if(!r){console.log("Refer\xeancia n\xe3o encontrada"),alert("Refer\xeancia que come\xe7a com "+o+" \xe9 inv\xe1lida neste livro.");return}window.location.href="/"+n+"/"+r+"#"+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{fetch("/"+n+"/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("/"+n+"/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)})}; \ No newline at end of file +var observer,elementosNaPagina=[];let ref_cap_busca={},modelo_referencia_antigo=!1;window.onload=e=>{const t=new Audio("https://js.livro.online/moan-quarto/Interruptor.mp3"),o=metadados.livroUrl,n=["#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')"];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"),h=document.querySelector("main");var v=document.createElement("div");function y(e,t){const o=document.createElement("button"),n=document.createElement("img");return n.src=e,o.appendChild(n),o.addEventListener("click",(function(){t()})),o}v.id="moan-menu-texto";let _=document.querySelector("header");const E=window.getComputedStyle(f,null).getPropertyValue("font-size").split("p")[0];function C(){let e=localStorage.getItem("livro.online@"+o+".config");let t=!1;t="default"!=localStorage.getItem("quarto-color-scheme");let r=JSON.parse(e);e&&(r[0]&&B(r[0]),r[1]&&(a=r[1],f.style.background=n[r[1]],g&&!t&&i&&(i.style.background=n[r[1]]),t&&f.style.removeProperty("background")),r[2]&&(g=r[2],g&&!t&&D()))}function b(e,t){let n=localStorage.getItem("livro.online@"+o+".config");if(n){let a,r=JSON.parse(n);switch(e){case"fonte":r[0]=t,a=JSON.stringify(r),localStorage.setItem("livro.online@"+o+".config",a);break;case"papel":r[1]=t,a=JSON.stringify(r),localStorage.setItem("livro.online@"+o+".config",a);break;case"luz_apagada":r[2]=t,a=JSON.stringify(r),localStorage.setItem("livro.online@"+o+".config",a)}}else{let n,a=[];switch(e){case"fonte":a[0]=t,n=JSON.stringify(a),localStorage.setItem("livro.online@"+o+".config",n);break;case"papel":a[1]=t,n=JSON.stringify(a),localStorage.setItem("livro.online@"+o+".config",n);break;case"fundo":a[2]=t,n=JSON.stringify(a),localStorage.setItem("livro.online@"+o+".config",n)}}}C();const S=document.createElement("script");S.src="https://js.livro.online/bibliotecas_de_terceiros/qrcode.min.js",document.body.appendChild(S);const w=document.createElement("div");w.id="modal",w.className="modal",w.style.display="none";const L=document.createElement("div");L.className="modal-content";const q=document.createElement("span");q.className="close",q.innerHTML="×",q.style.fontSize="20px";const I=document.createElement("div"),z=document.createElement("p");z.innerHTML="Referência";const k=document.createElement("span");k.id="ref",I.appendChild(z),I.appendChild(k);const N=document.createElement("div"),x=document.createElement("p");x.innerHTML="Link";const P=document.createElement("span");P.id="link",N.appendChild(x),N.appendChild(P);const j=document.createElement("p");j.innerHTML="QR Code";const R=document.createElement("div");R.id="qrcode_container";const H=document.createElement("div"),M=document.createElement("p");M.innerHTML="Como Citar";const A=document.createElement("span");A.innerHTML=`Veja aqui como citar este livro.`,H.appendChild(M),H.appendChild(A);const T=document.createElement("div"),V=document.createElement("p");V.innerHTML="Versão Impressa";const $=document.createElement("span");function B(e){let t=window.getComputedStyle(v,null).getPropertyValue("font-size"),o=window.getComputedStyle(_,null).getPropertyValue("font-size");if(void 0!==e)f.style.fontSize=`${e}px`,v.style.fontSize=t,_.style.fontSize=o;else{let e=window.getComputedStyle(f,null).getPropertyValue("font-size").split("p"),n=parseInt(e[0])+2;f.style.fontSize=`${n}px`,v.style.fontSize=t,_.style.fontSize=o,b("fonte",n)}}function O(){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=n[a]),f.style.background=n[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 aqui onde comprar.`,T.appendChild(V),T.appendChild($),L.appendChild(q),L.appendChild(I),L.appendChild(N),L.appendChild(j),L.appendChild(R),L.appendChild(H),L.appendChild(T),w.appendChild(L),document.body.appendChild(w),v.appendChild(y("https://js.livro.online/moan-quarto/text_decrease_FILL0_wght400_GRAD0_opsz24.svg",(function(){let e=window.getComputedStyle(v,null).getPropertyValue("font-size"),t=window.getComputedStyle(_,null).getPropertyValue("font-size"),o=window.getComputedStyle(f,null).getPropertyValue("font-size").split("p"),n=parseInt(o[0])-2;f.style.fontSize=`${n}px`,v.style.fontSize=e,_.style.fontSize=t,b("fonte",n)}))),v.appendChild(y("https://js.livro.online/moan-quarto/text_increase_FILL0_wght400_GRAD0_opsz24.svg",B)),v.appendChild(y("https://js.livro.online/moan-quarto/format_clear_FILL0_wght400_GRAD0_opsz24.svg",(function(){f.style.fontSize=E+"px",b("fonte",E)}))),v.appendChild(y("https://js.livro.online/moan-quarto/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>n.length-1&&(a=0),f.style.background=n[a],b("papel",a),g&&i&&(i.style.background=n[a]))}))),v.appendChild(y("https://js.livro.online/moan-quarto/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=n[a],t.play(),O(),b("luz_apagada",!1)):(f.style.background=n[a],t.play(),D(),b("luz_apagada",!0))}))),h.insertBefore(v,h.firstChild);new MutationObserver((function(e,t){for(const t of e)"attributes"===t.type&&"class"===t.attributeName&&(r.classList.contains("quarto-dark")?(O(),f.style.removeProperty("background")):C())})).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://js.livro.online/moan-quarto/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://js.livro.online/moan-quarto/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,o=window.getSelection().focusNode.parentElement;if(t&&o){let e=ie(t),n=ie(o),a=window.location.href;const r=new URL(a);r.search="",r.hash="";let l=r.href;if(e===n){let t=`${l}${e?"#"+e:""}`,o=e;o&&""!==o.trim()?k.style.fontSize="30px":(o="Elemento sem referência direta",k.style.fontSize="14px"),le(o,t)}else if(e{0===t&&n("lista vazia"),e.forEach((e=>{o++,e.isIntersecting&&elementosNaPagina.push(e),o===t&&0!=elementosNaPagina.length&&n("lista pronta")}))})),a=new Promise((e=>{e(elementosNaPagina.sort((function(e,t){let o=e.target.id.split("P"),n=t.target.id.split("P");return parseInt(o[1])parseInt(n[1])?1:void 0})))}));n.then((e=>{"lista pronta"===e?a.then((e=>{let t=e.length-1;e[0].target.id===e[t].target.id?G.innerHTML=`${e[0].target.id}`:G.innerHTML=`${e[0].target.id} a ${e[t].target.id}`})).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=[],re(),console.log("Observador ativado")}));let ae={root:null,rootMargin:"0px",threshold:.01,delay:1e3,trackVisibility:!0};function re(){observer&&observer.disconnect();var e=f.querySelectorAll(".unidade"),t=Array.from(e);0!==t.length&&(observer=new IntersectionObserver(ne,ae),t.map((e=>observer.observe(e))))}function le(e,t){document.getElementById("ref").textContent=e,document.getElementById("link").textContent=t;document.getElementById("modal").style.display="block";let o=document.getElementById("qrcode_container");o.innerHTML="";let n=t.match(/:\/\/([^/]+)\/(.+)/)[2];console.log("Verificando: "+n),n=n.replace(/\//g,"--"),n=n.replace(/#/g,"__"),n="https://livro.online/qr-code/?livro="+n;new QRCode(o,{text:n,colorDark:"#000000",colorLight:"#ffffff",correctLevel:QRCode.CorrectLevel.H})}function ie(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)}}re(),W.addEventListener("focus",(()=>{fetch("/"+o+"/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,n,a,r=W.value.replace(/[&<>"']/g,"");e?(t=r,n=r[0],a=ref_cap_busca[n]):(t=r.toUpperCase(),n=t.split("P")[0],a=ref_cap_busca[n]);if(!a)return console.log("Referência não encontrada"),void alert("Referência que começa com "+n+" é inválida neste livro.");const l="/"+o+"/"+a+"#"+t;window.location.href=l}(modelo_referencia_antigo))})),document.querySelector(".close").addEventListener("click",(function(){document.getElementById("modal").style.display="none"}));const se=/Ainda não disponível/i;fetch("/"+o+"/postos-de-venda.json").then((e=>e.json())).then((e=>{if(!se.test(Object.keys(e)[0])){const t=document.createElement("div");t.className="versao-impressa-compre";const o=document.createElement("h2");o.textContent="Está gostando?",t.appendChild(o);const n=document.createElement("span");n.textContent="Considere ajudar, comprando uma cópia física deste livro.",t.appendChild(n);const a=document.createElement("ul"),r=/não disponível/i;for(const t in e)if(!r.test(t)){const o=document.createElement("li"),n=document.createElement("a");n.href=e[t],n.textContent=t,o.appendChild(n),a.appendChild(o)}t.appendChild(a),c.appendChild(t)}})).catch((e=>{console.error("Erro ao carregar o arquivo postos-de-venda.json:",e)}))}; \ No newline at end of file