summaryrefslogtreecommitdiff
path: root/resume/resume.js
diff options
context:
space:
mode:
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2021-10-03 15:03:42 -0400
committerAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2021-10-03 15:03:42 -0400
commit7dccf6e8684f767b6e377d627b36ccf493947f1e (patch)
tree4859d4e1a24ea2028de1366bc59cd28e6782a6d1 /resume/resume.js
downloadalxu.ca-7dccf6e8684f767b6e377d627b36ccf493947f1e.tar.xz
alxu.ca-7dccf6e8684f767b6e377d627b36ccf493947f1e.zip
Initial commit
Diffstat (limited to 'resume/resume.js')
-rw-r--r--resume/resume.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/resume/resume.js b/resume/resume.js
new file mode 100644
index 0000000..3f33976
--- /dev/null
+++ b/resume/resume.js
@@ -0,0 +1,51 @@
+(function(w, d, a){
+ 'use strict';
+ if (d.documentMode)
+ ie.style.display = "block";
+ else
+ ie.parentNode.removeChild(ie);
+ const css = d.styleSheets[0];
+ if (w.safari) {
+ css.insertRule("@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("@page{margin-top:auto;margin-bottom:auto}", css.cssRules.length);
+ 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', () => {
+ 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');
+ }
+ });
+ w[a]('afterprint', function () {
+ for (let el of d.getElementsByTagName('a')) {
+ el.href = el.getAttribute('data-href');
+ el.removeAttribute('data-href');
+ }
+ });
+}(window, document, 'addEventListener'));