// deno-fmt-ignore-file // deno-lint-ignore-file // This code was bundled using `deno bundle` and it's not recommended to edit it manually (function() { const cookiesDisabled = !navigator.cookieEnabled; if (cookiesDisabled) { document.cookie = "disabled"; document.cookie.indexOf("disabled"); return console.log("Pager is disabled due to cookie restrictions."); } let settings = { pager: {} }; const url = self.location.href.split("#")[0].split("?")[0]; const scrollRestore = (url)=>{ if (history.scrollRestoration) history.scrollRestoration = "manual"; if (localStorage["settings"]) { settings = JSON.parse(localStorage["settings"]); } const fragment = document.getElementById(location.hash.slice(1)); const fragmentInURL = self.location.hash.length > 0; if (fragmentInURL && document.body.contains(fragment)) { settings["pager"][url] = self.pageYOffset; localStorage["settings"] = JSON.stringify(settings); fragment.scrollIntoView(); self.addEventListener("load", function() { fragment.scrollIntoView(); }); return; } if (settings["pager"][url] > 0) { self.scrollTo(0, settings["pager"][url]); return; } settings["pager"][url] = self.pageYOffset; localStorage["settings"] = JSON.stringify(settings); }; const scrollTrack = (url)=>{ const currentPosition = self.pageYOffset; settings["pager"][url] = currentPosition; localStorage["settings"] = JSON.stringify(settings); }; const backTrack = (back, up, event)=>{ if (document.body.contains(up) && up.contains(event.target)) { event.preventDefault(); window.scrollTo(0, 0); } if (document.body.contains(back) && back.contains(event.target)) { if (history.length < 2) return; event.preventDefault(); history.go(-1); } }; self.addEventListener("DOMContentLoaded", function() { scrollRestore(url); self.addEventListener("click", function(event) { const up = document.getElementById("top"); const back = document.getElementById("back"); backTrack(back, up, event); }); }); self.addEventListener("scroll", function() { scrollTrack(url); }); self.addEventListener("hashchange", function() { scrollRestore(url); }); })(); (function() { const options = "targetWindow,width=700,height=500,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes"; self.addEventListener("keydown", function(event) { if (event.repeat && event.key === "d") { selection(dictionary); } if (event.repeat && event.key === "s") { selection(search); } if (event.repeat && event.key === "m") { selection(manual); } }); function selection(execute) { let phrase = "" + window.getSelection(); phrase = phrase.replace(/[!.:?,;"]/g, ""); phrase = phrase.replace(/^\s*(\S*?)\s*$/g, "$1"); if (phrase && phrase > "" && phrase.length > 1) { execute(phrase); } } function dictionary(word) { window.open("https://www.merriam-webster.com/dictionary/" + encodeURIComponent(word), "Definitions", options); } function search(phrase) { window.open("https://lite.duckduckgo.com/lite/?q=" + encodeURIComponent(phrase), "Search", options); } function manual(program) { window.open("https://man.archlinux.org/search?q=" + encodeURIComponent(program), "Manual", options); } })(); (function() { self.addEventListener("DOMContentLoaded", function() { let mouseoverTimer; let lastTouchTimestamp; const prefetches = new Set(); const prefetchElement = document.createElement("link"); const isSupported = prefetchElement.relList && prefetchElement.relList.supports && prefetchElement.relList.supports("prefetch") && window.IntersectionObserver && "isIntersecting" in IntersectionObserverEntry.prototype; const allowQueryString = "instantAllowQueryString" in document.body.dataset; const allowExternalLinks = "instantAllowExternalLinks" in document.body.dataset; const useWhitelist = "instantWhitelist" in document.body.dataset; const mousedownShortcut = "instantMousedownShortcut" in document.body.dataset; let delayOnHover = 65; let useMousedown = false; let useMousedownOnly = false; let useViewport = false; if ("instantIntensity" in document.body.dataset) { const intensity = document.body.dataset.instantIntensity; if (intensity.substr(0, "mousedown".length) == "mousedown") { useMousedown = true; if (intensity == "mousedown-only") { useMousedownOnly = true; } } else if (intensity.substr(0, "viewport".length) == "viewport") { if (!(navigator.connection && (navigator.connection.saveData || navigator.connection.effectiveType && navigator.connection.effectiveType.includes("2g")))) { if (intensity == "viewport") { if (document.documentElement.clientWidth * document.documentElement.clientHeight < 450000) { useViewport = true; } } else if (intensity == "viewport-all") { useViewport = true; } } } else { const milliseconds = parseInt(intensity); if (!isNaN(milliseconds)) { delayOnHover = milliseconds; } } } if (isSupported) { const eventListenersOptions = { capture: true, passive: true }; if (!useMousedownOnly) { document.addEventListener("touchstart", touchstartListener, eventListenersOptions); } if (!useMousedown) { document.addEventListener("mouseover", mouseoverListener, eventListenersOptions); } else if (!mousedownShortcut) { document.addEventListener("mousedown", mousedownListener, eventListenersOptions); } if (mousedownShortcut) { document.addEventListener("mousedown", mousedownShortcutListener, eventListenersOptions); } if (useViewport) { let triggeringFunction; if (window.requestIdleCallback) { triggeringFunction = function(callback) { requestIdleCallback(callback, { timeout: 1500 }); }; } else { triggeringFunction = function(callback) { callback(); }; } triggeringFunction(function() { const intersectionObserver = new IntersectionObserver(function(entries) { entries.forEach(function(entry) { if (entry.isIntersecting) { const linkElement = entry.target; intersectionObserver.unobserve(linkElement); preload(linkElement.href); } }); }); document.querySelectorAll("a").forEach(function(linkElement) { if (isPreloadable(linkElement)) { intersectionObserver.observe(linkElement); } }); }); } } function touchstartListener(event) { lastTouchTimestamp = performance.now(); const linkElement = event.target.closest("a"); if (!isPreloadable(linkElement)) { return; } preload(linkElement.href); } function mouseoverListener(event) { if (performance.now() - lastTouchTimestamp < 1111) { return; } const linkElement = event.target.closest("a"); if (!isPreloadable(linkElement)) { return; } linkElement.addEventListener("mouseout", mouseoutListener, { passive: true }); mouseoverTimer = setTimeout(function() { preload(linkElement.href); mouseoverTimer = undefined; }, delayOnHover); } function mousedownListener(event) { const linkElement = event.target.closest("a"); if (!isPreloadable(linkElement)) { return; } preload(linkElement.href); } function mouseoutListener(event) { if (event.relatedTarget && event.target.closest("a") == event.relatedTarget.closest("a")) { return; } if (mouseoverTimer) { clearTimeout(mouseoverTimer); mouseoverTimer = undefined; } } function mousedownShortcutListener(event) { if (performance.now() - lastTouchTimestamp < 1111) { return; } const linkElement = event.target.closest("a"); if (event.which > 1 || event.metaKey || event.ctrlKey) { return; } if (!linkElement) { return; } linkElement.addEventListener("click", function(event) { if (event.detail == 1337) { return; } event.preventDefault(); }, { capture: true, passive: false, once: true }); const customEvent = new MouseEvent("click", { view: window, bubbles: true, cancelable: false, detail: 1337 }); linkElement.dispatchEvent(customEvent); } function isPreloadable(linkElement) { if (!linkElement || !linkElement.href) { return; } if (useWhitelist && !("instant" in linkElement.dataset)) { return; } if (!allowExternalLinks && linkElement.origin != location.origin && !("instant" in linkElement.dataset)) { return; } if (![ "http:", "https:" ].includes(linkElement.protocol)) { return; } if (linkElement.protocol == "http:" && location.protocol == "https:") { return; } if (!allowQueryString && linkElement.search && !("instant" in linkElement.dataset)) { return; } if (linkElement.hash && linkElement.pathname + linkElement.search == location.pathname + location.search) { return; } if ("noInstant" in linkElement.dataset) { return; } return true; } function preload(url) { if (prefetches.has(url)) { return; } const prefetcher = document.createElement("link"); prefetcher.rel = "prefetch"; prefetcher.href = url; document.head.appendChild(prefetcher); prefetches.add(url); } }); })(); (function() { const hide = (triggers)=>{ for(let i = 0; i < triggers.length; i++){ triggers[i].checked = false; } }; const hideIfClickedOutside = (menus, triggers, event)=>{ for(let i = 0; i < menus.length; i++){ const active = triggers[i].checked === true; const outside = !menus[i].contains(event.target); if (outside && active) hide(triggers); } }; self.addEventListener("scroll", function() { const triggers = document.querySelectorAll("micro-metadata-menu input"); hide(triggers); }); [ "click", "touchstart" ].forEach(function(event) { self.addEventListener(event, function(event) { const menus = document.querySelectorAll("micro-metadata-menu"); const triggers = document.querySelectorAll("micro-metadata-menu input"); hideIfClickedOutside(menus, triggers, event); }); }); })(); (function() { self.addEventListener("DOMContentLoaded", function() { const form = document.getElementById("search-form"); const query = document.getElementById("search-input"); document.getElementById("search-submit"); const dropdown = document.getElementById("search-results"); const container = document.getElementById("search-frame"); form.addEventListener("focusin", function() { initialize(); }); form.addEventListener("submit", function(event) { event.preventDefault(); return false; }); form.addEventListener("keydown", function(event) { const head = dropdown.firstChild.nextElementSibling.firstChild.nextElementSibling; const tail = dropdown.lastElementChild.firstChild.nextElementSibling; if (query.contains(event.target)) { if (event.keyCode == 27) { document.activeElement.blur(); dropdown.setAttribute("hidden", ""); } } if (event.keyCode == 40) { event.preventDefault(); if (document.activeElement == query) head.focus(); else if (document.activeElement == tail) query.focus(); else { document.activeElement.parentElement.nextElementSibling.firstChild.nextElementSibling.focus(); } } if (event.keyCode == 38) { event.preventDefault(); if (document.activeElement == query) tail.focus(); else if (document.activeElement == head) query.focus(); else { document.activeElement.parentElement.previousElementSibling.firstChild.nextElementSibling.focus(); } } if (event.keyCode == 8) { if (document.activeElement != query) { event.preventDefault(); query.focus(); } } if (event.keyCode == 13) { if (dropdown && document.activeElement == query) { event.preventDefault(); head.focus(); self.window.location = document.activeElement.href; } } }); let scrolls = 0; self.addEventListener("scroll", function() { if (scrolls > 3) { scrolls = 0; document.activeElement.blur(); dropdown.setAttribute("hidden", ""); container.removeAttribute("data-focus"); } scrolls++; }); document.addEventListener("click", function(event) { if (!form.contains(event.target)) { dropdown.setAttribute("hidden", ""); container.removeAttribute("data-focus"); } }); let data = {}; function isEmpty(obj) { return Object.keys(obj).length === 0; } function appendItemsTo(local, remote) { const paginated = Object.keys(remote).includes("next_url"); if (isEmpty(local)) { local = remote; } else { local.items = local.items.concat(remote.items); } if (paginated) { fetchJson(remote.next_url, local); } data = local; } function fetchJson(url, store) { const httpRequest = new XMLHttpRequest(); httpRequest.onreadystatechange = function() { if (httpRequest.readyState === 4 && httpRequest.status === 200) { appendItemsTo(store, JSON.parse(httpRequest.responseText)); } }; httpRequest.open("GET", url); httpRequest.send(); } function loadScript(url) { return new Promise(function(resolve, reject) { const script = document.createElement("script"); script.onerror = reject; script.onload = resolve; if (document.currentScript) { document.currentScript.parentNode.insertBefore(script, document.currentScript); } else { document.head.appendChild(script); } script.src = url; }); } let firstRun = true; function initialize() { if (firstRun) { loadScript(window.location.origin + "/js/fuzzysort.js").then(()=>{ firstRun = false; fetchJson("/index.json", {}); const options = { key: [ "title" ] }; query.addEventListener("keyup", function() { search(query.value, data.items, options); }); query.addEventListener("focusin", function() { search(query.value, data.items, options); }); search(query.value, data.items, options); }).catch((error)=>{ console.log("Error failed to load fuzzy sort: " + error); }); } } function search(term, data, options) { const results = fuzzysort.go(term, data, options); let items = ""; if (results.length === 0 && term.length >= 0) { let separator = "—"; if (term.length === 0) separator = ""; items = `
  • ${term} ${separator} No Results Found
  • `; dropdown.removeAttribute("hidden"); container.setAttribute("data-focus", ""); } else { dropdown.removeAttribute("hidden"); for(const string in results.slice(0, 10)){ const title = results[string].obj.title; let highlight = fuzzysort.highlight(fuzzysort.single(term, title), "", ""); if (highlight === null) { highlight = title; } items = items + `
  • ${highlight}
  • `; } } dropdown.innerHTML = items; } }); })(); (function() { const relative = new Intl.RelativeTimeFormat("en", { localeMatcher: "best fit", numeric: "always", style: "long" }); const date = ()=>{ [ ...document.querySelectorAll("time") ].forEach((element)=>{ try { const time = new Date(element.dateTime) || new Date(); const interval = (new Date().getTime() - time.getTime()) / 1000; const seconds = Math.floor(interval); const minutes = Math.floor(seconds / 60); const hours = Math.floor(minutes / 60); const days = Math.floor(hours / 24); if (Math.sign(seconds) === 1) { if (seconds <= 60) { return element.textContent = relative.format(-1 * seconds, "second"); } if (minutes <= 120) { return element.textContent = relative.format(-1 * minutes, "minute"); } if (hours <= 48) { return element.textContent = relative.format(-1 * hours, "hour"); } if (days <= 60) { return element.textContent = relative.format(-1 * days, "day"); } } if (Math.sign(seconds) === -1) { if (-1 * days >= 60) { return element.textContent = relative.format(-1 * days, "day"); } if (-1 * hours >= 48) { return element.textContent = relative.format(-1 * hours, "hour"); } if (-1 * minutes >= 120) { return element.textContent = relative.format(-1 * minutes, "minute"); } if (-1 * seconds >= 0) { return element.textContent = relative.format(-1 * seconds, "second"); } } } catch (error) { console.error("Error: Unable to resolve relative time format!", error); } }); }; const substitution = setInterval(date, 4); self.addEventListener("load", ()=>{ setTimeout(()=>{ clearInterval(substitution); setInterval(date, 1000); }, 1000); }); })(); console.log("Surface Control: Complete");