(document => { 'use strict'; const mangleurls = () => { for (let el of document.getElementsByTagName('a')) { const href = el.href.replace(/^javascript:location=(.*);void 0$/, '$1'); el.setAttribute('data-href', el.href); if (href != el.href) el.href = eval(href); else el.href = 'https://alxu.ca/analytics?url=' + href.replace(/[%&;]/g, s=>'%'+s.charCodeAt(0).toString(16)); } }; if (location.hostname === 'www.alxu.ca') { let timeout, pending = []; const flush = () => { clearTimeout(timeout); navigator.sendBeacon('/analytics', new Blob([JSON.stringify(pending)], {type: 'application/json'})); pending = []; }; const queue = (kind, details) => { clearTimeout(timeout); pending.push({created_ts: Date.now(), kind: kind, details: details}); timeout = setTimeout(flush, 2000); }; queue('l', ''); document.addEventListener('visibilitychange', () => { queue('v', document.visibilityState); if (document.visibilityState === 'hidden') flush(); }); document.addEventListener('click', e => { const a = e.target.closest('a'); if (a) queue('c', a.href); }); window.addEventListener('beforeprint', mangleurls); window.addEventListener('afterprint', () => { for (let el of document.getElementsByTagName('a')) { el.href = el.getAttribute('data-href'); el.removeAttribute('data-href'); } }); } else { mangleurls(); } const css = document.styleSheets[0]; if (window.safari) { css.insertRule('@media print{@page{margin:10mm}}', css.cssRules.length); css.insertRule('@media print{body{margin:-2mm 0 -2mm 0;padding:0 15mm 0 7mm}}', css.cssRules.length); } else if (window.chrome) // changing @page causes chrome to claim layout shift even in non-print css.insertRule('@media print{@page{margin-top:auto;margin-bottom:auto}}', css.cssRules.length); })(document);