Patch updateCookie for preserve extra args (like domain)

pull/2895/head
Féry Mathieu (Mathius) 3 years ago
parent ad6b29c09f
commit aa8758dec2
No known key found for this signature in database
GPG Key ID: F9CCC80C18A59037

@ -198,12 +198,15 @@ function updateCookie(newVolume, newSpeed) {
var volumeValue = newVolume != null ? newVolume : video_data.params.volume;
var speedValue = newSpeed != null ? newSpeed : video_data.params.speed;
var cookieValue = getCookieValue('PREFS');
var cookieData;
if (cookieValue != null) {
var cookieJson = JSON.parse(decodeURIComponent(cookieValue));
cookieJson.volume = volumeValue;
cookieJson.speed = speedValue;
document.cookie = document.cookie.replace(getCookieValue('PREFS'), encodeURIComponent(JSON.stringify(cookieJson)));
cookieData = encodeURIComponent(JSON.stringify(cookieJson));
} else {
cookieData = encodeURIComponent(JSON.stringify({ 'volume': volumeValue, 'speed': speedValue }));
}
var date = new Date();
// Set expiration in 2 year
date.setTime(date.getTime() + 63115200);
@ -212,10 +215,8 @@ function updateCookie(newVolume, newSpeed) {
var domainUsed = window.location.hostname;
if (!ipv4Regex.test(domainUsed) && !ipv6Regex.test(domainUsed) && domainUsed != 'localhost')
domainUsed = '.' + window.location.hostname;
document.cookie = 'PREFS=' +
encodeURIComponent(JSON.stringify({ 'volume': volumeValue, 'speed': speedValue })) +
'; SameSite=Strict; path=/; domain=' + domainUsed + '; expires=' + date.toGMTString() + ';';
}
document.cookie = 'PREFS=' + cookieData + '; SameSite=Strict; path=/; domain=' +
domainUsed + '; expires=' + date.toGMTString() + ';';
video_data.params.volume = volumeValue;
video_data.params.speed = speedValue;
}

Loading…
Cancel
Save