summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--resume/resume.html3
-rw-r--r--resume/resume.js71
2 files changed, 34 insertions, 40 deletions
diff --git a/resume/resume.html b/resume/resume.html
index f8e149c..03f9bf7 100644
--- a/resume/resume.html
+++ b/resume/resume.html
@@ -11,9 +11,6 @@
<link rel="stylesheet" href="resume.css">
</head>
<body>
- <div id="ie" style="font-size:2em;display:none">
- Internet Explorer does not support the web standards used on this page. Please upgrade to a modern browser such as <a href="https://firefox.com">Mozilla Firefox</a>, <a href="https://microsoft.com/edge">Microsoft Edge</a>, or <a href="https://google.com/chrome">Google Chrome</a>.
- </div>
<div class="right title">
<h1>Alex Xu</h1>
<p class="h1s">Generalist software developer</p>
diff --git a/resume/resume.js b/resume/resume.js
index adcb7de..4f66f24 100644
--- a/resume/resume.js
+++ b/resume/resume.js
@@ -1,55 +1,52 @@
-(function(w, d, a){
+(document => {
'use strict';
- const b = () => {
- for (let el of d.getElementsByTagName('a')) {
- const h = el.href.replace(/javascript:location=(.*);void 0/, '$1');
+ 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 (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 (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 t, p = [];
- const f = () => {
- clearTimeout(t);
- navigator.sendBeacon('/analytics', new Blob([JSON.stringify(p)], {type: 'application/json'}));
- p = [];
+ let timeout, pending = [];
+ const flush = () => {
+ clearTimeout(timeout);
+ navigator.sendBeacon('/analytics', new Blob([JSON.stringify(pending)], {type: 'application/json'}));
+ pending = [];
};
- const q = (kind, details) => {
- clearTimeout(t);
- p.push({created_ts: Date.now(), kind: kind, details: details});
- t = setTimeout(f, 2000);
+ const queue = (kind, details) => {
+ clearTimeout(timeout);
+ pending.push({created_ts: Date.now(), kind: kind, details: details});
+ timeout = setTimeout(flush, 2000);
};
- q('l', '');
- d[a]('visibilitychange', () => {
- const vs = d.visibilityState;
- q('v', vs);
- if (vs === 'hidden')
- f();
+ queue('l', '');
+ document.addEventListener('visibilitychange', () => {
+ queue('v', document.visibilityState);
+ if (document.visibilityState === 'hidden')
+ flush();
});
- d[a]('click', e => {
+ document.addEventListener('click', e => {
const a = e.target.closest('a');
if (a)
- q('c', a.href);
+ queue('c', a.href);
});
- w[a]('beforeprint', b);
- w[a]('afterprint', function () {
- for (let el of d.getElementsByTagName('a')) {
+ 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 {
- b();
+ mangleurls();
}
- 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);
+ 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 (w.chrome)
- css.insertRule("@media print{@page{margin-top:auto;margin-bottom:auto}}", css.cssRules.length);
-}(window, document, 'addEventListener'));
+ 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);