Skip to content

Setting cookies? #21

Closed Answered by uBlock-user
peace2000 asked this question in Q&A
Apr 6, 2023 · 1 comments · 15 replies
Discussion options

You must be logged in to vote
/// setCookie.js
// example.com##+js(setCookie, SOCS, CAESEwgDEgk1MjE4NjcxMTIaAmVuIAEaBgiAl7ihBg)
function( 
	cName = '', 
	cValue = '',
	expTime = '',
	behavior = '' 
) {
	let timer = undefined;
	if ( cName === '' ) { return; }
	if ( expTime === '' ) { expTime = '1'; }
	if ( cValue === '' ) { cValue = '""'; }	
	const setCookie = () => {
		try {
			const cookies = document.cookie;
			if ( !cookies.includes(cName) || !cookies.includes(cValue) ) {
		      		const date = new Date();
				date.setTime(date.getTime() + (expTime * 24 * 60 * 60 * 1000));
				const expires = "expires=" + date.toUTCString();
				document.cookie = cName + "=" + cValue + "; " + expires + "; path=/";
			} else { 
				…

Replies: 1 comment 15 replies

Comment options

You must be logged in to vote
15 replies
@uBlock-user
Comment options

@uBlock-user
Comment options

@peace2000
Comment options

@uBlock-user
Comment options

@peace2000
Comment options

Answer selected by uBlock-user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants