-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzephyr.min.js
1 lines (1 loc) · 3.64 KB
/
zephyr.min.js
1
var dark=!1,darkcolor="#4a94fa",lightcolor="#990099",darkbgcolor="#000000",lightbgcolor="#ffffff",i=0;const darkSwitch=()=>{"dark"==localStorage.getItem("current_theme")?localStorage.setItem("current_theme","light"):"light"==localStorage.getItem("current_theme")?localStorage.setItem("current_theme","dark"):localStorage.setItem("current_theme",dark?"dark":"light"),dark=!dark,document.querySelectorAll("za").forEach((t=>{if("zli"==t.parentNode.nodeName.toLowerCase())return""==window.location.pathname.split("/").pop()&&"index.html"==t.getAttribute("href")||t.getAttribute("href")==window.location.pathname.split("/").pop()?t.className="active":void(t.style.color=shadeColor(dark?darkcolor:lightcolor,2))})),document.querySelector("zdark").innerText=dark?"Light Mode":"Dark Mode",document.querySelector("*").style.setProperty("--color",dark?darkcolor:lightcolor),document.querySelector("*").style.setProperty("--bgColor",dark?darkbgcolor:lightbgcolor)},shadeColor=(t,e)=>{const r=t.startsWith("#")?1:0;var o=parseInt(t.substring(r,3),16),a=parseInt(t.substring(r+2,5),16),l=parseInt(t.substring(r+4,7),16);o=Math.round(o/e),a=(a=Math.round(a/e))<255?a:255,l=(l=Math.round(l/e))<255?l:255;return`#${1===(o=o<255?o:255).toString(16).length?`0${o.toString(16)}`:o.toString(16)}${1===a.toString(16).length?`0${a.toString(16)}`:a.toString(16)}${1===l.toString(16).length?`0${l.toString(16)}`:l.toString(16)}`};HTMLElement.prototype.attributeToCSS=function(){Array.prototype.slice.call(this.attributes).forEach((t=>"href"==t.name?(this.addEventListener("click",(()=>window.location.href=t.value)),this.style.cursor="pointer"):"src"==t.name?(t.value.includes("http"),this.style.backgroundImage=`url(${t.value})`):void(this.style[t.name]=t.value)))},window.post=function(t,e){return fetch(t,{method:"POST",mode:"no-cors",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})},window.get=function(t){return fetch(t,{method:"GET",mode:"no-cors",headers:{"Content-Type":"application/json"}})},setInterval((()=>{360==i&&(i=0),document.querySelectorAll("zh1").forEach((t=>{t.style.background=dark?`linear-gradient(${i}deg, rgba(2, 0, 36, 1) 25%, rgba(2, 0, 36, 1) 50%, #4a94fa 75%, #4a94fa 100%)`:`linear-gradient(${i}deg, rgb(117, 22, 117) 25%, rgb(82, 41, 82) 50%, rgb(75, 23, 75) 75%, rgb(82, 41, 82) 100%)`,t.style.webkitBackgroundClip="text"})),i++}),10),document.addEventListener("DOMContentLoaded",(()=>document.querySelectorAll("zloader").forEach((t=>{if(document.querySelector("zbody").style.opacity=0,"windowLoad"==t.getAttribute("waitFor")){if(t.hasAttribute("delay"))return setTimeout((()=>{t.remove(),document.querySelector("zbody").style.opacity=1}),t.getAttribute("delay"));t.remove(),document.querySelector("zbody").style.opacity=1}})))),document.querySelectorAll("zform").forEach((t=>{let e=[];Array.prototype.slice.call(t.children).forEach((r=>{"button"==r.nodeName.toLowerCase()&&r.addEventListener("click",(()=>{Array.prototype.slice.call(t.children).forEach((t=>{"input"!=t.nodeName.toLowerCase()&&"textarea"!=t.nodeName.toLowerCase()||e.push(t)}));const r=new CustomEvent("zSubmit",{detail:e});let o,a;Array.prototype.slice.call(t.attributes).forEach((t=>{"method"==t.name&&(o=t.value.toLowerCase()),"action"==t.name&&(a=t.value.toLowerCase())})),"post"==o&&console.log(post(a,e)),"get"==o&&console.log(get(a)),e=[],o="",a="",t.dispatchEvent(r)}))}))})),document.querySelector("zdark").addEventListener("click",darkSwitch),document.querySelectorAll("*").forEach((t=>{t.nodeName.toLowerCase().startsWith("z")&&t.attributeToCSS()})),Array.prototype.slice.call(document.querySelector("zconfig").attributes).forEach((t=>{t.name.startsWith("$")&&(window[t.name.split("$").pop()]=t.value)})),darkSwitch();