mirror of
https://github.com/iv-org/invidious
synced 2024-11-27 21:43:28 +01:00
Inline a few JS functions
Helps sending less bytes to the client.
This commit is contained in:
parent
b344e1aadb
commit
53d349a648
@ -60,29 +60,19 @@ videojs.Vhs.xhr.beforeRequest = function(options) {
|
|||||||
var player = videojs('player', options);
|
var player = videojs('player', options);
|
||||||
|
|
||||||
const storage = (() => {
|
const storage = (() => {
|
||||||
try {
|
try { if (localStorage.length !== -1) return localStorage; }
|
||||||
if (localStorage.length !== -1) {
|
catch (e) { console.info('No storage available: ' + e); }
|
||||||
return localStorage;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.info('No storage available: ' + e);
|
|
||||||
}
|
|
||||||
return undefined;
|
return undefined;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
if (location.pathname.startsWith('/embed/')) {
|
if (location.pathname.startsWith('/embed/')) {
|
||||||
|
var overlay_content = '<h1><a rel="noopener" target="_blank" href="' + location.origin + '/watch?v=' + video_data.id + '">' + player_data.title + '</a></h1>';
|
||||||
player.overlay({
|
player.overlay({
|
||||||
overlays: [{
|
overlays: [
|
||||||
start: 'loadstart',
|
{ start: 'loadstart', content: overlay_content, end: 'playing', align: 'top'},
|
||||||
content: '<h1><a rel="noopener" target="_blank" href="' + location.origin + '/watch?v=' + video_data.id + '">' + player_data.title + '</a></h1>',
|
{ start: 'pause', content: overlay_content, end: 'playing', align: 'top'}
|
||||||
end: 'playing',
|
]
|
||||||
align: 'top'
|
|
||||||
}, {
|
|
||||||
start: 'pause',
|
|
||||||
content: '<h1><a rel="noopener" target="_blank" href="' + location.origin + '/watch?v=' + video_data.id + '">' + player_data.title + '</a></h1>',
|
|
||||||
end: 'playing',
|
|
||||||
align: 'top'
|
|
||||||
}]
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,9 +89,7 @@ if (isMobile()) {
|
|||||||
|
|
||||||
buttons = ["playToggle", "volumePanel", "captionsButton"];
|
buttons = ["playToggle", "volumePanel", "captionsButton"];
|
||||||
|
|
||||||
if (video_data.params.quality !== 'dash') {
|
if (video_data.params.quality !== 'dash') buttons.push("qualitySelector")
|
||||||
buttons.push("qualitySelector")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new control bar object for operation buttons
|
// Create new control bar object for operation buttons
|
||||||
const ControlBar = videojs.getComponent("controlBar");
|
const ControlBar = videojs.getComponent("controlBar");
|
||||||
@ -146,16 +134,12 @@ player.on('error', function (event) {
|
|||||||
|
|
||||||
player.load();
|
player.load();
|
||||||
|
|
||||||
if (currentTime > 0.5) {
|
if (currentTime > 0.5) currentTime -= 0.5;
|
||||||
currentTime -= 0.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
player.currentTime(currentTime);
|
player.currentTime(currentTime);
|
||||||
player.playbackRate(playbackRate);
|
player.playbackRate(playbackRate);
|
||||||
|
|
||||||
if (!paused) {
|
if (!paused) player.play();
|
||||||
player.play();
|
|
||||||
}
|
|
||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -183,13 +167,8 @@ if (video_data.params.video_start > 0 || video_data.params.video_end > 0) {
|
|||||||
|
|
||||||
player.markers({
|
player.markers({
|
||||||
onMarkerReached: function (marker) {
|
onMarkerReached: function (marker) {
|
||||||
if (marker.text === 'End') {
|
if (marker.text === 'End')
|
||||||
if (player.loop()) {
|
player.loop() ? player.markers.prev('Start') : player.pause();
|
||||||
player.markers.prev('Start');
|
|
||||||
} else {
|
|
||||||
player.pause();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
markers: markers
|
markers: markers
|
||||||
});
|
});
|
||||||
@ -217,9 +196,7 @@ if (video_data.params.save_player_pos) {
|
|||||||
const remeberedTime = get_video_time();
|
const remeberedTime = get_video_time();
|
||||||
let lastUpdated = 0;
|
let lastUpdated = 0;
|
||||||
|
|
||||||
if(!hasTimeParam) {
|
if(!hasTimeParam) set_seconds_after_start(remeberedTime);
|
||||||
set_seconds_after_start(remeberedTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateTime = () => {
|
const updateTime = () => {
|
||||||
const raw = player.currentTime();
|
const raw = player.currentTime();
|
||||||
@ -233,9 +210,7 @@ if (video_data.params.save_player_pos) {
|
|||||||
|
|
||||||
player.on("timeupdate", updateTime);
|
player.on("timeupdate", updateTime);
|
||||||
}
|
}
|
||||||
else {
|
else remove_all_video_times();
|
||||||
remove_all_video_times();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (video_data.params.autoplay) {
|
if (video_data.params.autoplay) {
|
||||||
var bpb = player.getChild('bigPlayButton');
|
var bpb = player.getChild('bigPlayButton');
|
||||||
@ -433,26 +408,10 @@ function set_time_percent(percent) {
|
|||||||
player.currentTime(newTime);
|
player.currentTime(newTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
function play() {
|
function play() { player.play(); }
|
||||||
player.play();
|
function pause() { player.pause(); }
|
||||||
}
|
function stop() { player.pause(); player.currentTime(0); }
|
||||||
|
function toggle_play() { player.paused() ? play() : pause(); }
|
||||||
function pause() {
|
|
||||||
player.pause();
|
|
||||||
}
|
|
||||||
|
|
||||||
function stop() {
|
|
||||||
player.pause();
|
|
||||||
player.currentTime(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggle_play() {
|
|
||||||
if (player.paused()) {
|
|
||||||
play();
|
|
||||||
} else {
|
|
||||||
pause();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const toggle_captions = (function () {
|
const toggle_captions = (function () {
|
||||||
let toggledTrack = null;
|
let toggledTrack = null;
|
||||||
@ -490,9 +449,7 @@ const toggle_captions = (function () {
|
|||||||
const tracks = player.textTracks();
|
const tracks = player.textTracks();
|
||||||
for (let i = 0; i < tracks.length; i++) {
|
for (let i = 0; i < tracks.length; i++) {
|
||||||
const track = tracks[i];
|
const track = tracks[i];
|
||||||
if (track.kind !== 'captions') {
|
if (track.kind !== 'captions') continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fallbackCaptionsTrack === null) {
|
if (fallbackCaptionsTrack === null) {
|
||||||
fallbackCaptionsTrack = track;
|
fallbackCaptionsTrack = track;
|
||||||
@ -513,11 +470,7 @@ const toggle_captions = (function () {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
function toggle_fullscreen() {
|
function toggle_fullscreen() {
|
||||||
if (player.isFullscreen()) {
|
player.isFullscreen() ? player.exitFullscreen() : player.requestFullscreen();
|
||||||
player.exitFullscreen();
|
|
||||||
} else {
|
|
||||||
player.requestFullscreen();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function increase_playback_rate(steps) {
|
function increase_playback_rate(steps) {
|
||||||
@ -560,27 +513,15 @@ window.addEventListener('keydown', e => {
|
|||||||
action = toggle_play;
|
action = toggle_play;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'MediaPlay':
|
case 'MediaPlay': action = play; break;
|
||||||
action = play;
|
case 'MediaPause': action = pause; break;
|
||||||
break;
|
case 'MediaStop': action = stop; break;
|
||||||
|
|
||||||
case 'MediaPause':
|
|
||||||
action = pause;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'MediaStop':
|
|
||||||
action = stop;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'ArrowUp':
|
case 'ArrowUp':
|
||||||
if (isPlayerFocused) {
|
if (isPlayerFocused) action = increase_volume.bind(this, 0.1);
|
||||||
action = increase_volume.bind(this, 0.1);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'ArrowDown':
|
case 'ArrowDown':
|
||||||
if (isPlayerFocused) {
|
if (isPlayerFocused) action = increase_volume.bind(this, -0.1);
|
||||||
action = increase_volume.bind(this, -0.1);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
@ -619,12 +560,8 @@ window.addEventListener('keydown', e => {
|
|||||||
action = set_time_percent.bind(this, percent);
|
action = set_time_percent.bind(this, percent);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c':
|
case 'c': action = toggle_captions; break;
|
||||||
action = toggle_captions;
|
case 'f': action = toggle_fullscreen; break;
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
action = toggle_fullscreen;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'N':
|
case 'N':
|
||||||
case 'MediaTrackNext':
|
case 'MediaTrackNext':
|
||||||
@ -642,12 +579,8 @@ window.addEventListener('keydown', e => {
|
|||||||
// TODO: Add support for previous-frame-stepping.
|
// TODO: Add support for previous-frame-stepping.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '>':
|
case '>': action = increase_playback_rate.bind(this, 1); break;
|
||||||
action = increase_playback_rate.bind(this, 1);
|
case '<': action = increase_playback_rate.bind(this, -1); break;
|
||||||
break;
|
|
||||||
case '<':
|
|
||||||
action = increase_playback_rate.bind(this, -1);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.info('Unhandled key down event: %s:', decoratedKey, e);
|
console.info('Unhandled key down event: %s:', decoratedKey, e);
|
||||||
|
Loading…
Reference in New Issue
Block a user