summaryrefslogtreecommitdiffstats
path: root/assets/js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/js')
-rw-r--r--assets/js/embed.js9
-rw-r--r--assets/js/player.js41
-rw-r--r--assets/js/themes.js15
-rw-r--r--assets/js/watch.js9
4 files changed, 60 insertions, 14 deletions
diff --git a/assets/js/embed.js b/assets/js/embed.js
index 99d2fc53..9d0be0ea 100644
--- a/assets/js/embed.js
+++ b/assets/js/embed.js
@@ -31,6 +31,11 @@ function get_playlist(plid, retries) {
player.on('ended', function () {
var url = new URL('https://example.com/embed/' + xhr.response.nextVideo);
+ url.searchParams.set('list', plid);
+ if (!plid.startsWith('RD')) {
+ url.searchParams.set('index', xhr.response.index);
+ }
+
if (video_data.params.autoplay || video_data.params.continue_autoplay) {
url.searchParams.set('autoplay', '1');
}
@@ -47,10 +52,6 @@ function get_playlist(plid, retries) {
url.searchParams.set('local', video_data.params.local);
}
- url.searchParams.set('list', plid);
- if (!plid.startsWith('RD')) {
- url.searchParams.set('index', xhr.response.index);
- }
location.assign(url.pathname + url.search);
});
}
diff --git a/assets/js/player.js b/assets/js/player.js
index f79fbbf3..fcba43d8 100644
--- a/assets/js/player.js
+++ b/assets/js/player.js
@@ -41,8 +41,16 @@ var shareOptions = {
embedCode: "<iframe id='ivplayer' width='640' height='360' src='" + embed_url + "' style='border:none;'></iframe>"
}
+videojs.Hls.xhr.beforeRequest = function(options) {
+ if (options.uri.indexOf('local=true') === -1) {
+ options.uri = options.uri + '?local=true';
+ }
+ return options;
+};
+
var player = videojs('player', options);
+
if (location.pathname.startsWith('/embed/')) {
player.overlay({
overlays: [{
@@ -146,6 +154,35 @@ if (video_data.params.autoplay) {
if (!video_data.params.listen && video_data.params.quality === 'dash') {
player.httpSourceSelector();
+
+ if (video_data.params.quality_dash != "auto") {
+ player.ready(() => {
+ player.on("loadedmetadata", () => {
+ const qualityLevels = Array.from(player.qualityLevels()).sort((a, b) => a.height - b.height);
+ let targetQualityLevel;
+ switch (video_data.params.quality_dash) {
+ case "best":
+ targetQualityLevel = qualityLevels.length - 1;
+ break;
+ case "worst":
+ targetQualityLevel = 0;
+ break;
+ default:
+ const targetHeight = Number.parseInt(video_data.params.quality_dash, 10);
+ for (let i = 0; i < qualityLevels.length; i++) {
+ if (qualityLevels[i].height <= targetHeight) {
+ targetQualityLevel = i;
+ } else {
+ break;
+ }
+ }
+ }
+ for (let i = 0; i < qualityLevels.length; i++) {
+ qualityLevels[i].enabled = (i == targetQualityLevel);
+ }
+ });
+ });
+ }
}
player.vttThumbnails({
@@ -502,4 +539,6 @@ window.addEventListener('keydown', e => {
}());
// Since videojs-share can sometimes be blocked, we defer it until last
-player.share(shareOptions);
+if (player.share) {
+ player.share(shareOptions);
+}
diff --git a/assets/js/themes.js b/assets/js/themes.js
index c600073d..543b849e 100644
--- a/assets/js/themes.js
+++ b/assets/js/themes.js
@@ -2,7 +2,7 @@ var toggle_theme = document.getElementById('toggle_theme');
toggle_theme.href = 'javascript:void(0);';
toggle_theme.addEventListener('click', function () {
- var dark_mode = document.getElementById('dark_theme').media === 'none';
+ var dark_mode = document.body.classList.contains("light-theme");
var url = '/toggle_theme?redirect=false';
var xhr = new XMLHttpRequest();
@@ -22,7 +22,7 @@ window.addEventListener('storage', function (e) {
}
});
-window.addEventListener('load', function () {
+window.addEventListener('DOMContentLoaded', function () {
window.localStorage.setItem('dark_mode', document.getElementById('dark_mode_pref').textContent);
// Update localStorage if dark mode preference changed on preferences page
update_mode(window.localStorage.dark_mode);
@@ -50,13 +50,18 @@ function scheme_switch (e) {
}
function set_mode (bool) {
- document.getElementById('dark_theme').media = !bool ? 'none' : '';
- document.getElementById('light_theme').media = bool ? 'none' : '';
-
if (bool) {
+ // dark
toggle_theme.children[0].setAttribute('class', 'icon ion-ios-sunny');
+ document.body.classList.remove('no-theme');
+ document.body.classList.remove('light-theme');
+ document.body.classList.add('dark-theme');
} else {
+ // light
toggle_theme.children[0].setAttribute('class', 'icon ion-ios-moon');
+ document.body.classList.remove('no-theme');
+ document.body.classList.remove('dark-theme');
+ document.body.classList.add('light-theme');
}
}
diff --git a/assets/js/watch.js b/assets/js/watch.js
index e9ad2ddc..05530f3d 100644
--- a/assets/js/watch.js
+++ b/assets/js/watch.js
@@ -154,6 +154,11 @@ function get_playlist(plid, retries) {
player.on('ended', function () {
var url = new URL('https://example.com/watch?v=' + xhr.response.nextVideo);
+ url.searchParams.set('list', plid);
+ if (!plid.startsWith('RD')) {
+ url.searchParams.set('index', xhr.response.index);
+ }
+
if (video_data.params.autoplay || video_data.params.continue_autoplay) {
url.searchParams.set('autoplay', '1');
}
@@ -170,10 +175,6 @@ function get_playlist(plid, retries) {
url.searchParams.set('local', video_data.params.local);
}
- url.searchParams.set('list', plid);
- if (!plid.startsWith('RD')) {
- url.searchParams.set('index', xhr.response.index);
- }
location.assign(url.pathname + url.search);
});
}