2022-04-20 04:38:24 -04:00
|
|
|
'use strict';
|
2022-04-20 06:40:30 -04:00
|
|
|
var player_data = JSON.parse(document.getElementById('player_data').textContent);
|
|
|
|
var video_data = JSON.parse(document.getElementById('video_data').textContent);
|
2020-03-15 17:46:08 -04:00
|
|
|
|
2019-05-06 12:23:14 -04:00
|
|
|
var options = {
|
2019-06-07 20:56:41 -04:00
|
|
|
preload: 'auto',
|
2019-05-20 13:15:48 -04:00
|
|
|
liveui: true,
|
2019-07-14 11:08:46 -04:00
|
|
|
playbackRates: [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0],
|
2019-05-06 12:23:14 -04:00
|
|
|
controlBar: {
|
|
|
|
children: [
|
2019-06-07 20:56:41 -04:00
|
|
|
'playToggle',
|
|
|
|
'volumePanel',
|
|
|
|
'currentTimeDisplay',
|
|
|
|
'timeDivider',
|
|
|
|
'durationDisplay',
|
|
|
|
'progressControl',
|
|
|
|
'remainingTimeDisplay',
|
2021-05-03 05:25:32 -04:00
|
|
|
'Spacer',
|
2019-06-07 20:56:41 -04:00
|
|
|
'captionsButton',
|
2022-06-25 05:19:11 -04:00
|
|
|
'audioTrackButton',
|
2019-06-07 20:56:41 -04:00
|
|
|
'qualitySelector',
|
|
|
|
'playbackRateMenuButton',
|
|
|
|
'fullscreenToggle'
|
2019-05-06 12:23:14 -04:00
|
|
|
]
|
2021-01-16 20:43:36 -05:00
|
|
|
},
|
|
|
|
html5: {
|
2021-02-24 01:02:55 -05:00
|
|
|
preloadTextTracks: false,
|
2022-01-30 10:22:31 -05:00
|
|
|
vhs: {
|
2021-01-16 20:43:36 -05:00
|
|
|
overrideNative: true
|
|
|
|
}
|
2019-05-06 12:23:14 -04:00
|
|
|
}
|
2022-04-20 05:05:19 -04:00
|
|
|
};
|
2019-05-06 12:23:14 -04:00
|
|
|
|
|
|
|
if (player_data.aspect_ratio) {
|
|
|
|
options.aspectRatio = player_data.aspect_ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
var embed_url = new URL(location);
|
|
|
|
embed_url.searchParams.delete('v');
|
2022-02-19 11:03:22 -05:00
|
|
|
var short_url = location.origin + '/' + video_data.id + embed_url.search;
|
2019-05-06 12:23:14 -04:00
|
|
|
embed_url = location.origin + '/embed/' + video_data.id + embed_url.search;
|
|
|
|
|
2022-04-20 05:49:05 -04:00
|
|
|
var save_player_pos_key = 'save_player_pos';
|
2021-10-25 20:59:36 -04:00
|
|
|
|
2022-01-30 10:22:31 -05:00
|
|
|
videojs.Vhs.xhr.beforeRequest = function(options) {
|
2022-05-15 01:38:46 -04:00
|
|
|
// set local if requested not videoplayback
|
2022-05-21 06:35:41 -04:00
|
|
|
if (!options.uri.includes('videoplayback')) {
|
2022-05-15 01:38:46 -04:00
|
|
|
if (!options.uri.includes('local=true'))
|
|
|
|
options.uri += '?local=true';
|
2022-05-21 06:35:41 -04:00
|
|
|
}
|
2020-12-08 00:47:26 -05:00
|
|
|
return options;
|
|
|
|
};
|
|
|
|
|
2019-08-16 17:01:14 -04:00
|
|
|
var player = videojs('player', options);
|
2019-05-06 12:23:14 -04:00
|
|
|
|
2022-05-05 21:46:59 -04:00
|
|
|
player.on('error', function () {
|
|
|
|
if (video_data.params.quality === 'dash') return;
|
2022-06-05 13:54:48 -04:00
|
|
|
|
2022-05-19 00:15:17 -04:00
|
|
|
var localNotDisabled = (
|
|
|
|
!player.currentSrc().includes('local=true') && !video_data.local_disabled
|
|
|
|
);
|
|
|
|
var reloadMakesSense = (
|
2022-06-05 13:54:48 -04:00
|
|
|
player.error().code === MediaError.MEDIA_ERR_NETWORK ||
|
2022-05-19 00:15:17 -04:00
|
|
|
player.error().code === MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED
|
|
|
|
);
|
2022-05-05 21:46:59 -04:00
|
|
|
|
|
|
|
if (localNotDisabled) {
|
|
|
|
// add local=true to all current sources
|
|
|
|
player.src(player.currentSources().map(function (source) {
|
|
|
|
source.src += '&local=true';
|
2022-07-25 08:38:17 -04:00
|
|
|
return source;
|
2022-05-05 21:46:59 -04:00
|
|
|
}));
|
|
|
|
} else if (reloadMakesSense) {
|
2022-05-17 03:03:07 -04:00
|
|
|
setTimeout(function () {
|
|
|
|
console.warn('An error occurred in the player, reloading...');
|
2022-05-05 21:46:59 -04:00
|
|
|
|
2022-05-17 03:03:07 -04:00
|
|
|
// After load() all parameters are reset. Save them
|
2022-05-05 21:46:59 -04:00
|
|
|
var currentTime = player.currentTime();
|
|
|
|
var playbackRate = player.playbackRate();
|
|
|
|
var paused = player.paused();
|
|
|
|
|
|
|
|
player.load();
|
|
|
|
|
|
|
|
if (currentTime > 0.5) currentTime -= 0.5;
|
|
|
|
|
|
|
|
player.currentTime(currentTime);
|
|
|
|
player.playbackRate(playbackRate);
|
|
|
|
if (!paused) player.play();
|
2022-05-17 03:03:07 -04:00
|
|
|
}, 5000);
|
2022-04-22 16:37:45 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-05-05 21:46:59 -04:00
|
|
|
if (video_data.params.quality === 'dash') {
|
2022-04-22 16:37:45 -04:00
|
|
|
player.reloadSourceOnError({
|
|
|
|
errorInterval: 10
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-19 11:03:22 -05:00
|
|
|
/**
|
|
|
|
* Function for add time argument to url
|
2023-09-27 17:01:25 -04:00
|
|
|
*
|
2022-02-21 18:44:36 -05:00
|
|
|
* @param {String} url
|
2023-09-27 17:01:25 -04:00
|
|
|
* @param {String} [base]
|
2022-05-05 21:46:59 -04:00
|
|
|
* @returns {URL} urlWithTimeArg
|
2022-02-19 11:03:22 -05:00
|
|
|
*/
|
2023-09-27 17:01:25 -04:00
|
|
|
function addCurrentTimeToURL(url, base) {
|
|
|
|
var urlUsed = new URL(url, base);
|
2022-02-19 11:03:22 -05:00
|
|
|
urlUsed.searchParams.delete('start');
|
|
|
|
var currentTime = Math.ceil(player.currentTime());
|
|
|
|
if (currentTime > 0)
|
|
|
|
urlUsed.searchParams.set('t', currentTime);
|
2022-02-21 18:27:00 -05:00
|
|
|
else if (urlUsed.searchParams.has('t'))
|
|
|
|
urlUsed.searchParams.delete('t');
|
2022-02-19 11:03:22 -05:00
|
|
|
return urlUsed;
|
|
|
|
}
|
|
|
|
|
2023-10-21 07:45:15 -04:00
|
|
|
/**
|
|
|
|
* Global variable to save the last timestamp (in full seconds) at which the external
|
|
|
|
* links were updated by the 'timeupdate' callback below.
|
|
|
|
*
|
|
|
|
* It is initialized to 5s so that the video will always restart from the beginning
|
|
|
|
* if the user hasn't really started watching before switching to the other website.
|
|
|
|
*/
|
|
|
|
var timeupdate_last_ts = 5;
|
|
|
|
|
2023-09-14 14:39:46 -04:00
|
|
|
/**
|
2023-09-15 18:41:39 -04:00
|
|
|
* Callback that updates the timestamp on all external links
|
2023-09-14 14:39:46 -04:00
|
|
|
*/
|
2023-09-15 18:41:39 -04:00
|
|
|
player.on('timeupdate', function () {
|
2023-10-21 07:45:15 -04:00
|
|
|
// Only update once every second
|
|
|
|
let current_ts = Math.floor(player.currentTime());
|
|
|
|
if (current_ts > timeupdate_last_ts) timeupdate_last_ts = current_ts;
|
|
|
|
else return;
|
2023-09-15 18:41:39 -04:00
|
|
|
|
2023-09-14 16:10:02 -04:00
|
|
|
// YouTube links
|
|
|
|
|
2023-09-14 14:50:17 -04:00
|
|
|
let elem_yt_watch = document.getElementById('link-yt-watch');
|
|
|
|
let elem_yt_embed = document.getElementById('link-yt-embed');
|
2023-09-14 14:39:46 -04:00
|
|
|
|
2023-09-14 14:50:17 -04:00
|
|
|
let base_url_yt_watch = elem_yt_watch.getAttribute('data-base-url');
|
|
|
|
let base_url_yt_embed = elem_yt_embed.getAttribute('data-base-url');
|
2023-09-14 16:10:02 -04:00
|
|
|
|
2023-09-17 06:21:11 -04:00
|
|
|
elem_yt_watch.href = addCurrentTimeToURL(base_url_yt_watch);
|
|
|
|
elem_yt_embed.href = addCurrentTimeToURL(base_url_yt_embed);
|
2023-09-14 16:10:02 -04:00
|
|
|
|
|
|
|
// Invidious links
|
|
|
|
|
2023-09-27 17:01:25 -04:00
|
|
|
let domain = window.location.origin;
|
|
|
|
|
2023-09-14 16:10:02 -04:00
|
|
|
let elem_iv_embed = document.getElementById('link-iv-embed');
|
|
|
|
let elem_iv_other = document.getElementById('link-iv-other');
|
|
|
|
|
2023-09-14 14:50:17 -04:00
|
|
|
let base_url_iv_embed = elem_iv_embed.getAttribute('data-base-url');
|
2023-09-14 16:10:02 -04:00
|
|
|
let base_url_iv_other = elem_iv_other.getAttribute('data-base-url');
|
2023-09-14 14:39:46 -04:00
|
|
|
|
2023-09-27 17:01:25 -04:00
|
|
|
elem_iv_embed.href = addCurrentTimeToURL(base_url_iv_embed, domain);
|
|
|
|
elem_iv_other.href = addCurrentTimeToURL(base_url_iv_other, domain);
|
2023-09-14 14:39:46 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2022-02-19 11:03:22 -05:00
|
|
|
var shareOptions = {
|
|
|
|
socials: ['fbFeed', 'tw', 'reddit', 'email'],
|
|
|
|
|
|
|
|
get url() {
|
|
|
|
return addCurrentTimeToURL(short_url);
|
|
|
|
},
|
|
|
|
title: player_data.title,
|
|
|
|
description: player_data.description,
|
|
|
|
image: player_data.thumbnail,
|
|
|
|
get embedCode() {
|
2022-05-17 02:43:05 -04:00
|
|
|
// Single quotes inside here required. HTML inserted as is into value attribute of input
|
|
|
|
return "<iframe id='ivplayer' width='640' height='360' src='" +
|
|
|
|
addCurrentTimeToURL(embed_url) + "' style='border:none;'></iframe>";
|
2022-02-19 11:03:22 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-08 11:52:47 -04:00
|
|
|
if (location.pathname.startsWith('/embed/')) {
|
2022-02-07 18:08:52 -05:00
|
|
|
var overlay_content = '<h1><a rel="noopener" target="_blank" href="' + location.origin + '/watch?v=' + video_data.id + '">' + player_data.title + '</a></h1>';
|
2019-06-08 11:52:47 -04:00
|
|
|
player.overlay({
|
2022-02-07 18:08:52 -05:00
|
|
|
overlays: [
|
|
|
|
{ start: 'loadstart', content: overlay_content, end: 'playing', align: 'top'},
|
|
|
|
{ start: 'pause', content: overlay_content, end: 'playing', align: 'top'}
|
|
|
|
]
|
2019-06-08 11:52:47 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-07 07:57:14 -05:00
|
|
|
// Detect mobile users and initialize mobileUi for better UX
|
2021-04-11 02:12:35 -04:00
|
|
|
// Detection code taken from https://stackoverflow.com/a/20293441
|
|
|
|
|
|
|
|
function isMobile() {
|
2022-04-20 05:49:05 -04:00
|
|
|
try{ document.createEvent('TouchEvent'); return true; }
|
2021-04-11 02:12:35 -04:00
|
|
|
catch(e){ return false; }
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isMobile()) {
|
2022-06-22 07:33:02 -04:00
|
|
|
player.mobileUi({ touchControls: { seekSeconds: 5 * player.playbackRate() } });
|
2021-04-11 02:12:35 -04:00
|
|
|
|
2022-04-20 06:23:24 -04:00
|
|
|
var buttons = ['playToggle', 'volumePanel', 'captionsButton'];
|
2021-04-11 02:12:35 -04:00
|
|
|
|
2022-06-25 07:24:20 -04:00
|
|
|
if (!video_data.params.listen && video_data.params.quality === 'dash') buttons.push('audioTrackButton');
|
|
|
|
if (video_data.params.listen || video_data.params.quality !== 'dash') buttons.push('qualitySelector');
|
2021-04-11 02:12:35 -04:00
|
|
|
|
|
|
|
// Create new control bar object for operation buttons
|
2022-04-20 05:49:05 -04:00
|
|
|
const ControlBar = videojs.getComponent('controlBar');
|
2021-04-11 02:12:35 -04:00
|
|
|
let operations_bar = new ControlBar(player, {
|
|
|
|
children: [],
|
|
|
|
playbackRates: [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0]
|
|
|
|
});
|
2022-04-20 05:36:52 -04:00
|
|
|
buttons.slice(1).forEach(function (child) {operations_bar.addChild(child);});
|
2021-04-11 02:12:35 -04:00
|
|
|
|
|
|
|
// Remove operation buttons from primary control bar
|
2022-04-20 06:23:24 -04:00
|
|
|
var primary_control_bar = player.getChild('controlBar');
|
2022-04-20 05:36:52 -04:00
|
|
|
buttons.forEach(function (child) {primary_control_bar.removeChild(child);});
|
2021-04-11 02:12:35 -04:00
|
|
|
|
2022-04-20 06:23:24 -04:00
|
|
|
var operations_bar_element = operations_bar.el();
|
2022-05-05 21:46:59 -04:00
|
|
|
operations_bar_element.classList.add('mobile-operations-bar');
|
2022-04-20 05:05:19 -04:00
|
|
|
player.addChild(operations_bar);
|
2021-04-11 02:12:35 -04:00
|
|
|
|
2022-02-07 07:57:14 -05:00
|
|
|
// Playback menu doesn't work when it's initialized outside of the primary control bar
|
2022-04-20 06:23:24 -04:00
|
|
|
var playback_element = document.getElementsByClassName('vjs-playback-rate')[0];
|
2022-04-20 05:05:19 -04:00
|
|
|
operations_bar_element.append(playback_element);
|
2021-04-11 02:12:35 -04:00
|
|
|
|
|
|
|
// The share and http source selector element can't be fetched till the players ready.
|
2022-04-20 05:49:05 -04:00
|
|
|
player.one('playing', function () {
|
2022-04-27 08:01:34 -04:00
|
|
|
var share_element = document.getElementsByClassName('vjs-share-control')[0];
|
|
|
|
operations_bar_element.append(share_element);
|
|
|
|
|
2022-06-25 07:24:20 -04:00
|
|
|
if (!video_data.params.listen && video_data.params.quality === 'dash') {
|
2022-05-05 21:46:59 -04:00
|
|
|
var http_source_selector = document.getElementsByClassName('vjs-http-source-selector vjs-menu-button')[0];
|
|
|
|
operations_bar_element.append(http_source_selector);
|
2022-04-27 08:01:34 -04:00
|
|
|
}
|
|
|
|
});
|
2021-04-10 23:22:30 -04:00
|
|
|
}
|
|
|
|
|
2021-04-11 09:09:10 -04:00
|
|
|
// Enable VR video support
|
2021-09-14 19:37:23 -04:00
|
|
|
if (!video_data.params.listen && video_data.vr && video_data.params.vr_mode) {
|
2022-04-20 05:49:05 -04:00
|
|
|
player.crossOrigin('anonymous');
|
2021-09-10 03:42:39 -04:00
|
|
|
switch (video_data.projection_type) {
|
2022-04-20 05:49:05 -04:00
|
|
|
case 'EQUIRECTANGULAR':
|
|
|
|
player.vr({projection: 'equirectangular'});
|
|
|
|
default: // Should only be 'MESH' but we'll use this as a fallback.
|
|
|
|
player.vr({projection: 'EAC'});
|
2021-09-10 03:42:39 -04:00
|
|
|
}
|
2021-04-11 09:09:10 -04:00
|
|
|
}
|
|
|
|
|
2019-05-06 12:23:14 -04:00
|
|
|
// Add markers
|
|
|
|
if (video_data.params.video_start > 0 || video_data.params.video_end > 0) {
|
|
|
|
var markers = [{ time: video_data.params.video_start, text: 'Start' }];
|
|
|
|
|
|
|
|
if (video_data.params.video_end < 0) {
|
|
|
|
markers.push({ time: video_data.length_seconds - 0.5, text: 'End' });
|
|
|
|
} else {
|
|
|
|
markers.push({ time: video_data.params.video_end, text: 'End' });
|
|
|
|
}
|
|
|
|
|
|
|
|
player.markers({
|
|
|
|
onMarkerReached: function (marker) {
|
2022-02-07 18:08:52 -05:00
|
|
|
if (marker.text === 'End')
|
|
|
|
player.loop() ? player.markers.prev('Start') : player.pause();
|
2019-05-06 12:23:14 -04:00
|
|
|
},
|
|
|
|
markers: markers
|
|
|
|
});
|
|
|
|
|
|
|
|
player.currentTime(video_data.params.video_start);
|
|
|
|
}
|
|
|
|
|
|
|
|
player.volume(video_data.params.volume / 100);
|
|
|
|
player.playbackRate(video_data.params.speed);
|
|
|
|
|
2022-02-12 16:07:41 -05:00
|
|
|
/**
|
2022-04-09 13:58:49 -04:00
|
|
|
* Method for getting the contents of a cookie
|
|
|
|
*
|
2022-02-12 16:07:41 -05:00
|
|
|
* @param {String} name Name of cookie
|
2022-05-05 21:46:59 -04:00
|
|
|
* @returns {String|null} cookieValue
|
2022-02-12 16:07:41 -05:00
|
|
|
*/
|
|
|
|
function getCookieValue(name) {
|
2022-05-05 21:46:59 -04:00
|
|
|
var cookiePrefix = name + '=';
|
|
|
|
var matchedCookie = document.cookie.split(';').find(function (item) {return item.includes(cookiePrefix);});
|
|
|
|
if (matchedCookie)
|
|
|
|
return matchedCookie.replace(cookiePrefix, '');
|
|
|
|
return null;
|
2022-02-12 16:07:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-04-20 05:49:05 -04:00
|
|
|
* Method for updating the 'PREFS' cookie (or creating it if missing)
|
2022-04-09 13:58:49 -04:00
|
|
|
*
|
|
|
|
* @param {number} newVolume New volume defined (null if unchanged)
|
|
|
|
* @param {number} newSpeed New speed defined (null if unchanged)
|
2022-02-12 16:07:41 -05:00
|
|
|
*/
|
|
|
|
function updateCookie(newVolume, newSpeed) {
|
2022-04-20 05:13:16 -04:00
|
|
|
var volumeValue = newVolume !== null ? newVolume : video_data.params.volume;
|
|
|
|
var speedValue = newSpeed !== null ? newSpeed : video_data.params.speed;
|
2022-04-09 13:58:49 -04:00
|
|
|
|
2022-02-12 16:07:41 -05:00
|
|
|
var cookieValue = getCookieValue('PREFS');
|
2022-02-22 14:05:22 -05:00
|
|
|
var cookieData;
|
2022-04-09 13:58:49 -04:00
|
|
|
|
2022-04-20 05:13:16 -04:00
|
|
|
if (cookieValue !== null) {
|
2022-02-12 16:07:41 -05:00
|
|
|
var cookieJson = JSON.parse(decodeURIComponent(cookieValue));
|
|
|
|
cookieJson.volume = volumeValue;
|
|
|
|
cookieJson.speed = speedValue;
|
2022-02-22 14:05:22 -05:00
|
|
|
cookieData = encodeURIComponent(JSON.stringify(cookieJson));
|
2022-02-12 16:07:41 -05:00
|
|
|
} else {
|
2022-02-22 14:05:22 -05:00
|
|
|
cookieData = encodeURIComponent(JSON.stringify({ 'volume': volumeValue, 'speed': speedValue }));
|
2022-02-12 16:07:41 -05:00
|
|
|
}
|
2022-04-09 13:58:49 -04:00
|
|
|
|
2022-02-22 14:05:22 -05:00
|
|
|
// Set expiration in 2 year
|
2022-04-09 13:58:49 -04:00
|
|
|
var date = new Date();
|
2022-08-22 12:16:50 -04:00
|
|
|
date.setFullYear(date.getFullYear() + 2);
|
2022-04-09 13:58:49 -04:00
|
|
|
|
2023-03-23 18:10:53 -04:00
|
|
|
var ipRegex = /^((\d+\.){3}\d+|[\dA-Fa-f]*:[\d:A-Fa-f]*:[\d:A-Fa-f]+)$/;
|
2022-05-05 21:46:59 -04:00
|
|
|
var domainUsed = location.hostname;
|
2022-04-09 13:58:49 -04:00
|
|
|
|
2022-04-09 14:04:42 -04:00
|
|
|
// Fix for a bug in FF where the leading dot in the FQDN is not ignored
|
2022-04-20 05:13:16 -04:00
|
|
|
if (domainUsed.charAt(0) !== '.' && !ipRegex.test(domainUsed) && domainUsed !== 'localhost')
|
2022-05-05 21:46:59 -04:00
|
|
|
domainUsed = '.' + location.hostname;
|
2022-04-09 13:58:49 -04:00
|
|
|
|
2022-08-22 12:16:50 -04:00
|
|
|
var secure = location.protocol.startsWith("https") ? " Secure;" : "";
|
|
|
|
|
|
|
|
document.cookie = 'PREFS=' + cookieData + '; SameSite=Lax; path=/; domain=' +
|
|
|
|
domainUsed + '; expires=' + date.toGMTString() + ';' + secure;
|
2022-04-09 13:58:49 -04:00
|
|
|
|
2022-02-12 16:07:41 -05:00
|
|
|
video_data.params.volume = volumeValue;
|
|
|
|
video_data.params.speed = speedValue;
|
2022-02-12 11:34:19 -05:00
|
|
|
}
|
2019-05-06 12:23:14 -04:00
|
|
|
|
2022-02-12 16:07:41 -05:00
|
|
|
player.on('ratechange', function () {
|
|
|
|
updateCookie(null, player.playbackRate());
|
2022-06-22 07:33:02 -04:00
|
|
|
if (isMobile()) {
|
|
|
|
player.mobileUi({ touchControls: { seekSeconds: 5 * player.playbackRate() } });
|
|
|
|
}
|
2022-02-12 16:07:41 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
player.on('volumechange', function () {
|
|
|
|
updateCookie(Math.ceil(player.volume() * 100), null);
|
|
|
|
});
|
|
|
|
|
2019-05-20 13:15:48 -04:00
|
|
|
player.on('waiting', function () {
|
|
|
|
if (player.playbackRate() > 1 && player.liveTracker.isLive() && player.liveTracker.atLiveEdge()) {
|
2022-05-05 21:46:59 -04:00
|
|
|
console.info('Player has caught up to source, resetting playbackRate');
|
2019-05-20 13:15:48 -04:00
|
|
|
player.playbackRate(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-06-08 11:18:45 -04:00
|
|
|
if (video_data.premiere_timestamp && Math.round(new Date() / 1000) < video_data.premiere_timestamp) {
|
|
|
|
player.getChild('bigPlayButton').hide();
|
|
|
|
}
|
|
|
|
|
2021-10-26 19:25:29 -04:00
|
|
|
if (video_data.params.save_player_pos) {
|
2021-11-17 20:25:47 -05:00
|
|
|
const url = new URL(location);
|
2022-04-20 05:49:05 -04:00
|
|
|
const hasTimeParam = url.searchParams.has('t');
|
2022-05-05 21:46:59 -04:00
|
|
|
const rememberedTime = get_video_time();
|
2021-10-25 20:59:36 -04:00
|
|
|
let lastUpdated = 0;
|
|
|
|
|
2022-05-05 21:46:59 -04:00
|
|
|
if(!hasTimeParam) set_seconds_after_start(rememberedTime);
|
2021-10-25 20:59:36 -04:00
|
|
|
|
2022-05-05 21:46:59 -04:00
|
|
|
player.on('timeupdate', function () {
|
2021-10-25 20:59:36 -04:00
|
|
|
const raw = player.currentTime();
|
|
|
|
const time = Math.floor(raw);
|
|
|
|
|
2021-12-30 21:24:08 -05:00
|
|
|
if(lastUpdated !== time && raw <= video_data.length_seconds - 15) {
|
2021-10-25 20:59:36 -04:00
|
|
|
save_video_time(time);
|
|
|
|
lastUpdated = time;
|
|
|
|
}
|
2022-05-05 21:46:59 -04:00
|
|
|
});
|
2021-10-25 20:59:36 -04:00
|
|
|
}
|
2022-02-07 18:08:52 -05:00
|
|
|
else remove_all_video_times();
|
2021-10-25 20:59:36 -04:00
|
|
|
|
2019-05-06 12:23:14 -04:00
|
|
|
if (video_data.params.autoplay) {
|
|
|
|
var bpb = player.getChild('bigPlayButton');
|
2019-06-08 11:18:45 -04:00
|
|
|
bpb.hide();
|
|
|
|
|
|
|
|
player.ready(function () {
|
|
|
|
new Promise(function (resolve, reject) {
|
2022-04-20 05:36:52 -04:00
|
|
|
setTimeout(function () {resolve(1);}, 1);
|
2019-06-08 11:18:45 -04:00
|
|
|
}).then(function (result) {
|
|
|
|
var promise = player.play();
|
|
|
|
|
|
|
|
if (promise !== undefined) {
|
2022-04-20 05:36:52 -04:00
|
|
|
promise.then(function () {
|
|
|
|
}).catch(function (error) {
|
2019-06-08 11:18:45 -04:00
|
|
|
bpb.show();
|
|
|
|
});
|
|
|
|
}
|
2019-05-06 12:23:14 -04:00
|
|
|
});
|
2019-06-08 11:18:45 -04:00
|
|
|
});
|
2019-05-06 12:23:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!video_data.params.listen && video_data.params.quality === 'dash') {
|
|
|
|
player.httpSourceSelector();
|
2020-12-13 04:16:26 -05:00
|
|
|
|
2022-04-20 05:49:05 -04:00
|
|
|
if (video_data.params.quality_dash !== 'auto') {
|
2022-04-20 05:36:52 -04:00
|
|
|
player.ready(function () {
|
2022-04-20 05:49:05 -04:00
|
|
|
player.on('loadedmetadata', function () {
|
2022-04-20 05:36:52 -04:00
|
|
|
const qualityLevels = Array.from(player.qualityLevels()).sort(function (a, b) {return a.height - b.height;});
|
2020-12-19 11:48:20 -05:00
|
|
|
let targetQualityLevel;
|
|
|
|
switch (video_data.params.quality_dash) {
|
2022-04-20 05:49:05 -04:00
|
|
|
case 'best':
|
2020-12-19 11:48:20 -05:00
|
|
|
targetQualityLevel = qualityLevels.length - 1;
|
|
|
|
break;
|
2022-04-20 05:49:05 -04:00
|
|
|
case 'worst':
|
2020-12-19 11:48:20 -05:00
|
|
|
targetQualityLevel = 0;
|
|
|
|
break;
|
|
|
|
default:
|
2022-05-21 06:35:41 -04:00
|
|
|
const targetHeight = parseInt(video_data.params.quality_dash);
|
2020-12-19 11:48:20 -05:00
|
|
|
for (let i = 0; i < qualityLevels.length; i++) {
|
2022-05-05 21:46:59 -04:00
|
|
|
if (qualityLevels[i].height <= targetHeight)
|
2020-12-19 11:48:20 -05:00
|
|
|
targetQualityLevel = i;
|
2022-05-05 21:46:59 -04:00
|
|
|
else
|
2020-12-19 11:48:20 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-05-05 21:46:59 -04:00
|
|
|
qualityLevels.forEach(function (level, index) {
|
|
|
|
level.enabled = (index === targetQualityLevel);
|
|
|
|
});
|
2020-12-13 04:16:26 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2019-05-06 12:23:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
player.vttThumbnails({
|
2022-05-05 21:46:59 -04:00
|
|
|
src: '/api/v1/storyboards/' + video_data.id + '?height=90',
|
2020-11-08 16:02:25 -05:00
|
|
|
showTimestamp: true
|
2019-05-06 12:23:14 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// Enable annotations
|
2019-05-09 09:36:36 -04:00
|
|
|
if (!video_data.params.listen && video_data.params.annotations) {
|
2022-05-05 21:46:59 -04:00
|
|
|
addEventListener('load', function (e) {
|
|
|
|
addEventListener('__ar_annotation_click', function (e) {
|
2022-04-20 07:56:00 -04:00
|
|
|
const url = e.detail.url,
|
|
|
|
target = e.detail.target,
|
|
|
|
seconds = e.detail.seconds;
|
2019-10-18 12:44:11 -04:00
|
|
|
var path = new URL(url);
|
2019-05-06 12:23:14 -04:00
|
|
|
|
2019-10-18 12:44:11 -04:00
|
|
|
if (path.href.startsWith('https://www.youtube.com/watch?') && seconds) {
|
|
|
|
path.search += '&t=' + seconds;
|
|
|
|
}
|
2019-05-06 12:23:14 -04:00
|
|
|
|
2019-10-18 12:44:11 -04:00
|
|
|
path = path.pathname + path.search;
|
2019-05-06 12:23:14 -04:00
|
|
|
|
2019-10-18 12:44:11 -04:00
|
|
|
if (target === 'current') {
|
2022-05-05 21:46:59 -04:00
|
|
|
location.href = path;
|
2019-10-18 12:44:11 -04:00
|
|
|
} else if (target === 'new') {
|
2022-05-05 21:46:59 -04:00
|
|
|
open(path, '_blank');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
helpers.xhr('GET', '/api/v1/annotations/' + video_data.id, {
|
|
|
|
responseType: 'text',
|
|
|
|
timeout: 60000
|
|
|
|
}, {
|
|
|
|
on200: function (response) {
|
|
|
|
var video_container = document.getElementById('player');
|
|
|
|
videojs.registerPlugin('youtubeAnnotationsPlugin', youtubeAnnotationsPlugin);
|
|
|
|
if (player.paused()) {
|
|
|
|
player.one('play', function (event) {
|
|
|
|
player.youtubeAnnotationsPlugin({ annotationXml: response, videoContainer: video_container });
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
player.youtubeAnnotationsPlugin({ annotationXml: response, videoContainer: video_container });
|
|
|
|
}
|
2019-10-18 12:44:11 -04:00
|
|
|
}
|
|
|
|
});
|
2019-06-15 11:08:06 -04:00
|
|
|
|
2019-10-18 12:44:11 -04:00
|
|
|
});
|
2019-05-06 12:23:14 -04:00
|
|
|
}
|
|
|
|
|
2022-05-15 01:38:46 -04:00
|
|
|
function change_volume(delta) {
|
2019-08-16 17:01:14 -04:00
|
|
|
const curVolume = player.volume();
|
2022-05-21 06:35:41 -04:00
|
|
|
let newVolume = curVolume + delta;
|
|
|
|
newVolume = helpers.clamp(newVolume, 0, 1);
|
2019-08-16 17:01:14 -04:00
|
|
|
player.volume(newVolume);
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggle_muted() {
|
2022-05-05 21:46:59 -04:00
|
|
|
player.muted(!player.muted());
|
2019-08-16 17:01:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function skip_seconds(delta) {
|
|
|
|
const duration = player.duration();
|
|
|
|
const curTime = player.currentTime();
|
2022-05-21 06:35:41 -04:00
|
|
|
let newTime = curTime + delta;
|
|
|
|
newTime = helpers.clamp(newTime, 0, duration);
|
2019-08-16 17:01:14 -04:00
|
|
|
player.currentTime(newTime);
|
|
|
|
}
|
|
|
|
|
2021-10-25 20:59:36 -04:00
|
|
|
function set_seconds_after_start(delta) {
|
|
|
|
const start = video_data.params.video_start;
|
|
|
|
player.currentTime(start + delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
function save_video_time(seconds) {
|
|
|
|
const all_video_times = get_all_video_times();
|
2022-05-21 06:35:41 -04:00
|
|
|
all_video_times[video_data.id] = seconds;
|
2022-05-06 00:21:19 -04:00
|
|
|
helpers.storage.set(save_player_pos_key, all_video_times);
|
2021-10-25 20:59:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_video_time() {
|
2022-05-21 06:35:41 -04:00
|
|
|
return get_all_video_times()[video_data.id] || 0;
|
2021-10-25 20:59:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_all_video_times() {
|
2022-05-06 00:21:19 -04:00
|
|
|
return helpers.storage.get(save_player_pos_key) || {};
|
2021-10-25 20:59:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function remove_all_video_times() {
|
2022-05-05 21:46:59 -04:00
|
|
|
helpers.storage.remove(save_player_pos_key);
|
2021-10-25 20:59:36 -04:00
|
|
|
}
|
|
|
|
|
2019-08-16 17:01:14 -04:00
|
|
|
function set_time_percent(percent) {
|
|
|
|
const duration = player.duration();
|
|
|
|
const newTime = duration * (percent / 100);
|
|
|
|
player.currentTime(newTime);
|
|
|
|
}
|
|
|
|
|
2022-02-07 18:08:52 -05:00
|
|
|
function play() { player.play(); }
|
|
|
|
function pause() { player.pause(); }
|
|
|
|
function stop() { player.pause(); player.currentTime(0); }
|
|
|
|
function toggle_play() { player.paused() ? play() : pause(); }
|
2019-08-16 17:01:14 -04:00
|
|
|
|
2019-10-18 12:44:11 -04:00
|
|
|
const toggle_captions = (function () {
|
2019-08-16 17:01:14 -04:00
|
|
|
let toggledTrack = null;
|
2022-06-05 13:54:48 -04:00
|
|
|
|
2022-05-05 21:46:59 -04:00
|
|
|
function bindChange(onOrOff) {
|
|
|
|
player.textTracks()[onOrOff]('change', function (e) {
|
|
|
|
toggledTrack = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-16 17:01:14 -04:00
|
|
|
// Wrapper function to ignore our own emitted events and only listen
|
|
|
|
// to events emitted by Video.js on click on the captions menu items.
|
2022-05-05 21:46:59 -04:00
|
|
|
function setMode(track, mode) {
|
2019-08-16 17:01:14 -04:00
|
|
|
bindChange('off');
|
|
|
|
track.mode = mode;
|
2022-05-05 21:46:59 -04:00
|
|
|
setTimeout(function () {
|
2019-08-16 17:01:14 -04:00
|
|
|
bindChange('on');
|
|
|
|
}, 0);
|
2022-05-05 21:46:59 -04:00
|
|
|
}
|
2022-06-05 13:54:48 -04:00
|
|
|
|
2019-08-16 17:01:14 -04:00
|
|
|
bindChange('on');
|
2019-10-18 12:44:11 -04:00
|
|
|
return function () {
|
2019-08-16 17:01:14 -04:00
|
|
|
if (toggledTrack !== null) {
|
|
|
|
if (toggledTrack.mode !== 'showing') {
|
|
|
|
setMode(toggledTrack, 'showing');
|
|
|
|
} else {
|
|
|
|
setMode(toggledTrack, 'disabled');
|
|
|
|
}
|
|
|
|
toggledTrack = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used as a fallback if no captions are currently active.
|
|
|
|
// TODO: Make this more intelligent by e.g. relying on browser language.
|
|
|
|
let fallbackCaptionsTrack = null;
|
|
|
|
|
|
|
|
const tracks = player.textTracks();
|
|
|
|
for (let i = 0; i < tracks.length; i++) {
|
|
|
|
const track = tracks[i];
|
2022-02-07 18:08:52 -05:00
|
|
|
if (track.kind !== 'captions') continue;
|
2019-08-16 17:01:14 -04:00
|
|
|
|
|
|
|
if (fallbackCaptionsTrack === null) {
|
|
|
|
fallbackCaptionsTrack = track;
|
|
|
|
}
|
|
|
|
if (track.mode === 'showing') {
|
|
|
|
setMode(track, 'disabled');
|
|
|
|
toggledTrack = track;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback if no captions are currently active.
|
|
|
|
if (fallbackCaptionsTrack !== null) {
|
|
|
|
setMode(fallbackCaptionsTrack, 'showing');
|
|
|
|
toggledTrack = fallbackCaptionsTrack;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
function toggle_fullscreen() {
|
2022-02-07 18:08:52 -05:00
|
|
|
player.isFullscreen() ? player.exitFullscreen() : player.requestFullscreen();
|
2019-08-16 17:01:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function increase_playback_rate(steps) {
|
|
|
|
const maxIndex = options.playbackRates.length - 1;
|
|
|
|
const curIndex = options.playbackRates.indexOf(player.playbackRate());
|
2022-05-21 06:35:41 -04:00
|
|
|
let newIndex = curIndex + steps;
|
|
|
|
newIndex = helpers.clamp(newIndex, 0, maxIndex);
|
2019-08-16 17:01:14 -04:00
|
|
|
player.playbackRate(options.playbackRates[newIndex]);
|
|
|
|
}
|
|
|
|
|
2022-05-05 21:46:59 -04:00
|
|
|
addEventListener('keydown', function (e) {
|
2019-08-16 17:01:14 -04:00
|
|
|
if (e.target.tagName.toLowerCase() === 'input') {
|
|
|
|
// Ignore input when focus is on certain elements, e.g. form fields.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// See https://github.com/ctd1500/videojs-hotkeys/blob/bb4a158b2e214ccab87c2e7b95f42bc45c6bfd87/videojs.hotkeys.js#L310-L313
|
|
|
|
const isPlayerFocused = false
|
|
|
|
|| e.target === document.querySelector('.video-js')
|
|
|
|
|| e.target === document.querySelector('.vjs-tech')
|
|
|
|
|| e.target === document.querySelector('.iframeblocker')
|
|
|
|
|| e.target === document.querySelector('.vjs-control-bar')
|
2019-10-18 12:44:11 -04:00
|
|
|
;
|
2019-08-16 17:01:14 -04:00
|
|
|
let action = null;
|
|
|
|
|
|
|
|
const code = e.keyCode;
|
2019-08-19 00:22:39 -04:00
|
|
|
const decoratedKey =
|
|
|
|
e.key
|
2019-10-18 12:44:11 -04:00
|
|
|
+ (e.altKey ? '+alt' : '')
|
2019-08-19 00:22:39 -04:00
|
|
|
+ (e.ctrlKey ? '+ctrl' : '')
|
|
|
|
+ (e.metaKey ? '+meta' : '')
|
2019-10-18 12:44:11 -04:00
|
|
|
;
|
2019-08-19 00:22:39 -04:00
|
|
|
switch (decoratedKey) {
|
2019-10-18 12:44:11 -04:00
|
|
|
case ' ':
|
|
|
|
case 'k':
|
2019-08-19 06:10:25 -04:00
|
|
|
case 'MediaPlayPause':
|
2019-10-18 12:44:11 -04:00
|
|
|
action = toggle_play;
|
|
|
|
break;
|
|
|
|
|
2022-02-07 18:08:52 -05:00
|
|
|
case 'MediaPlay': action = play; break;
|
|
|
|
case 'MediaPause': action = pause; break;
|
|
|
|
case 'MediaStop': action = stop; break;
|
2019-08-19 06:10:25 -04:00
|
|
|
|
2019-10-18 12:44:11 -04:00
|
|
|
case 'ArrowUp':
|
2022-05-15 01:38:46 -04:00
|
|
|
if (isPlayerFocused) action = change_volume.bind(this, 0.1);
|
2019-10-18 12:44:11 -04:00
|
|
|
break;
|
|
|
|
case 'ArrowDown':
|
2022-05-15 01:38:46 -04:00
|
|
|
if (isPlayerFocused) action = change_volume.bind(this, -0.1);
|
2019-10-18 12:44:11 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm':
|
|
|
|
action = toggle_muted;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ArrowRight':
|
2019-08-19 06:10:25 -04:00
|
|
|
case 'MediaFastForward':
|
2021-02-17 08:33:26 -05:00
|
|
|
action = skip_seconds.bind(this, 5 * player.playbackRate());
|
2019-10-18 12:44:11 -04:00
|
|
|
break;
|
|
|
|
case 'ArrowLeft':
|
2019-08-19 06:10:25 -04:00
|
|
|
case 'MediaTrackPrevious':
|
2021-02-17 08:33:26 -05:00
|
|
|
action = skip_seconds.bind(this, -5 * player.playbackRate());
|
2019-10-18 12:44:11 -04:00
|
|
|
break;
|
|
|
|
case 'l':
|
2021-02-17 08:33:26 -05:00
|
|
|
action = skip_seconds.bind(this, 10 * player.playbackRate());
|
2019-10-18 12:44:11 -04:00
|
|
|
break;
|
|
|
|
case 'j':
|
2021-02-17 08:33:26 -05:00
|
|
|
action = skip_seconds.bind(this, -10 * player.playbackRate());
|
2019-10-18 12:44:11 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '0':
|
|
|
|
case '1':
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
case '4':
|
|
|
|
case '5':
|
|
|
|
case '6':
|
|
|
|
case '7':
|
|
|
|
case '8':
|
|
|
|
case '9':
|
2022-02-07 18:01:53 -05:00
|
|
|
// Ignore numpad numbers
|
|
|
|
if (code > 57) break;
|
|
|
|
|
2019-10-18 12:44:11 -04:00
|
|
|
const percent = (code - 48) * 10;
|
|
|
|
action = set_time_percent.bind(this, percent);
|
|
|
|
break;
|
|
|
|
|
2022-02-07 18:08:52 -05:00
|
|
|
case 'c': action = toggle_captions; break;
|
|
|
|
case 'f': action = toggle_fullscreen; break;
|
2019-10-18 12:44:11 -04:00
|
|
|
|
|
|
|
case 'N':
|
2019-08-19 06:10:25 -04:00
|
|
|
case 'MediaTrackNext':
|
2019-10-18 12:44:11 -04:00
|
|
|
action = next_video;
|
|
|
|
break;
|
|
|
|
case 'P':
|
2019-08-19 06:10:25 -04:00
|
|
|
case 'MediaTrackPrevious':
|
2019-10-18 12:44:11 -04:00
|
|
|
// TODO: Add support to play back previous video.
|
|
|
|
break;
|
|
|
|
|
2022-05-05 21:46:59 -04:00
|
|
|
// TODO: More precise step. Now FPS is taken equal to 29.97
|
|
|
|
// Common FPS: https://forum.videohelp.com/threads/81868#post323588
|
|
|
|
// Possible solution is new HTMLVideoElement.requestVideoFrameCallback() https://wicg.github.io/video-rvfc/
|
2022-05-16 06:13:00 -04:00
|
|
|
case ',': action = function () { pause(); skip_seconds(-1/29.97); }; break;
|
|
|
|
case '.': action = function () { pause(); skip_seconds( 1/29.97); }; break;
|
2019-10-18 12:44:11 -04:00
|
|
|
|
2022-02-07 18:08:52 -05:00
|
|
|
case '>': action = increase_playback_rate.bind(this, 1); break;
|
|
|
|
case '<': action = increase_playback_rate.bind(this, -1); break;
|
2019-10-18 12:44:11 -04:00
|
|
|
|
|
|
|
default:
|
|
|
|
console.info('Unhandled key down event: %s:', decoratedKey, e);
|
|
|
|
break;
|
2019-08-16 17:01:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
e.preventDefault();
|
|
|
|
action();
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
// Add support for controlling the player volume by scrolling over it. Adapted from
|
|
|
|
// https://github.com/ctd1500/videojs-hotkeys/blob/bb4a158b2e214ccab87c2e7b95f42bc45c6bfd87/videojs.hotkeys.js#L292-L328
|
2019-10-18 12:44:11 -04:00
|
|
|
(function () {
|
2019-08-16 17:01:14 -04:00
|
|
|
const pEl = document.getElementById('player');
|
|
|
|
|
|
|
|
var volumeHover = false;
|
|
|
|
var volumeSelector = pEl.querySelector('.vjs-volume-menu-button') || pEl.querySelector('.vjs-volume-panel');
|
2022-04-20 05:13:16 -04:00
|
|
|
if (volumeSelector !== null) {
|
2019-10-18 12:44:11 -04:00
|
|
|
volumeSelector.onmouseover = function () { volumeHover = true; };
|
|
|
|
volumeSelector.onmouseout = function () { volumeHover = false; };
|
2019-08-16 17:01:14 -04:00
|
|
|
}
|
|
|
|
|
2022-05-05 21:46:59 -04:00
|
|
|
function mouseScroll(event) {
|
2019-10-18 12:44:11 -04:00
|
|
|
// When controls are disabled, hotkeys will be disabled as well
|
2022-05-05 21:46:59 -04:00
|
|
|
if (!player.controls() || !volumeHover) return;
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
var wheelMove = event.wheelDelta || -event.detail;
|
|
|
|
var volumeSign = Math.sign(wheelMove);
|
|
|
|
|
2022-05-15 01:38:46 -04:00
|
|
|
change_volume(volumeSign * 0.05); // decrease/increase by 5%
|
2022-05-05 21:46:59 -04:00
|
|
|
}
|
2019-08-16 17:01:14 -04:00
|
|
|
|
|
|
|
player.on('mousewheel', mouseScroll);
|
2022-04-20 05:49:05 -04:00
|
|
|
player.on('DOMMouseScroll', mouseScroll);
|
2019-08-16 17:01:14 -04:00
|
|
|
}());
|
|
|
|
|
2019-05-06 12:23:14 -04:00
|
|
|
// Since videojs-share can sometimes be blocked, we defer it until last
|
2022-05-05 21:46:59 -04:00
|
|
|
if (player.share) player.share(shareOptions);
|
2021-02-01 02:59:27 -05:00
|
|
|
|
2021-02-24 01:02:55 -05:00
|
|
|
// show the preferred caption by default
|
|
|
|
if (player_data.preferred_caption_found) {
|
2022-04-20 05:36:52 -04:00
|
|
|
player.ready(function () {
|
2022-06-22 13:01:11 -04:00
|
|
|
if (!video_data.params.listen && video_data.params.quality === 'dash') {
|
|
|
|
// play.textTracks()[0] on DASH mode is showing some debug messages
|
|
|
|
player.textTracks()[1].mode = 'showing';
|
|
|
|
} else {
|
|
|
|
player.textTracks()[0].mode = 'showing';
|
|
|
|
}
|
2021-02-24 01:02:55 -05:00
|
|
|
});
|
2021-02-26 13:59:16 -05:00
|
|
|
}
|
|
|
|
|
2021-02-02 08:25:13 -05:00
|
|
|
// Safari audio double duration fix
|
2022-04-20 05:49:05 -04:00
|
|
|
if (navigator.vendor === 'Apple Computer, Inc.' && video_data.params.listen) {
|
2021-02-02 22:50:14 -05:00
|
|
|
player.on('loadedmetadata', function () {
|
2021-02-01 02:59:27 -05:00
|
|
|
player.on('timeupdate', function () {
|
2022-03-27 06:32:00 -04:00
|
|
|
if (player.remainingTime() < player.duration() / 2 && player.remainingTime() >= 2) {
|
|
|
|
player.currentTime(player.duration() - 1);
|
2021-02-01 02:59:27 -05:00
|
|
|
}
|
2021-02-09 12:05:29 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2021-04-08 07:15:15 -04:00
|
|
|
|
|
|
|
// Watch on Invidious link
|
2022-05-05 21:46:59 -04:00
|
|
|
if (location.pathname.startsWith('/embed/')) {
|
2021-04-08 07:15:15 -04:00
|
|
|
const Button = videojs.getComponent('Button');
|
|
|
|
let watch_on_invidious_button = new Button(player);
|
|
|
|
|
|
|
|
// Create hyperlink for current instance
|
2022-04-20 06:23:24 -04:00
|
|
|
var redirect_element = document.createElement('a');
|
2022-04-20 06:03:05 -04:00
|
|
|
redirect_element.setAttribute('href', location.pathname.replace('/embed/', '/watch?v='));
|
2022-04-20 05:49:05 -04:00
|
|
|
redirect_element.appendChild(document.createTextNode('Invidious'));
|
2021-04-08 07:15:15 -04:00
|
|
|
|
2022-04-20 05:05:19 -04:00
|
|
|
watch_on_invidious_button.el().appendChild(redirect_element);
|
2022-04-20 05:49:05 -04:00
|
|
|
watch_on_invidious_button.addClass('watch-on-invidious');
|
2021-04-08 07:15:15 -04:00
|
|
|
|
2022-04-20 06:23:24 -04:00
|
|
|
var cb = player.getChild('ControlBar');
|
2022-04-20 05:05:19 -04:00
|
|
|
cb.addChild(watch_on_invidious_button);
|
|
|
|
}
|
2022-05-31 04:58:12 -04:00
|
|
|
|
2022-05-31 05:18:42 -04:00
|
|
|
addEventListener('DOMContentLoaded', function () {
|
|
|
|
// Save time during redirection on another instance
|
|
|
|
const changeInstanceLink = document.querySelector('#watch-on-another-invidious-instance > a');
|
|
|
|
if (changeInstanceLink) changeInstanceLink.addEventListener('click', function () {
|
|
|
|
changeInstanceLink.href = addCurrentTimeToURL(changeInstanceLink.href);
|
|
|
|
});
|
2022-05-31 04:58:12 -04:00
|
|
|
});
|