Last active
April 21, 2016 20:43
-
-
Save Opus1no2/ddc2454a2f7fca9e3c62a24fbb202e23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (w) { | |
var referrer, | |
currentDomain, | |
domainPattern = /^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)/im; | |
function isArrayWithLength(array) { | |
if (Array.isArray(array) && array.length === 2) { | |
return array[1]; | |
} | |
} | |
function uuid() { | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | |
var r = Math.random()*16|0, | |
v = c == 'x' ? r : (r&0x3|0x8); | |
return v.toString(16); | |
}); | |
} | |
function main() { | |
referrerMatch = document.referrer.match(domainPattern); | |
currentMatch = window.location.href.match(domainPattern); | |
referrer = isArrayWithLength(referrerMatch); | |
currentDomain = isArrayWithLength(currentMatch); | |
if (referrer === undefined || !new RegExp(referrer).test(currentDomain)) { | |
if (localStorage.getItem('olab-session-token')) { | |
localStorage.removeItem('olab-session-token'); | |
} | |
localStorage.setItem('olab-session-token', uuid()); | |
console.log('POST DATA'); | |
} | |
if (referrer && new RegExp(referrer).test(currentDomain)) { | |
if (localStorage.getItem('olab-session-token') === undefined) { | |
localStorage.setItem('olab-session-token', uuid()); | |
} | |
console.log('POST DATA'); | |
} | |
} | |
w.onload = main; | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment