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