Skip to content

Instantly share code, notes, and snippets.

@ultim8k
Last active August 7, 2018 15:38
Show Gist options
  • Save ultim8k/56f95f54a0c96ee8b80196660fcfd147 to your computer and use it in GitHub Desktop.
Save ultim8k/56f95f54a0c96ee8b80196660fcfd147 to your computer and use it in GitHub Desktop.

Bookmarklet: [🍪]("javascript:(function(){window.biscuit=(()=>({getCookie: cookieName => document.cookie.split(';').map(item=>item.split('=').map(name=>name.trim())).map(item=>({name: item[0], value: item[1]})).find(item => item.name === cookieName), setCookie: (cookieName, cookieValue) => document.cookie = ${cookieName}=${cookieValue} }))(); })();")

// Long
const Oreo = (function Biscuit () {
const readRawCookies = () => document.cookie;
const writeRawCookies = cookie => document.cookie = cookie;
const parseRawCookie = rawCookie => {
const [key, val] = rawCookie.split('=').map(item=>item.trim());
return {
name: key,
value: val
}
};
const createCookie = (name, value) => `${name}=${value}`;
const nameMatches = item => item.name === name;
const parseCookies = rawCookies => rawCookies.split(';').map(parseRawCookie);
const getCookie = name => parseCookies(readRawCookies()).find(nameMatches);
const setCookie = (name, value) => writeRawCookies(createCookie(name, value));
return {
getCookie,
setCookie
};
})();
// Oreo Mini
const OreoMini = (()=>({
getCookie: cookieName => document.cookie.split(';').map(item=>item.split('=').map(name=>name.trim())).map(item=>({name: item[0], value: item[1]})).find(item => item.name === cookieName),
setCookie: (cookieName, cookieValue) => document.cookie = `${cookieName}=${cookieValue}`
}))();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment