Created
October 19, 2022 21:39
-
-
Save bigdawggi/a99ff10cf6a5cc67fc41932d1cb1dda9 to your computer and use it in GitHub Desktop.
JavaScript Bookmarklet for Adding a cookie to your current domain
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
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