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