summaryrefslogtreecommitdiff
path: root/resume/resume.js
diff options
context:
space:
mode:
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2022-06-01 20:59:06 -0400
committerAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2022-06-01 20:59:06 -0400
commit60cea36e4deda33142cb641534abe3e7a698ebde (patch)
tree049055e0b06fc2aeaf2c313258a56cb7f2dcd0fb /resume/resume.js
parent98fac0582ab755abfd721a494b4e8f53e5797095 (diff)
downloadalxu.ca-master.tar.xz
alxu.ca-master.zip
Diffstat (limited to 'resume/resume.js')
-rw-r--r--resume/resume.js67
1 files changed, 31 insertions, 36 deletions
diff --git a/resume/resume.js b/resume/resume.js
index 4f66f24..500b49c 100644
--- a/resume/resume.js
+++ b/resume/resume.js
@@ -1,46 +1,41 @@
(document => {
'use strict';
- const mangleurls = () => {
+ let timeout, pending = [];
+ const flush = () => {
+ clearTimeout(timeout);
+ navigator.sendBeacon('https://www.alxu.ca/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', () => {
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));
+ else el.href = 'https://www.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();
- }
+ });
+ window.addEventListener('afterprint', () => {
+ for (let el of document.getElementsByTagName('a')) {
+ el.href = el.getAttribute('data-href');
+ el.removeAttribute('data-href');
+ }
+ });
const css = document.styleSheets[0];
if (window.safari) {
css.insertRule('@media print{@page{margin:10mm}}', css.cssRules.length);