1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
var observer,elementosNaPagina=[];let ref_cap_busca={};window.onload=e=>{let t=document.querySelectorAll("#quarto-document-content .figure-caption"),n=document.getElementsByTagName("caption"),a=Array.from(n);t.forEach(e=>{let t=e.innerHTML,n=t.split(":"),a=n.shift(),o="<span class='contador-figura'>"+a+"</span>: "+n.join(" ");e.innerHTML=o}),a.forEach(e=>{let t=e.innerHTML,n=t.split(":"),a=n.shift(),o="<span class='contador-figura'>"+a+"</span>: "+n.join(" ");e.innerHTML=o});let o=new Audio("https://js.livro.online/moan-quarto/Interruptor.mp3"),l=metadados.livroUrl,r=["#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')"],i=0,s=document.querySelector("body"),c=document.getElementById("quarto-content"),p=document.querySelector(".page-navigation"),d=document.getElementById("quarto-sidebar"),f=document.getElementById("quarto-margin-sidebar"),u=document.querySelectorAll(".sidebar-item-container"),g=document.querySelectorAll("span.chapter-number"),m=document.getElementById("toc-title"),y=!1,h=document.querySelector("#papel"),v=document.querySelector("main");var $=document.createElement("div");function E(e,t){let n=document.createElement("button"),a=document.createElement("img");return a.src=e,n.appendChild(a),n.addEventListener("click",function(){t()}),n}$.id="moan-menu-texto";let b=document.querySelector("header"),L=window.getComputedStyle(h,null).getPropertyValue("font-size"),C=L.split("p"),z=C[0];function S(){let e=localStorage.getItem("livro.online@"+l+".config"),t=localStorage.getItem("quarto-color-scheme"),n=!1;n="default"!=t;let a=JSON.parse(e);e&&(a[0]&&B(a[0]),a[1]&&(i=a[1],h.style.background=r[a[1]],y&&!n&&(p.style.background=r[a[1]]),n&&h.style.removeProperty("background")),a[2]&&(y=a[2])&&!n&&G())}function k(e,t){let n=localStorage.getItem("livro.online@"+l+".config");if(n){let a=JSON.parse(n),o;switch(e){case"fonte":a[0]=t,o=JSON.stringify(a),localStorage.setItem("livro.online@"+l+".config",o);break;case"papel":a[1]=t,o=JSON.stringify(a),localStorage.setItem("livro.online@"+l+".config",o);break;case"luz_apagada":a[2]=t,o=JSON.stringify(a),localStorage.setItem("livro.online@"+l+".config",o)}}else{let r=[],i;switch(e){case"fonte":r[0]=t,i=JSON.stringify(r),localStorage.setItem("livro.online@"+l+".config",i);break;case"papel":r[1]=t,i=JSON.stringify(r),localStorage.setItem("livro.online@"+l+".config",i);break;case"fundo":r[2]=t,i=JSON.stringify(r),localStorage.setItem("livro.online@"+l+".config",i)}}}S();let q=document.createElement("script");q.src="https://js.livro.online/bibliotecas_de_terceiros/qrcode.min.js",document.body.appendChild(q);let I=document.createElement("div");I.id="modal",I.className="modal",I.style.display="none";let P=document.createElement("div");P.className="modal-content";let _=document.createElement("span");_.className="close",_.innerHTML="×",_.style.fontSize="20px";let x=document.createElement("div"),N=document.createElement("p");N.innerHTML="<strong>Refer\xeancia</strong>";let w=document.createElement("span");w.id="ref",x.appendChild(N),x.appendChild(w);let j=document.createElement("div"),H=document.createElement("p");H.innerHTML="<strong>Link</strong>";let R=document.createElement("span");R.id="link",j.appendChild(H),j.appendChild(R);let T=document.createElement("p");T.innerHTML="<strong>QR Code</strong>";let M=document.createElement("div");function A(){let e=window.getComputedStyle($,null).getPropertyValue("font-size"),t=window.getComputedStyle(b,null).getPropertyValue("font-size"),n=parseInt(window.getComputedStyle(h,null).getPropertyValue("font-size").split("p")[0])-2;h.style.fontSize=`${n}px`,$.style.fontSize=e,b.style.fontSize=t,k("fonte",n)}function B(e){let t=window.getComputedStyle($,null).getPropertyValue("font-size"),n=window.getComputedStyle(b,null).getPropertyValue("font-size");if(void 0!==e)h.style.fontSize=`${e}px`,$.style.fontSize=t,b.style.fontSize=n;else{let a=parseInt(window.getComputedStyle(h,null).getPropertyValue("font-size").split("p")[0])+2;h.style.fontSize=`${a}px`,$.style.fontSize=t,b.style.fontSize=n,k("fonte",a)}}function V(){h.style.fontSize=z+"px",k("fonte",z)}function D(){if(s.classList.contains("quarto-dark")){alert("Voc\xea precisa desabilitar o modo escuro para poder alterar o papel.");return}(i+=1)>r.length-1&&(i=0),h.style.background=r[i],k("papel",i),y&&(p.style.background=r[i])}function F(){c.classList.remove("luz_apagada"),p.style.removeProperty("background"),d.style.removeProperty("color"),d.classList.remove("luz_apagada"),u.forEach(e=>{e.style.removeProperty("color")}),g.forEach(e=>{"H1"===e.parentNode.nodeName.toUpperCase()||e.parentNode.classList.contains("nav-page-text")||e.style.removeProperty("color")}),f.style.removeProperty("color"),m&&m.style.removeProperty("color"),y=!1}function G(){c.classList.add("luz_apagada"),p.style.backgroundColor=r[i],h.style.background=r[i],d.style.color="#fff",d.classList.add("luz_apagada"),u.forEach(e=>{e.style.color="#fff"}),g.forEach(e=>{"H1"===e.parentNode.nodeName.toUpperCase()||e.parentNode.classList.contains("nav-page-text")||(e.style.color="#fff")}),f.style.color="#fff",m&&(m.style.color="#fff"),y=!0}function U(){if(s.classList.contains("quarto-dark")){alert("Voc\xea precisa desabilitar o modo escuro para o estado da luz de fundo.");return}y?(h.style.background=r[i],o.play(),F(),k("luz_apagada",!1)):(h.style.background=r[i],o.play(),G(),k("luz_apagada",!0))}M.id="qrcode_container",P.appendChild(_),P.appendChild(x),P.appendChild(j),P.appendChild(T),P.appendChild(M),I.appendChild(P),document.body.appendChild(I),$.appendChild(E("https://js.livro.online/moan-quarto/text_decrease_FILL0_wght400_GRAD0_opsz24.svg",A)),$.appendChild(E("https://js.livro.online/moan-quarto/text_increase_FILL0_wght400_GRAD0_opsz24.svg",B)),$.appendChild(E("https://js.livro.online/moan-quarto/format_clear_FILL0_wght400_GRAD0_opsz24.svg",V)),$.appendChild(E("https://js.livro.online/moan-quarto/note_FILL0_wght400_GRAD0_opsz24.svg",D)),$.appendChild(E("https://js.livro.online/moan-quarto/emoji_objects_FILL0_wght400_GRAD0_opsz24.svg",U)),v.insertBefore($,v.firstChild);let O={attributes:!0,attributeFilter:["class"]};function J(e,t){for(let n of e)"attributes"===n.type&&"class"===n.attributeName&&(s.classList.contains("quarto-dark")?(F(),h.style.removeProperty("background")):S())}let Q=new MutationObserver(J);Q.observe(s,O);var X=document.createElement("div");X.className="referencias_capitulo";var Z=document.createElement("div");Z.className="cont_ref";var K=document.createElement("span");K.id="Paginacao",Z.appendChild(K),X.appendChild(Z);var W=document.createElement("input");W.id="busca_ref",W.className="buscar_ref",W.setAttribute("placeholder","Refer\xeancia..."),W.style.backgroundImage='url("https://js.livro.online/moan-quarto/search_FILL0_wght400_GRAD0_opsz24.svg")',W.style.backgroundRepeat="no-repeat",W.style.backgroundPosition="5px center",W.style.paddingLeft="25px",X.appendChild(W);let Y=document.createElement("button");Y.className="pegarLink";let ee=document.createElement("span");ee.style.display="flex",ee.style.flexDirection="column",ee.style.alignItems="center";let et=document.createElement("img");et.src="https://js.livro.online/moan-quarto/link_FILL0_wght400_GRAD0_opsz24.svg",ee.appendChild(et);let en=document.createTextNode("link");ee.appendChild(en),Y.appendChild(ee),X.appendChild(Y),Y.addEventListener("click",ep),document.body.appendChild(X);let ea=document.getElementById("busca_ref");function eo(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?K.innerHTML=`<span id='PaginacaoInicio'>${e[0].target.id}</span>`:K.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"),K.innerHTML="...")}).catch(e=>console.log("Erro: "+e))}window.addEventListener("scroll",()=>{elementosNaPagina=[],er(),console.log("Observador ativado")});let el={root:null,rootMargin:"0px",threshold:.01,delay:1e3,trackVisibility:!0};function er(){observer&&observer.disconnect();var e=Array.from(h.querySelectorAll(".unidade"));0!==e.length&&(observer=new IntersectionObserver(eo,el),e.map(e=>observer.observe(e)))}function ei(){let e=ea.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 es(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(/:\/\/([^/]+)\/(.+)/),l=o[2];console.log("Verificando: "+l),l="https://livro.online/qr-code/?livro="+(l=(l=l.replace(/\//g,"--")).replace(/#/g,"__")),new QRCode(a,{text:l,colorDark:"#000000",colorLight:"#ffffff",correctLevel:QRCode.CorrectLevel.H})}function ec(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 ep(){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=ec(t),o=ec(n),l=window.location.href,r=new URL(l);r.search="",r.hash="";let i=r.href;if(a===o){let s=`${i}${a?"#"+a:""}`,c=a;c&&""!==c.trim()?w.style.fontSize="30px":(c="Elemento sem refer\xeancia direta",w.style.fontSize="14px"),es(c,s)}else if(a<o){let p=`${i}${a?"#"+a:"#"+o}`,d=a;d&&""!==d.trim()?w.style.fontSize="30px":(d="Elemento sem refer\xeancia direta",w.style.fontSize="14px"),es(d,p)}else{let f=`${i}${o?"#"+o:"#"+a}`,u=o;u&&""!==u.trim()?w.style.fontSize="30px":(u="Elemento sem refer\xeancia direta",w.style.fontSize="14px"),es(u,f)}}}er(),ea.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)})}),ea.addEventListener("keydown",e=>{("Enter"===e.key||13===e.keyCode)&&(e.preventDefault(),ei())}),document.querySelector(".close").addEventListener("click",function(){let e=document.getElementById("modal");e.style.display="none"})}; |