Created
June 6, 2013 00:55
-
-
Save titanew/5718565 to your computer and use it in GitHub Desktop.
about cookie
This file contains hidden or 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() { | |
function getCookie(name) { | |
var cookie = document.cookie; | |
var s = removeBlanks(cookie); | |
var pairs = s.split(";"); | |
for (var i = 0; i < pairs.length; i++) { | |
var pairSplit = pairs[i].split("="); | |
if (pairSplit.length > 1 && pairSplit[0] == name) { | |
return pairSplit[1]; | |
} | |
} | |
return ""; | |
} | |
function removeBlanks(s) { | |
var temp = ""; | |
for (var i = 0; i < s.length; i++) { | |
var c = s.charAt(i); | |
if (c != " ") { | |
temp += c; | |
} | |
} | |
return temp; | |
} | |
function setCookie(name, value) { | |
var d = new Date(); | |
d.setTime(d.getTime() + 360 * 24 * 60 * 60 * 1000); | |
var newCookie = name + "=" + value + ";" + "path=/;domain=.rubyless.com;expires=" + d.toGMTString(); | |
window.document.cookie = newCookie; | |
} | |
function getMstuid() { | |
var d = new Date(); | |
var mstuid = d.getTime() + "_" + Math.round(Math.random() * 10000); | |
return mstuid; | |
} | |
function creatSrcipt(url) { | |
var o = document.createElement('script'); | |
o.type = 'text/javascript'; | |
o.async = true; | |
o.src = url; | |
var s = document.getElementsByTagName('script')[0]; | |
s.parentNode.insertBefore(o, s); | |
} | |
function bind(oTarget, sEventType, fnHandler) { | |
if (oTarget.addEventListener) { //firefox | |
oTarget.addEventListener(sEventType, fnHandler, false); | |
} else if (oTarget.attachEvent) { //IE | |
oTarget.attachEvent("on" + sEventType, fnHandler); | |
} else { | |
oTarget["on" + sEventType] = fnHandler; | |
} | |
} | |
function stopDefault(e) { | |
if (e && e.preventDefault) { | |
e.preventDefault(); | |
} else { | |
event.returnValue = false; | |
} | |
} | |
var uri = document.location.href.replace(/&/g, '|'); | |
var ref = document.referrer.replace(/&/g, '|'); | |
var phpsessid = getCookie("PHPSESSID"); | |
var mstuid = getCookie("mstuid"); | |
var muuid = getCookie("muuid"); | |
var mucid = getCookie("mucid"); | |
var mstlastpid = getCookie("mstlastpid"); | |
if (mstuid === "") { | |
mstuid = getMstuid(); | |
setCookie("mstuid", mstuid); | |
} | |
var d2 = new Date(); | |
var param = "phpsessid=" + phpsessid + "&mstuid=" + mstuid + "&muuid=" + muuid + "&mucid=" + mucid + "&mstpid=" + mstlastpid + "×tamp=" + d2.getTime() + "&ref=" + encodeURIComponent(ref), | |
url = "http://xxx.com/js/mstr.js?"; | |
creatSrcipt(url + param); | |
var allLinks = document.getElementsByTagName("a"); | |
for (var i = 0; i < allLinks.length; i++) { | |
var mstObj = allLinks[i], | |
pid = mstObj.getAttribute("mstpid"); | |
if (pid) { | |
bind(mstObj, "click", function(e) { | |
var pid = this.getAttribute("mstpid"), | |
gid = this.getAttribute("mstgid"), | |
src = this.getAttribute("href"); | |
stopDefault(e); | |
if (mstlastpid != pid) { | |
document.cookie = "mstlastpid=" + pid + name + ";" + "path=/;domain=.rubyless.com"; | |
} | |
var paramNew = "mstpid=" + pid + "&mstgid=" + gid + "&mstlastpid=" + mstlastpid + "&" + param + "&target=" + src; | |
creatSrcipt(url + paramNew); | |
window.setTimeout(function() { | |
window.location = src; | |
}, 200); | |
}); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment