diff options
| author | Felix Hanley <felix@userspace.com.au> | 2020-02-21 08:27:42 +0000 |
|---|---|---|
| committer | Felix Hanley <felix@userspace.com.au> | 2020-02-21 08:27:42 +0000 |
| commit | b25a204138d82d0b8c29eaf81003cc6b5553d58f (patch) | |
| tree | 4b4bebcf5f8ce807a463ab97cb7768da07b5aee5 /counter | |
| parent | d68c6aad01c2f6e7f30389536152e1f96682b5cd (diff) | |
| download | sws-b25a204138d82d0b8c29eaf81003cc6b5553d58f.tar.gz sws-b25a204138d82d0b8c29eaf81003cc6b5553d58f.tar.bz2 | |
Add HitSet and associated interfaces for charts and reuse
Diffstat (limited to 'counter')
| -rw-r--r-- | counter/sws.js | 28 | ||||
| -rw-r--r-- | counter/test.html | 19 |
2 files changed, 14 insertions, 33 deletions
diff --git a/counter/sws.js b/counter/sws.js index 6995bbb..56a283e 100644 --- a/counter/sws.js +++ b/counter/sws.js @@ -1,27 +1,28 @@ var d = document -var de = document.documentElement +var de = d.documentElement var w = window var l = d.location var n = w.navigator var esc = encodeURIComponent -var me = document.currentScript -console.log('me:', me) -console.log('me.sws:', me.dataset.sws) +var me = d.currentScript -var _sws = w._sws || {noxhr: false, noauto: false} -console.log('_sws:', _sws) -_sws.d = _sws.d || me.dataset.sws || 'http://sws.userspace.com.au/sws.gif' +var _sws = w._sws || {noauto: false} +_sws.d = _sws.d || me.src _sws.site = _sws.site || me.dataset.site -console.log('using', _sws.d) function count (p, obj) { - console.log('sending', p, JSON.stringify(obj)) + if (l.hostname.match(/(localhost$|^127\.|^10\.|^172\.16\.|^192\.168\.)/)) + return + if ('visibilityState' in d && d.visibilityState === 'prerender') + return + var qs = Object.keys(obj) .map(function (k) { return esc(k) + '=' + esc(obj[k]) }) .join('&') - if (!_sws.xhr) { + + if (!_sws.noxhr) { var r = new w.XMLHttpRequest() r.open('GET', p + '?' + qs, true) r.send() @@ -32,9 +33,7 @@ function count (p, obj) { } function ready (fn) { - if (d.attachEvent - ? d.readyState === 'complete' - : d.readyState !== 'loading') { + if (d.attachEvent ? d.readyState === 'complete' : d.readyState !== 'loading') { fn() } else { d.addEventListener('DOMContentLoaded', fn) @@ -46,7 +45,8 @@ var viewPort = (w.innerWidth || de.clientWidth || d.body.clientWidth) + 'x' + ready(function () { if (!_sws.noauto) { - count(_sws.d, { + var ep = new URL(_sws.d) + count(ep.protocol+'//'+ep.host+'/sws.gif', { i: _sws.site, s: l.protocol, h: l.host, diff --git a/counter/test.html b/counter/test.html deleted file mode 100644 index ef2f621..0000000 --- a/counter/test.html +++ /dev/null @@ -1,19 +0,0 @@ -<!doctype html> -<html> - <head> - <meta charset="utf-8"> - <script> - var _sws = { - title: "test title" - } - </script> - <script async src="http://localhost:5000/sws.js"></script> - <title>This is the title</title> - <noscript> - <img src="http://localhost:5000/sws.gif?s=http%3A&h=localhost%3A5000&p=%2F?noscript&r=&u=Mozilla%2F5.0%20(Windows%20NT%2010.0%3B%20Win64%3B%20x64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F69.0.3497.32%20Safari%2F537.36&v=1916x563" /> - </noscript> - </head> - <body> - <a href="?referred">test</a> - </body> -</html> |
