whisper.cat/weboasis/js/custom.min.js

1 line
4.2 KiB
JavaScript
Raw Normal View History

2023-10-05 23:28:32 +11:00
document.addEventListener("DOMContentLoaded",function(){function a(a){url_str="url(media/bg/bg"+a+".jpg)",console.log(url_str),void 0===a|!a?(document.getElementById("canvasContainer").style.display="block",document.getElementById("body").style.display.backgroundImage="none",document.getElementById("resetBackgroundBtn").style.display="none"):(document.getElementById("canvasContainer").style.display="none",document.getElementById("body").style.backgroundImage=url_str)}function b(){var a=localStorage.getItem("background_image_file");document.getElementById("canvasContainer").style.display="none",document.getElementById("body").style.backgroundImage="url("+a+")","none"===document.getElementById("resetBackgroundBtn").style.display&&(document.getElementById("resetBackgroundBtn").style.display="inline-block")}var d=document.getElementById("resetBackgroundBtn"),f=localStorage.getItem("background_id");"yes"==localStorage.getItem("use_own_background_image")?(d.style.display="inline-block",b()):a(f),console.log("Filling options");for(var g,h=0,j=linkMenuOrder.length;h<j;h++)g=document.createElement("option"),g.innerHTML=linkMenuOrder[h],document.getElementById("menu-select").appendChild(g);document.getElementById("add").addEventListener("click",function(){return"https://"===document.getElementById("url").value||""===document.getElementById("url").value||""===document.getElementById("title").value?void alert("You haven't entered new link URL or title!"):void(addLinkToMenu(document.getElementById("url").value,document.getElementById("title").value,document.getElementById("menu-select").value),document.getElementById("url").value="https://",document.getElementById("title").value="")});var k=document.getElementById("add-link-form");document.getElementById("add-link-btn").addEventListener("click",function(){k.classList.toggle("active")}),bg_container=document.getElementById("customBackgrounds"),bg_list=document.getElementById("customBackgroundsList"),bg_thumb=document.getElementById("thumbTemplate"),bg_count=6;for(var m=0;5>=m;m++){var n="media/bg-thumbs/bg"+m+".jpg",h=bg_thumb.cloneNode(!0);h.classList.remove("template"),h.style.backgroundImage="url("+n+")",h.setAttribute("data-id",m),bg_list.appendChild(h)}var l=function(){f="",localStorage.setItem("background_id",f),document.getElementById("thumbTemplate").classList.remove("active"),a(f),"yes"===localStorage.getItem("use_own_background_image")&&(localStorage.setItem("use_own_background_image","no"),localStorage.setItem("background_image_file",""))};document.getElementById("customBgBtnToggle").addEventListener("click",function(){document.getElementById("customBackgrounds").classList.toggle("active")});var o=document.querySelectorAll(".thumb");Array.from(o).forEach(function(c){c.addEventListener("mouseover",function(){bg_container.classList.contains("active")&&a(this.getAttribute("data-id"))}),c.addEventListener("mouseleave",function(){bg_container.classList.contains("active")&&("yes"===localStorage.getItem("use_own_background_image")?b():a(f))}),c.addEventListener("click",function(){if(bg_container.classList.contains("active")){f=this.getAttribute("data-id"),localStorage.setItem("background_id",f);for(let a of this.parentNode.children)a.classList.remove("active");this.classList.add("active"),d.style.display="inline-block"}localStorage.setItem("use_own_background_image","no"),localStorage.setItem("background_image_file","")})}),d.addEventListener("click",function(){l()}),globalResetBackground=l,document.getElementById("customBackgroundFile").addEventListener("change",function(){var a=this.files[0];if(0>a.type.indexOf("image"))return void alert("Sorry, that is an invalid file type");var b=new FileReader;b.onload=function(){var a=b.result;try{localStorage.setItem("background_image_file",a),localStorage.setItem("use_own_background_image","yes"),document.getElementById("canvasContainer").style.display="none",document.getElementById("body").style.backgroundImage="url("+a+")",d.style.display="inline-block",document.getElementById("customBackgrounds").classList.toggle("active"),lockSidebar=