mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-04-11.git
synced 2024-08-15 00:43:26 +00:00
Minor code/comments cleaning
This commit is contained in:
parent
e66b317f02
commit
6aa7db2358
1 changed files with 18 additions and 6 deletions
|
@ -180,25 +180,32 @@ player.volume(video_data.params.volume / 100);
|
||||||
player.playbackRate(video_data.params.speed);
|
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
|
* @param {String} name Name of cookie
|
||||||
* @returns cookieValue
|
* @returns cookieValue
|
||||||
*/
|
*/
|
||||||
function getCookieValue(name) {
|
function getCookieValue(name) {
|
||||||
var value = document.cookie.split(";").filter(item => item.includes(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)
|
* 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)
|
* @param {number} newVolume New volume defined (null if unchanged)
|
||||||
|
* @param {number} newSpeed New speed defined (null if unchanged)
|
||||||
*/
|
*/
|
||||||
function updateCookie(newVolume, newSpeed) {
|
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;
|
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;
|
||||||
|
@ -207,15 +214,20 @@ function updateCookie(newVolume, newSpeed) {
|
||||||
} else {
|
} else {
|
||||||
cookieData = encodeURIComponent(JSON.stringify({ 'volume': volumeValue, 'speed': speedValue }));
|
cookieData = encodeURIComponent(JSON.stringify({ 'volume': volumeValue, 'speed': speedValue }));
|
||||||
}
|
}
|
||||||
var date = new Date();
|
|
||||||
// Set expiration in 2 year
|
// Set expiration in 2 year
|
||||||
|
var date = new Date();
|
||||||
date.setTime(date.getTime() + 63115200);
|
date.setTime(date.getTime() + 63115200);
|
||||||
|
|
||||||
var ipRegex = /^((\d+\.){3}\d+|[A-Fa-f0-9]*:[A-Fa-f0-9:]*:[A-Fa-f0-9:]+)$/;
|
var ipRegex = /^((\d+\.){3}\d+|[A-Fa-f0-9]*:[A-Fa-f0-9:]*:[A-Fa-f0-9:]+)$/;
|
||||||
var domainUsed = window.location.hostname;
|
var domainUsed = window.location.hostname;
|
||||||
|
|
||||||
if (!ipRegex.test(domainUsed) && domainUsed != 'localhost')
|
if (!ipRegex.test(domainUsed) && domainUsed != 'localhost')
|
||||||
domainUsed = '.' + window.location.hostname;
|
domainUsed = '.' + window.location.hostname;
|
||||||
|
|
||||||
document.cookie = 'PREFS=' + cookieData + '; SameSite=Strict; path=/; domain=' +
|
document.cookie = 'PREFS=' + cookieData + '; SameSite=Strict; path=/; domain=' +
|
||||||
domainUsed + '; expires=' + date.toGMTString() + ';';
|
domainUsed + '; expires=' + date.toGMTString() + ';';
|
||||||
|
|
||||||
video_data.params.volume = volumeValue;
|
video_data.params.volume = volumeValue;
|
||||||
video_data.params.speed = speedValue;
|
video_data.params.speed = speedValue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue