Skip to content

Instantly share code, notes, and snippets.

@yahelc
Last active December 21, 2015 19:28
Show Gist options
  • Save yahelc/6354070 to your computer and use it in GitHub Desktop.
Save yahelc/6354070 to your computer and use it in GitHub Desktop.
BSD SPUD-less Sourcing Script
(function(){
var get = (function() {
var map = {};
location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, k, v) {
map[k] = v;
});
return map;
} ());
function readCookie(a){return(RegExp("(?:^|; )"+a+"=([^;]*)").exec(document.cookie)||[]).pop();}
function createCookie(name,value,days) {
var expires = days ? "; expires=" + (new Date(days*864E5 + (new Date()).getTime())).toGMTString() :"";
document.cookie = name+"="+value+expires+"; path=/; domain="+ location.hostname.split(".").slice(-2).join(".");
}
if(get.source && get.source !== readCookie("source")){
createCookie("source", get.source, 180);
}
if(get.subsource && get.subsource !== readCookie("subsource")){
createCookie("subsource", get.subsource, 180);
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment