Patch updateCookie for preserve extra args (like domain)

This commit is contained in:
Féry Mathieu (Mathius) 2022-02-22 20:05:22 +01:00
parent ad6b29c09f
commit aa8758dec2
No known key found for this signature in database
GPG key ID: F9CCC80C18A59037

View file

@ -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;
}