-
Notifications
You must be signed in to change notification settings - Fork 2
/
darkmode.min.js
7 lines (7 loc) · 6.53 KB
/
darkmode.min.js
1
2
3
4
5
6
7
const darkModeSwitches=document.querySelectorAll(".dark-mode-switch");function toggleDarkMode(){"true"===localStorage.getItem("darkMode")?(document.documentElement.setAttribute("data-mode","light"),localStorage.setItem("darkMode",!1),darkModeSwitches.forEach($=>$.classList.add("light")),darkModeSwitches.forEach($=>$.classList.remove("dark"))):(document.documentElement.setAttribute("data-mode","dark"),localStorage.setItem("darkMode",!0),darkModeSwitches.forEach($=>$.classList.add("dark")),darkModeSwitches.forEach($=>$.classList.remove("light")))}function initDarkMode(){let $=localStorage.getItem("darkMode");if("true"===$){darkModeSwitches.forEach($=>$.classList.add("dark"));return}if("false"===$){darkModeSwitches.forEach($=>$.classList.add("light"));return}window.matchMedia("(prefers-color-scheme: dark)").matches&&(document.documentElement.setAttribute("data-mode","dark"),darkModeSwitches.forEach($=>$.classList.add("dark")))}darkModeSwitches&&darkModeSwitches.forEach($=>{$.addEventListener("click",()=>{darkModeSwitches.forEach($=>$.classList.add("animated")),toggleDarkMode()})}),initDarkMode();const codeBlocks=document.querySelectorAll(".highlight"),copyCodeButtons=document.querySelectorAll(".window-copy-icon");function rocket($){document.addEventListener("DOMContentLoaded",function(){let $=document.querySelector(".rocket");$&&0===$.offsetHeight&&($.classList.remove("show","launch"),$.style.visibility="hidden"),window.addEventListener("scroll",function(){window.scrollY>100?$.classList.add("show"):$.classList.remove("show")})});let _=document.querySelector(".rocket");_&&_.addEventListener("click",function(){_.classList.add("launch"),scrollToTop();let e=document.querySelector(".another-target");e&&(e.style.transition="visibility 0.3s ease",e.style.visibility="hidden",setTimeout(function(){e.style.visibility="visible"},$)),setTimeout(function(){_.classList.remove("launch")},1500)})}function scrollToTop(){window.scrollTo({top:0,behavior:"smooth"})}function languageIcon(){return'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path d="M4 1.75C4 .784 4.784 0 5.75 0h5.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v8.586A1.75 1.75 0 0 1 14.25 15h-9a.75.75 0 0 1 0-1.5h9a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 10 4.25V1.5H5.75a.25.25 0 0 0-.25.25v2a.75.75 0 0 1-1.5 0Zm-4 6C0 6.784.784 6 1.75 6h1.5C4.216 6 5 6.784 5 7.75v2.5A1.75 1.75 0 0 1 3.25 12h-1.5A1.75 1.75 0 0 1 0 10.25ZM6.75 6h1.5a.75.75 0 0 1 .75.75v3.75h.75a.75.75 0 0 1 0 1.5h-3a.75.75 0 0 1 0-1.5h.75v-3h-.75a.75.75 0 0 1 0-1.5Zm-5 1.5a.25.25 0 0 0-.25.25v2.5c0 .138.112.25.25.25h1.5a.25.25 0 0 0 .25-.25v-2.5a.25.25 0 0 0-.25-.25Zm9.75-5.938V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"></path></svg>'}function starIcon(){return'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path d="M8 .25a.75.75 0 0 1 .673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611L7.327.668A.75.75 0 0 1 8 .25Zm0 2.445L6.615 5.5a.75.75 0 0 1-.564.41l-3.097.45 2.24 2.184a.75.75 0 0 1 .216.664l-.528 3.084 2.769-1.456a.75.75 0 0 1 .698 0l2.77 1.456-.53-3.084a.75.75 0 0 1 .216-.664l2.24-2.183-3.096-.45a.75.75 0 0 1-.564-.41L8 2.694Z"></path></svg>'}function forkIcon(){return'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path d="M5 5.372v.878c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75v-.878a2.25 2.25 0 1 1 1.5 0v.878a2.25 2.25 0 0 1-2.25 2.25h-1.5v2.128a2.251 2.251 0 1 1-1.5 0V8.5h-1.5A2.25 2.25 0 0 1 3.5 6.25v-.878a2.25 2.25 0 1 1 1.5 0ZM5 3.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Zm6.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3 8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"></path></svg>'}function licenseIcon(){return'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path d="M8.75.75V2h.985c.304 0 .603.08.867.231l1.29.736c.038.022.08.033.124.033h2.234a.75.75 0 0 1 0 1.5h-.427l2.111 4.692a.75.75 0 0 1-.154.838l-.53-.53.529.531-.001.002-.002.002-.006.006-.006.005-.01.01-.045.04c-.21.176-.441.327-.686.45C14.556 10.78 13.88 11 13 11a4.498 4.498 0 0 1-2.023-.454 3.544 3.544 0 0 1-.686-.45l-.045-.04-.016-.015-.006-.006-.004-.004v-.001a.75.75 0 0 1-.154-.838L12.178 4.5h-.162c-.305 0-.604-.079-.868-.231l-1.29-.736a.245.245 0 0 0-.124-.033H8.75V13h2.5a.75.75 0 0 1 0 1.5h-6.5a.75.75 0 0 1 0-1.5h2.5V3.5h-.984a.245.245 0 0 0-.124.033l-1.289.737c-.265.15-.564.23-.869.23h-.162l2.112 4.692a.75.75 0 0 1-.154.838l-.53-.53.529.531-.001.002-.002.002-.006.006-.016.015-.045.04c-.21.176-.441.327-.686.45C4.556 10.78 3.88 11 3 11a4.498 4.498 0 0 1-2.023-.454 3.544 3.544 0 0 1-.686-.45l-.045-.04-.016-.015-.006-.006-.004-.004v-.001a.75.75 0 0 1-.154-.838L2.178 4.5H1.75a.75.75 0 0 1 0-1.5h2.234a.249.249 0 0 0 .125-.033l1.288-.737c.265-.15.564-.23.869-.23h.984V.75a.75.75 0 0 1 1.5 0Zm2.945 8.477c.285.135.718.273 1.305.273s1.02-.138 1.305-.273L13 6.327Zm-10 0c.285.135.718.273 1.305.273s1.02-.138 1.305-.273L3 6.327Z"></path></svg>'}copyCodeButtons.forEach(($,_)=>{let e=codeBlocks[_].innerText;$.addEventListener("click",()=>{window.navigator.clipboard.writeText(e),$.classList.add("copied"),setTimeout(()=>{$.classList.remove("copied")},1e3)})}),rocket(1e3),document.addEventListener("DOMContentLoaded",async()=>{let $=document.querySelector(".github-card .name a").textContent.trim();function _($){return $>=1e3?($/1e3).toFixed(1)+"k":$.toString()}async function e($){try{let _=await fetch(`https://api.github.com/repos/${$}`);if(!_.ok)throw Error(`HTTP error! status: ${_.status}`);return await _.json()}catch(e){return console.warn(`Failed to fetch data for ${$}: ${e.message}`),null}}async function t(){let t=await e($);if(t){let{full_name:a,description:s,stargazers_count:o,forks_count:n,pushed_at:c,language:i,license:r,topics:d=[]}=t,l=new Date(c).toLocaleDateString("en-US",{month:"short",day:"numeric"}),h=document.querySelector(".github-card .panel-body"),u=document.createElement("div");if(u.className="description",u.textContent=s,h.appendChild(u),d.length>0){let g=document.createElement("div");g.className="badge-group",g.innerHTML=d.map($=>`<span class='badge'>${$}</span>`).join(" "),h.appendChild(g)}let m=document.createElement("div");m.className="stats",m.innerHTML=`
<span>${languageIcon()} ${i||"Unknown Language"}</span>
<span>${starIcon()} ${_(o)}</span>
<span>${forkIcon()} ${_(n)}</span>
<span>${licenseIcon()} ${r?.name||"No License"}</span>
<span>Updated on ${l}</span>
`,h.appendChild(m)}}t()});