1
0
Fork 0
This repository has been archived on 2025-05-26. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Checkpoint-Golang/develop/js/u.js
2025-05-26 12:42:36 -05:00

132 lines
No EOL
9.8 KiB
JavaScript

// Smooth scroll to ID
window.addEventListener("load", function () { setTimeout(() => { if (window.location.hash) { let t = window.location.hash.substring(1), o = document.getElementById(t); o && o.scrollIntoView({ behavior: "smooth", block: "start" }) } }, 135) });
// No card hover on touch
("ontouchstart" in window || navigator.maxTouchPoints > 0) && window.addEventListener("touchstart", function t() { document.body.classList.add("no-hover"), window.removeEventListener("touchstart", t, !1) }, !1);
// Auto-add target="_blank" and secure rel (noopener & noreferrer) to external links,
// except those with the "eel" class
(() => { let e = document.baseURI, t = document.querySelectorAll("a[href]:not(.eel)"), r = window.location.hostname; for (let l = 0, n = t.length; l < n; l++) { let o = t[l]; try { let b = new URL(o.getAttribute("href"), e); if (b.hostname !== r) { "_blank" !== o.getAttribute("target") && o.setAttribute("target", "_blank"); let a = o.getAttribute("rel") || ""; /\bnoopener\b/.test(a) || (a += " noopener"), /\bnoreferrer\b/.test(a) || (a += " noreferrer"), o.setAttribute("rel", a.trim()) } } catch (i) { } } })();
// Switch to JPG for devices that don't support WebP
!async function () { await async function () { return new Promise((function (n) { const e = new Image; e.onload = function () { n(1 === e.width && 1 === e.height) }, e.onerror = function () { n(!1) }, e.src = "data:image/webp;base64,UklGRhYAAABXRUJQVlA4TAoAAAAvAAAAAEX/I/of" })) }() || document.querySelectorAll('img[src$=".webp"]').forEach((function (n) { n.src = n.src.replace(/\.webp$/i, ".jpg") })) }()
// Link redirect animation
document.addEventListener('DOMContentLoaded', function () {
// Create and inject CSS for the animation
const style = document.createElement('style');
style.textContent = `
.link-arrow-container {
position: absolute;
pointer-events: none;
z-index: 9999;
width: 20px;
height: 20px;
right: 0px;
opacity: 0;
transform: translateX(-5px);
transition: transform 0.1s ease-out, opacity 0.1s ease-out;
/* Vertical alignment handled by parent flex settings */
}
.link-arrow-container.animate {
opacity: 1;
transform: translateX(5px);
}
.link-arrow-container svg {
width: 100%;
height: 100%;
fill: currentColor;
display: block;
}
a[href]:not(.no-arrow-padding):not(a[target="_blank"]) {
position: relative;
padding-right: 24px;
display: inline-flex;
align-items: center;
}
`;
document.head.appendChild(style);
// SVG arrow icon data
const svgArrow = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z"/></svg>`;
// Add arrow containers to eligible links on load
document.querySelectorAll('a[href]').forEach(link => {
const href = link.getAttribute('href');
// Skip links that open in new tabs, are anchors, or javascript calls
if (link.getAttribute('target') === '_blank' || href.startsWith('#') || href.startsWith('javascript:')) {
return;
}
// Create and append arrow container
const arrowContainer = document.createElement('div');
arrowContainer.className = 'link-arrow-container';
arrowContainer.innerHTML = svgArrow;
link.appendChild(arrowContainer);
});
// Delegated click listener on the body
document.body.addEventListener('click', function (e) {
// Find the closest ancestor link
const link = e.target.closest('a[href]');
// If no link was clicked, or checks fail, do nothing
if (!link) return;
const href = link.getAttribute('href');
if (link.getAttribute('target') === '_blank' || href.startsWith('#') || href.startsWith('javascript:')) {
return;
}
// Skip if modifier keys are pressed
if (e.ctrlKey || e.metaKey || e.shiftKey) return;
// Find the arrow container within this link
const arrowContainer = link.querySelector('.link-arrow-container');
if (!arrowContainer) return; // Should exist, but safety check
// Prevent default navigation
e.preventDefault();
// Animate the arrow
arrowContainer.classList.add('animate');
// Navigate after a delay
setTimeout(() => {
window.location.href = href;
}, 100);
});
// Reset animation state on page show (handles bfcache)
window.addEventListener('pageshow', function (event) {
if (event.persisted) {
document.querySelectorAll('.link-arrow-container.animate').forEach(arrow => {
arrow.classList.remove('animate');
});
}
});
});
// Quicklink 2.3.0
!function (e, n) { "object" == typeof exports && "undefined" != typeof module ? n(exports) : "function" == typeof define && define.amd ? define(["exports"], n) : n(e.quicklink = {}) }(this, function (e) { function n(e) { return new Promise(function (n, r, t) { (t = new XMLHttpRequest).open("GET", e, t.withCredentials = !0), t.onload = function () { 200 === t.status ? n() : r() }, t.send() }) } var r, t = (r = document.createElement("link")).relList && r.relList.supports && r.relList.supports("prefetch") ? function (e) { return new Promise(function (n, r, t) { (t = document.createElement("link")).rel = "prefetch", t.href = e, t.onload = n, t.onerror = r, document.head.appendChild(t) }) } : n, o = window.requestIdleCallback || function (e) { var n = Date.now(); return setTimeout(function () { e({ didTimeout: !1, timeRemaining: function () { return Math.max(0, 50 - (Date.now() - n)) } }) }, 1) }, i = new Set, c = new Set, u = !1; function a(e) { if (e) { if (e.saveData) return new Error("Save-Data is enabled"); if (/2g/.test(e.effectiveType)) return new Error("network conditions are poor") } return !0 } function s(e, r, o) { var s = a(navigator.connection); return s instanceof Error ? Promise.reject(new Error("Cannot prefetch, " + s.message)) : (c.size > 0 && !u && console.warn("[Warning] You are using both prefetching and prerendering on the same document"), Promise.all([].concat(e).map(function (e) { if (!i.has(e)) return i.add(e), (r ? function (e) { return window.fetch ? fetch(e, { credentials: "include" }) : n(e) } : t)(new URL(e, location.href).toString()) }))) } function f(e, n) { var r = a(navigator.connection); if (r instanceof Error) return Promise.reject(new Error("Cannot prerender, " + r.message)); if (!HTMLScriptElement.supports("speculationrules")) return s(e), Promise.reject(new Error("This browser does not support the speculation rules API. Falling back to prefetch.")); if (document.querySelector('script[type="speculationrules"]')) return Promise.reject(new Error("Speculation Rules is already defined and cannot be altered.")); for (var t = 0, o = [].concat(e); t < o.length; t += 1) { var f = o[t]; if (window.location.origin !== new URL(f, window.location.href).origin) return Promise.reject(new Error("Only same origin URLs are allowed: " + f)); c.add(f) } i.size > 0 && !u && console.warn("[Warning] You are using both prefetching and prerendering on the same document"); var l = function (e) { var n = document.createElement("script"); n.type = "speculationrules", n.text = '{"prerender":[{"source": "list","urls": ["' + Array.from(e).join('","') + '"]}]}'; try { document.head.appendChild(n) } catch (e) { return e } return !0 }(c); return !0 === l ? Promise.resolve() : Promise.reject(l) } e.listen = function (e) { if (e || (e = {}), window.IntersectionObserver) { var n = function (e) { e = e || 1; var n = [], r = 0; function t() { r < e && n.length > 0 && (n.shift()(), r++) } return [function (e) { n.push(e) > 1 || t() }, function () { r--, t() }] }(e.throttle || 1 / 0), r = n[0], t = n[1], a = e.limit || 1 / 0, l = e.origins || [location.hostname], d = e.ignores || [], h = e.delay || 0, p = [], m = e.timeoutFn || o, w = "function" == typeof e.hrefFn && e.hrefFn, g = e.prerender || !1; u = e.prerenderAndPrefetch || !1; var v = new IntersectionObserver(function (n) { n.forEach(function (n) { if (n.isIntersecting) p.push((n = n.target).href), function (e, n) { n ? setTimeout(e, n) : e() }(function () { -1 !== p.indexOf(n.href) && (v.unobserve(n), (u || g) && c.size < 1 ? f(w ? w(n) : n.href).catch(function (n) { if (!e.onError) throw n; e.onError(n) }) : i.size < a && !g && r(function () { s(w ? w(n) : n.href, e.priority).then(t).catch(function (n) { t(), e.onError && e.onError(n) }) })) }, h); else { var o = p.indexOf((n = n.target).href); o > -1 && p.splice(o) } }) }, { threshold: e.threshold || 0 }); return m(function () { (e.el || document).querySelectorAll("a").forEach(function (e) { l.length && !l.includes(e.hostname) || function e(n, r) { return Array.isArray(r) ? r.some(function (r) { return e(n, r) }) : (r.test || r).call(r, n.href, n) }(e, d) || v.observe(e) }) }, { timeout: e.timeout || 2e3 }), function () { i.clear(), v.disconnect() } } }, e.prefetch = s, e.prerender = f });
quicklink.listen({
origins: [],
ignores: [
// Don't prefetch URL fragments from my own site
uri => uri.includes('caileb.com') && uri.includes('#'),
// Don't prefetch hosted services
uri => uri.includes('gallery.caileb.com'),
uri => uri.includes('jellyfin.caileb.com'),
uri => uri.includes('archive.caileb.com'),
uri => uri.includes('music.caileb.com'),
// Don't prefetch API's
/\/api\/?/,
/^api\./,
// Don't prefetch these file types
uri => /\.(zip|tar|7z|rar|js|apk|xapk|woff2|tff|otf|pdf|mp3|mp4|wav|exe|msi|bat|deb|rpm|bin|dmg|iso|csv|log|sql|xml|key|odp|ods|pps|ppt|xls|doc|jpg|jpeg|jpe|jif|jfif|jfi|png|gif|webp|tif|psd|raw|arw|cr2|nrw|k25|bmp|dib|heif|heic|ind|indd|indt|jp2|j2k|jpf|jpx|jpm|mj2|svg|ai|eps)$/i.test(uri),
// Don't prefetch these protocols
uri => /^(http|file|ftp|mailto|tel):/i.test(uri),
]
});