summaryrefslogtreecommitdiff
path: root/resume/resume.js
blob: adcb7de2616a38cd5ed5368b40ddf2f2a25dcbcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(function(w, d, a){
    'use strict';
    const b = () => {
        for (let el of d.getElementsByTagName('a')) {
            const h = el.href.replace(/javascript:location=(.*);void 0/, '$1');
            el.setAttribute('data-href', el.href);
            if (h != el.href) el.href = eval(h);
            else el.href = "https://alxu.ca/analytics?url=" + el.href.replace(/%/g, '%25').replace(/&/g, '%26').replace(/;/g, '%3B');
        }
    };
    if (location.hostname === 'www.alxu.ca') {
        let t, p = [];
        const f = () => {
            clearTimeout(t);
            navigator.sendBeacon('/analytics', new Blob([JSON.stringify(p)], {type: 'application/json'}));
            p = [];
        };
        const q = (kind, details) => {
            clearTimeout(t);
            p.push({created_ts: Date.now(), kind: kind, details: details});
            t = setTimeout(f, 2000);
        };
        q('l', '');
        d[a]('visibilitychange', () => {
            const vs = d.visibilityState;
            q('v', vs);
            if (vs === 'hidden')
                f();
        });
        d[a]('click', e => {
            const a = e.target.closest('a');
            if (a)
                q('c', a.href);
        });
        w[a]('beforeprint', b);
        w[a]('afterprint', function () {
            for (let el of d.getElementsByTagName('a')) {
                el.href = el.getAttribute('data-href');
                el.removeAttribute('data-href');
            }
        });
    } else {
        b();
    }
    if (d.documentMode)
        ie.style.display = "block";
    const css = d.styleSheets[0];
    // changing @page causes chrome to claim layout shift
    if (w.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 (w.chrome)
        css.insertRule("@media print{@page{margin-top:auto;margin-bottom:auto}}", css.cssRules.length);
}(window, document, 'addEventListener'));