mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-03-16.git
synced 2024-08-15 00:53:18 +00:00
Move store of modification in Cookie instead of localStorage
This commit is contained in:
parent
17ae2648ed
commit
7048193f00
4 changed files with 48 additions and 15 deletions
|
@ -176,17 +176,55 @@ if (video_data.params.video_start > 0 || video_data.params.video_end > 0) {
|
||||||
player.currentTime(video_data.params.video_start);
|
player.currentTime(video_data.params.video_start);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
player.volume(video_data.params.volume / 100);
|
||||||
If the video settings are default, we enable the management of the settings by
|
player.playbackRate(video_data.params.speed);
|
||||||
the videojs-persist module otherwise we apply the preferences.
|
|
||||||
*/
|
/**
|
||||||
if (video_data.params.volume == 100 && video_data.params.speed == "1.0")
|
* Method for get content of Cookie
|
||||||
player.persist();
|
* @param {String} name Name of cookie
|
||||||
else {
|
* @returns cookieValue
|
||||||
player.volume(video_data.params.volume / 100);
|
*/
|
||||||
player.playbackRate(video_data.params.speed);
|
function getCookieValue(name) {
|
||||||
|
var value = document.cookie.split(";").filter(item => {
|
||||||
|
return item.includes(name + "=");
|
||||||
|
});
|
||||||
|
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)
|
||||||
|
*/
|
||||||
|
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');
|
||||||
|
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)));
|
||||||
|
} else {
|
||||||
|
var date = new Date();
|
||||||
|
//Set expiration in 2 year
|
||||||
|
date.setTime(date.getTime() + 63115200);
|
||||||
|
document.cookie = 'PREFS=' +
|
||||||
|
encodeURIComponent(JSON.stringify({ 'volume': volumeValue, 'speed': speedValue })) +
|
||||||
|
'; expires=' + date.toGMTString() + '; SameSite=Strict; path=/';
|
||||||
|
}
|
||||||
|
video_data.params.volume = volumeValue;
|
||||||
|
video_data.params.speed = speedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.on('ratechange', function () {
|
||||||
|
updateCookie(null, player.playbackRate());
|
||||||
|
});
|
||||||
|
|
||||||
|
player.on('volumechange', function () {
|
||||||
|
updateCookie(Math.ceil(player.volume() * 100), null);
|
||||||
|
});
|
||||||
|
|
||||||
player.on('waiting', function () {
|
player.on('waiting', function () {
|
||||||
if (player.playbackRate() > 1 && player.liveTracker.isLive() && player.liveTracker.atLiveEdge()) {
|
if (player.playbackRate() > 1 && player.liveTracker.isLive() && player.liveTracker.atLiveEdge()) {
|
||||||
console.log('Player has caught up to source, resetting playbackRate.')
|
console.log('Player has caught up to source, resetting playbackRate.')
|
||||||
|
|
|
@ -30,7 +30,7 @@ struct Invidious::User
|
||||||
value: URI.encode_www_form(preferences.to_json),
|
value: URI.encode_www_form(preferences.to_json),
|
||||||
expires: Time.utc + 2.years,
|
expires: Time.utc + 2.years,
|
||||||
secure: SECURE,
|
secure: SECURE,
|
||||||
http_only: true
|
http_only: false
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
<script src="/videojs/videojs-contrib-quality-levels/videojs-contrib-quality-levels.js?v=<%= ASSET_COMMIT %>"></script>
|
<script src="/videojs/videojs-contrib-quality-levels/videojs-contrib-quality-levels.js?v=<%= ASSET_COMMIT %>"></script>
|
||||||
<script src="/videojs/videojs-http-source-selector/videojs-http-source-selector.js?v=<%= ASSET_COMMIT %>"></script>
|
<script src="/videojs/videojs-http-source-selector/videojs-http-source-selector.js?v=<%= ASSET_COMMIT %>"></script>
|
||||||
<script src="/videojs/videojs-markers/videojs-markers.js?v=<%= ASSET_COMMIT %>"></script>
|
<script src="/videojs/videojs-markers/videojs-markers.js?v=<%= ASSET_COMMIT %>"></script>
|
||||||
<script src="/videojs/videojs-persist/videojs-persist.js?v=<%= ASSET_COMMIT %>"></script>
|
|
||||||
<script src="/videojs/videojs-share/videojs-share.js?v=<%= ASSET_COMMIT %>"></script>
|
<script src="/videojs/videojs-share/videojs-share.js?v=<%= ASSET_COMMIT %>"></script>
|
||||||
<script src="/videojs/videojs-vtt-thumbnails/videojs-vtt-thumbnails.js?v=<%= ASSET_COMMIT %>"></script>
|
<script src="/videojs/videojs-vtt-thumbnails/videojs-vtt-thumbnails.js?v=<%= ASSET_COMMIT %>"></script>
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,6 @@ videojs-overlay:
|
||||||
version: 2.1.4
|
version: 2.1.4
|
||||||
shasum: 5a103b25374dbb753eb87960d8360c2e8f39cc05
|
shasum: 5a103b25374dbb753eb87960d8360c2e8f39cc05
|
||||||
|
|
||||||
videojs-persist:
|
|
||||||
version: 0.1.2
|
|
||||||
shasum: 44da05aced1fbf15693a36b7cce3cc4a9960dabe
|
|
||||||
|
|
||||||
videojs-share:
|
videojs-share:
|
||||||
version: 3.2.1
|
version: 3.2.1
|
||||||
shasum: 0a3024b981387b9d21c058c829760a72c14b8ceb
|
shasum: 0a3024b981387b9d21c058c829760a72c14b8ceb
|
||||||
|
|
Loading…
Reference in a new issue