summaryrefslogtreecommitdiffstats
path: root/assets
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2022-04-09 19:58:49 +0200
committerSamantaz Fox <coding@samantaz.fr>2022-04-09 19:58:49 +0200
commit6aa7db2358c3c329ca3340a9087291bd36faf54a (patch)
treecca043880db70dff367f43079484b9f8e98f7b88 /assets
parente66b317f020d4e18ed0e924d1c8f81a80fdb78f2 (diff)
downloadinvidious-6aa7db2358c3c329ca3340a9087291bd36faf54a.tar.gz
invidious-6aa7db2358c3c329ca3340a9087291bd36faf54a.tar.bz2
invidious-6aa7db2358c3c329ca3340a9087291bd36faf54a.zip
Minor code/comments cleaning
Diffstat (limited to 'assets')
-rw-r--r--assets/js/player.js24
1 files changed, 18 insertions, 6 deletions
diff --git a/assets/js/player.js b/assets/js/player.js
index 4681340f..b694a34b 100644
--- a/assets/js/player.js
+++ b/assets/js/player.js
@@ -180,25 +180,32 @@ player.volume(video_data.params.volume / 100);
player.playbackRate(video_data.params.speed);
/**
- * Method for get content of Cookie
+ * Method for getting the contents of a cookie
+ *
* @param {String} name Name of cookie
* @returns cookieValue
*/
function getCookieValue(name) {
var value = document.cookie.split(";").filter(item => item.includes(name + "="));
- return value != null && value.length >= 1 ? value[0].substring((name + "=").length, value[0].length) : null;
+
+ return (value != null && value.length >= 1)
+ ? value[0].substring((name + "=").length, value[0].length)
+ : null;
}
/**
- * Method for update Prefs cookie (Or create if missing)
- * @param {number} newVolume New Volume defined (Null if unchanged)
- * @param {number} newSpeed New Speed defined (Null if unchanged)
+ * Method for updating the "PREFS" cookie (or creating it if missing)
+ *
+ * @param {number} newVolume New volume defined (null if unchanged)
+ * @param {number} newSpeed New speed defined (null if unchanged)
*/
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;
@@ -207,15 +214,20 @@ function updateCookie(newVolume, newSpeed) {
} else {
cookieData = encodeURIComponent(JSON.stringify({ 'volume': volumeValue, 'speed': speedValue }));
}
- var date = new Date();
+
// Set expiration in 2 year
+ var date = new Date();
date.setTime(date.getTime() + 63115200);
+
var ipRegex = /^((\d+\.){3}\d+|[A-Fa-f0-9]*:[A-Fa-f0-9:]*:[A-Fa-f0-9:]+)$/;
var domainUsed = window.location.hostname;
+
if (!ipRegex.test(domainUsed) && domainUsed != 'localhost')
domainUsed = '.' + window.location.hostname;
+
document.cookie = 'PREFS=' + cookieData + '; SameSite=Strict; path=/; domain=' +
domainUsed + '; expires=' + date.toGMTString() + ';';
+
video_data.params.volume = volumeValue;
video_data.params.speed = speedValue;
}