feat: only set as session cookie if no conscent

This commit is contained in:
alistair3149 2021-03-22 13:33:17 -04:00
parent 63da182147
commit b850797b4d
No known key found for this signature in database
GPG key ID: 94D081060FD3DD9C

View file

@ -7,11 +7,25 @@
var prefersColorSchemeDarkQuery,
userTheme,
theme,
setCookieChangeTheme;
setCookieChangeTheme,
hasCookieConscent,
cookieOptions;
setCookieChangeTheme = function ( themeName ) {
try {
window.mw.cookie.set( 'skin-citizen-theme', themeName, { sameSite: 'Strict' } );
cookieOptions = {};
// The cookie is only used on the site
cookieOptions.sameSite = 'Strict';
// Check if Extension:CookieWarning is enabled
if ( window.mw.loader.getState( 'ext.CookieWarning' ) ) {
// Set the cookie as a session cookie if no conscent is given
hasCookieConscent = window.mw.cookie.get( 'cookiewarning_dismissed' ) === true ||
window.mw.user.options.get( 'cookiewarning_dismissed' ) === 1;
if ( !hasCookieConscent ) {
cookieOptions.expires = null;
}
}
window.mw.cookie.set( 'skin-citizen-theme', themeName, cookieOptions );
} catch ( e ) {
}