Skip to content

Instantly share code, notes, and snippets.

@hitGovernor
Created February 3, 2020 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitGovernor/f2e935bec2260b6b578958d53f6a54b0 to your computer and use it in GitHub Desktop.
Save hitGovernor/f2e935bec2260b6b578958d53f6a54b0 to your computer and use it in GitHub Desktop.
ens_cookieModuleFix.js
//Begin Cookie Module
//Pull Date: 10-17-18
//Be sure to update domain to top level domain of client website
// @updated 01-22-2020 bjohnson@evolytics.com update set() to account for sameSite + Secure
Bootstrapper.Cookies = function () {
return {
domain: 'intuit.com' || location.hostname,
get: function (a, c) {
for (var b = document.cookie.split(";"), d = 0; d < b.length; d++) {
var e = b[d].replace(/^\s+/, "").split("=");
if (e[0] == a) return c ? e[1] : decodeURIComponent(e[1])
}
return ""
},
/**
* creates or updates the specified cookie
* @param a {string} cookie name
* @param c cookie expiration date/time
* @param b {string} cookie value
* @param ss {string} sameSite setting
* @param sec {string} secure setting
*/
set: function (a, c, b, ss, sec) {
var sameSite = (ss) ? ss : 'None',
isSecure = sec ? sec : '';
if (/none/i.test(sameSite) || isSecure == true) {
isSecure = 'Secure';
}
document.cookie = a + "=" + encodeURIComponent(c) + (b ? ";expires=" + b : "") + ";path=/;domain=" + Bootstrapper.Cookies.domain + ";SameSite=" + sameSite + ";" + isSecure;
return Bootstrapper.Cookies.get(a) == c
},
// original, unmodified:
// set: function(a, c, b) {
// document.cookie = a + "=" + encodeURIComponent(c) + (b ? ";expires=" + b : "") + ";path=/;domain=" + Bootstrapper.Cookies.domain + ((/https:/.test(location.protocol) === true) ? ";secure" : ";");
// return Bootstrapper.Cookies.get(a) == c
// },
test: function (a) {
return this.get(a) ? !0 : !1
},
remove: function (a) {
document.cookie = a + '="";expires=' + new Date(0).toUTCString() + ';path=/;domain=' + this.domain;
return this.get(a) === '' ? true : false;
}
}
}();
//End Cookie Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment