Commit 2f5d2b4500
Unsigned
Layout: unified · split
docs/.vitepress/theme/Layout.vue +33
| @@ -1315,6 +1315,39 @@ onMounted(() => { | ||
| 1315 | 1315 | initTitleOnly() |
| 1316 | 1316 | nextTick(setupManualCopyButtons) |
| 1317 | 1317 | |
| 1318 | // ping | |
| 1319 | if (import.meta.env.PROD) { | |
| 1320 | const API = 'https://ping.duckling.workers.dev' | |
| 1321 | let vid = localStorage.getItem('_wa_vid') | |
| 1322 | if (!vid) { | |
| 1323 | vid = Array.from(crypto.getRandomValues(new Uint8Array(16))) | |
| 1324 | .map(b => b.toString(16).padStart(2, '0')).join('') | |
| 1325 | localStorage.setItem('_wa_vid', vid) | |
| 1326 | } | |
| 1327 | let currentPage = location.pathname | |
| 1328 | function ping() { | |
| 1329 | const page = location.pathname | |
| 1330 | const isPageview = page !== currentPage | |
| 1331 | currentPage = page | |
| 1332 | fetch(API, { | |
| 1333 | method: 'POST', | |
| 1334 | headers: { 'Content-Type': 'application/json' }, | |
| 1335 | body: JSON.stringify({ v: vid, p: page, t: isPageview ? 'pageview' : 'heartbeat' }), | |
| 1336 | keepalive: true | |
| 1337 | }) | |
| 1338 | } | |
| 1339 | ping() | |
| 1340 | setInterval(ping, 10000) | |
| 1341 | let lastPath = location.pathname + location.hash | |
| 1342 | setInterval(() => { | |
| 1343 | if (location.pathname + location.hash !== lastPath) { | |
| 1344 | lastPath = location.pathname + location.hash | |
| 1345 | currentPage = '' | |
| 1346 | ping() | |
| 1347 | } | |
| 1348 | }, 1000) | |
| 1349 | } | |
| 1350 | ||
| 1318 | 1351 | // Icon tooltip: fixed-position popup appended to <body> to escape table overflow clipping |
| 1319 | 1352 | const tooltipEl = document.createElement('div') |
| 1320 | 1353 | tooltipEl.className = 'icon-tip-popup' |