Skip to content

Instantly share code, notes, and snippets.

@bigdawggi
Created October 19, 2022 21:39
Show Gist options
  • Save bigdawggi/a99ff10cf6a5cc67fc41932d1cb1dda9 to your computer and use it in GitHub Desktop.
Save bigdawggi/a99ff10cf6a5cc67fc41932d1cb1dda9 to your computer and use it in GitHub Desktop.
JavaScript Bookmarklet for Adding a cookie to your current domain
javascript: (() => {
const COOKIE_NAME = 'FOOBAR';
const COOKIE_VALUE = 1;
/**
* Should we show the alert popup after setting the cookie?
*/
const SHOULD_ALERT = true;
var date = new Date();
date.setYear(date.getFullYear() + 1);
var origHost = window.location.host;
var domain = origHost.split('.').splice(-2).join('.');
document.cookie = `${COOKIE_NAME}=${COOKIE_VALUE}; SameSite=None; Secure; Domain=.${domain}; Path=/; Expires=${date.toGMTString()}`;
if (SHOULD_ALERT) {
alert(`Set ${COOKIE_NAME} cookie`);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment