--
This commit is contained in:
@@ -91,30 +91,28 @@
|
|||||||
newHead.querySelectorAll('style').forEach(s => head.appendChild(s.cloneNode(true)));
|
newHead.querySelectorAll('style').forEach(s => head.appendChild(s.cloneNode(true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('click', (event) => {
|
let abortController = null;
|
||||||
const link = event.target.closest('a');
|
|
||||||
if (!link || link.hasAttribute('download')) return;
|
|
||||||
|
|
||||||
const url = new URL(link.href, location.href);
|
async function navigate(url) {
|
||||||
if (url.origin !== location.origin) return;
|
if (abortController) abortController.abort();
|
||||||
if (link.target || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
const ac = new AbortController();
|
||||||
|
abortController = ac;
|
||||||
|
|
||||||
if (url.hash && url.pathname === location.pathname) {
|
document.startViewTransition(async () => {
|
||||||
event.preventDefault();
|
let response;
|
||||||
const target = document.querySelector(url.hash);
|
try {
|
||||||
if (target) {
|
response = await fetch(url.href, {
|
||||||
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
headers: { 'X-Requested-With': 'view-transition' },
|
||||||
history.pushState(null, '', url.hash);
|
signal: ac.signal
|
||||||
}
|
});
|
||||||
|
} catch (err) {
|
||||||
|
if (err.name === 'AbortError') return;
|
||||||
|
location.href = url.href;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.preventDefault();
|
if (ac.signal.aborted) return;
|
||||||
|
|
||||||
document.startViewTransition(async () => {
|
|
||||||
const response = await fetch(url.href, {
|
|
||||||
headers: { 'X-Requested-With': 'view-transition' }
|
|
||||||
});
|
|
||||||
const html = await response.text();
|
const html = await response.text();
|
||||||
const doc = new DOMParser().parseFromString(html, 'text/html');
|
const doc = new DOMParser().parseFromString(html, 'text/html');
|
||||||
|
|
||||||
@@ -145,6 +143,35 @@
|
|||||||
window.__cursorReinit();
|
window.__cursorReinit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
window.__navigate = function (href) {
|
||||||
|
let url;
|
||||||
|
try { url = new URL(href, location.href); } catch (_) { location.href = href; return; }
|
||||||
|
if (url.origin !== location.origin) { location.href = href; return; }
|
||||||
|
navigate(url);
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener('click', (event) => {
|
||||||
|
const link = event.target.closest('a');
|
||||||
|
if (!link || link.hasAttribute('download')) return;
|
||||||
|
|
||||||
|
const url = new URL(link.href, location.href);
|
||||||
|
if (url.origin !== location.origin) return;
|
||||||
|
if (link.target || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
||||||
|
|
||||||
|
if (url.hash && url.pathname === location.pathname) {
|
||||||
|
event.preventDefault();
|
||||||
|
const target = document.querySelector(url.hash);
|
||||||
|
if (target) {
|
||||||
|
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||||
|
history.pushState(null, '', url.hash);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
navigate(url);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('popstate', () => location.reload());
|
window.addEventListener('popstate', () => location.reload());
|
||||||
|
|||||||
+4
-4
@@ -46,14 +46,14 @@
|
|||||||
|
|
||||||
function onTap() {
|
function onTap() {
|
||||||
tapCount++;
|
tapCount++;
|
||||||
if (tapCount >= 10) {
|
if (tapCount >= 3) {
|
||||||
clearTimeout(tapTimer);
|
clearTimeout(tapTimer);
|
||||||
tapCount = 0;
|
tapCount = 0;
|
||||||
location.href = '/qr-code/';
|
typeof window.__navigate === 'function' ? window.__navigate('/qr-code/') : (location.href = '/qr-code/');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
clearTimeout(tapTimer);
|
clearTimeout(tapTimer);
|
||||||
tapTimer = setTimeout(() => { tapCount = 0; }, 1500);
|
tapTimer = setTimeout(() => { tapCount = 0; }, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
el.addEventListener('touchend', (e) => {
|
el.addEventListener('touchend', (e) => {
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
}, { passive: false });
|
}, { passive: false });
|
||||||
|
|
||||||
el.addEventListener('click', () => {
|
el.addEventListener('click', () => {
|
||||||
if (Date.now() - lastTouch < 1400) return;
|
if (Date.now() - lastTouch < 300) return;
|
||||||
onTap();
|
onTap();
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -94,7 +94,9 @@
|
|||||||
(msg.entries || []).forEach((e) => appendRow(e.phase, e.detail, "", e.severity));
|
(msg.entries || []).forEach((e) => appendRow(e.phase, e.detail, "", e.severity));
|
||||||
if (msg.status === "done") {
|
if (msg.status === "done") {
|
||||||
closedByDone = true;
|
closedByDone = true;
|
||||||
location.replace(init.resultsUrl);
|
typeof window.__navigate === 'function'
|
||||||
|
? window.__navigate(init.resultsUrl)
|
||||||
|
: location.replace(init.resultsUrl);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -118,7 +120,12 @@
|
|||||||
if (msg.type === "done") {
|
if (msg.type === "done") {
|
||||||
closedByDone = true;
|
closedByDone = true;
|
||||||
markDone(msg.rank, msg.score);
|
markDone(msg.rank, msg.score);
|
||||||
setTimeout(() => location.replace(msg.redirect || init.resultsUrl), 300);
|
setTimeout(() => {
|
||||||
|
const target = msg.redirect || init.resultsUrl;
|
||||||
|
typeof window.__navigate === 'function'
|
||||||
|
? window.__navigate(target)
|
||||||
|
: location.replace(target);
|
||||||
|
}, 300);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.type === "error") {
|
if (msg.type === "error") {
|
||||||
|
|||||||
Reference in New Issue
Block a user