mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-23 05:33:07 +05:30
commit
3bbd709bd6
@ -1,19 +1,20 @@
|
||||
var community_data = JSON.parse(document.getElementById('community_data').innerHTML);
|
||||
'use strict';
|
||||
var community_data = JSON.parse(document.getElementById('community_data').textContent);
|
||||
|
||||
String.prototype.supplant = function (o) {
|
||||
return this.replace(/{([^{}]*)}/g, function (a, b) {
|
||||
var r = o[b];
|
||||
return typeof r === 'string' || typeof r === 'number' ? r : a;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function hide_youtube_replies(event) {
|
||||
var target = event.target;
|
||||
|
||||
sub_text = target.getAttribute('data-inner-text');
|
||||
inner_text = target.getAttribute('data-sub-text');
|
||||
var sub_text = target.getAttribute('data-inner-text');
|
||||
var inner_text = target.getAttribute('data-sub-text');
|
||||
|
||||
body = target.parentNode.parentNode.children[1];
|
||||
var body = target.parentNode.parentNode.children[1];
|
||||
body.style.display = 'none';
|
||||
|
||||
target.innerHTML = sub_text;
|
||||
@ -25,10 +26,10 @@ function hide_youtube_replies(event) {
|
||||
function show_youtube_replies(event) {
|
||||
var target = event.target;
|
||||
|
||||
sub_text = target.getAttribute('data-inner-text');
|
||||
inner_text = target.getAttribute('data-sub-text');
|
||||
var sub_text = target.getAttribute('data-inner-text');
|
||||
var inner_text = target.getAttribute('data-sub-text');
|
||||
|
||||
body = target.parentNode.parentNode.children[1];
|
||||
var body = target.parentNode.parentNode.children[1];
|
||||
body.style.display = '';
|
||||
|
||||
target.innerHTML = sub_text;
|
||||
@ -63,8 +64,8 @@ function get_youtube_replies(target, load_more) {
|
||||
xhr.open('GET', url, true);
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status == 200) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
if (load_more) {
|
||||
body = body.parentNode.parentNode;
|
||||
body.removeChild(body.lastElementChild);
|
||||
@ -92,12 +93,12 @@ function get_youtube_replies(target, load_more) {
|
||||
body.innerHTML = fallback;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.ontimeout = function () {
|
||||
console.log('Pulling comments failed.');
|
||||
console.warn('Pulling comments failed.');
|
||||
body.innerHTML = fallback;
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
}
|
||||
|
@ -1,19 +1,21 @@
|
||||
var video_data = JSON.parse(document.getElementById('video_data').innerHTML);
|
||||
'use strict';
|
||||
var video_data = JSON.parse(document.getElementById('video_data').textContent);
|
||||
|
||||
function get_playlist(plid, retries) {
|
||||
if (retries == undefined) retries = 5;
|
||||
if (retries === undefined) retries = 5;
|
||||
|
||||
if (retries <= 0) {
|
||||
console.log('Failed to pull playlist');
|
||||
console.warn('Failed to pull playlist');
|
||||
return;
|
||||
}
|
||||
|
||||
var plid_url;
|
||||
if (plid.startsWith('RD')) {
|
||||
var plid_url = '/api/v1/mixes/' + plid +
|
||||
plid_url = '/api/v1/mixes/' + plid +
|
||||
'?continuation=' + video_data.id +
|
||||
'&format=html&hl=' + video_data.preferences.locale;
|
||||
} else {
|
||||
var plid_url = '/api/v1/playlists/' + plid +
|
||||
plid_url = '/api/v1/playlists/' + plid +
|
||||
'?index=' + video_data.index +
|
||||
'&continuation' + video_data.id +
|
||||
'&format=html&hl=' + video_data.preferences.locale;
|
||||
@ -57,17 +59,17 @@ function get_playlist(plid, retries) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
console.log('Pulling playlist failed... ' + retries + '/5');
|
||||
setTimeout(function () { get_playlist(plid, retries - 1) }, 1000);
|
||||
}
|
||||
console.warn('Pulling playlist failed... ' + retries + '/5');
|
||||
setTimeout(function () { get_playlist(plid, retries - 1); }, 1000);
|
||||
};
|
||||
|
||||
xhr.ontimeout = function () {
|
||||
console.log('Pulling playlist failed... ' + retries + '/5');
|
||||
console.warn('Pulling playlist failed... ' + retries + '/5');
|
||||
get_playlist(plid, retries - 1);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
}
|
||||
@ -96,7 +98,7 @@ window.addEventListener('load', function (e) {
|
||||
}
|
||||
|
||||
if (video_data.video_series.length !== 0) {
|
||||
url.searchParams.set('playlist', video_data.video_series.join(','))
|
||||
url.searchParams.set('playlist', video_data.video_series.join(','));
|
||||
}
|
||||
|
||||
location.assign(url.pathname + url.search);
|
||||
|
@ -76,7 +76,7 @@
|
||||
});
|
||||
|
||||
n2a(document.querySelectorAll('[data-onrange="update_volume_value"]')).forEach(function (e) {
|
||||
var cb = function () { update_volume_value(e); }
|
||||
var cb = function () { update_volume_value(e); };
|
||||
e.oninput = cb;
|
||||
e.onchange = cb;
|
||||
});
|
||||
@ -102,13 +102,13 @@
|
||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status != 200) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status !== 200) {
|
||||
count.innerText = parseInt(count.innerText) + 1;
|
||||
row.style.display = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var csrf_token = target.parentNode.querySelector('input[name="csrf_token"]').value;
|
||||
xhr.send('csrf_token=' + csrf_token);
|
||||
@ -131,20 +131,20 @@
|
||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status != 200) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status !== 200) {
|
||||
count.innerText = parseInt(count.innerText) + 1;
|
||||
row.style.display = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var csrf_token = target.parentNode.querySelector('input[name="csrf_token"]').value;
|
||||
xhr.send('csrf_token=' + csrf_token);
|
||||
}
|
||||
|
||||
// Handle keypresses
|
||||
window.addEventListener('keydown', (event) => {
|
||||
window.addEventListener('keydown', function (event) {
|
||||
// Ignore modifier keys
|
||||
if (event.ctrlKey || event.metaKey) return;
|
||||
|
||||
@ -152,14 +152,14 @@
|
||||
let focused_tag = document.activeElement.tagName.toLowerCase();
|
||||
const allowed = /^(button|checkbox|file|radio|submit)$/;
|
||||
|
||||
if (focused_tag === "textarea") return;
|
||||
if (focused_tag === "input") {
|
||||
if (focused_tag === 'textarea') return;
|
||||
if (focused_tag === 'input') {
|
||||
let focused_type = document.activeElement.type.toLowerCase();
|
||||
if (!focused_type.match(allowed)) return;
|
||||
}
|
||||
|
||||
// Focus search bar on '/'
|
||||
if (event.key == "/") {
|
||||
if (event.key === '/') {
|
||||
document.getElementById('searchbox').focus();
|
||||
event.preventDefault();
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
var notification_data = JSON.parse(document.getElementById('notification_data').innerHTML);
|
||||
'use strict';
|
||||
var notification_data = JSON.parse(document.getElementById('notification_data').textContent);
|
||||
|
||||
var notifications, delivered;
|
||||
|
||||
function get_subscriptions(callback, retries) {
|
||||
if (retries == undefined) retries = 5;
|
||||
if (retries === undefined) retries = 5;
|
||||
|
||||
if (retries <= 0) {
|
||||
return;
|
||||
@ -17,21 +18,21 @@ function get_subscriptions(callback, retries) {
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
subscriptions = xhr.response;
|
||||
var subscriptions = xhr.response;
|
||||
callback(subscriptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
console.log('Pulling subscriptions failed... ' + retries + '/5');
|
||||
setTimeout(function () { get_subscriptions(callback, retries - 1) }, 1000);
|
||||
}
|
||||
console.warn('Pulling subscriptions failed... ' + retries + '/5');
|
||||
setTimeout(function () { get_subscriptions(callback, retries - 1); }, 1000);
|
||||
};
|
||||
|
||||
xhr.ontimeout = function () {
|
||||
console.log('Pulling subscriptions failed... ' + retries + '/5');
|
||||
console.warn('Pulling subscriptions failed... ' + retries + '/5');
|
||||
get_subscriptions(callback, retries - 1);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
}
|
||||
@ -40,7 +41,7 @@ function create_notification_stream(subscriptions) {
|
||||
notifications = new SSE(
|
||||
'/api/v1/auth/notifications?fields=videoId,title,author,authorId,publishedText,published,authorThumbnails,liveNow', {
|
||||
withCredentials: true,
|
||||
payload: 'topics=' + subscriptions.map(function (subscription) { return subscription.authorId }).join(','),
|
||||
payload: 'topics=' + subscriptions.map(function (subscription) { return subscription.authorId; }).join(','),
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||
});
|
||||
delivered = [];
|
||||
@ -53,7 +54,7 @@ function create_notification_stream(subscriptions) {
|
||||
}
|
||||
|
||||
var notification = JSON.parse(event.data);
|
||||
console.log('Got notification:', notification);
|
||||
console.info('Got notification:', notification);
|
||||
|
||||
if (start_time < notification.published && !delivered.includes(notification.videoId)) {
|
||||
if (Notification.permission === 'granted') {
|
||||
@ -67,7 +68,7 @@ function create_notification_stream(subscriptions) {
|
||||
|
||||
system_notification.onclick = function (event) {
|
||||
window.open('/watch?v=' + event.currentTarget.tag, '_blank');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
delivered.push(notification.videoId);
|
||||
@ -82,16 +83,16 @@ function create_notification_stream(subscriptions) {
|
||||
'<i class="icon ion-ios-notifications-outline"></i>';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
notifications.addEventListener('error', handle_notification_error);
|
||||
notifications.stream();
|
||||
}
|
||||
|
||||
function handle_notification_error(event) {
|
||||
console.log('Something went wrong with notifications, trying to reconnect...');
|
||||
console.warn('Something went wrong with notifications, trying to reconnect...');
|
||||
notifications = { close: function () { } };
|
||||
setTimeout(function () { get_subscriptions(create_notification_stream) }, 1000);
|
||||
setTimeout(function () { get_subscriptions(create_notification_stream); }, 1000);
|
||||
}
|
||||
|
||||
window.addEventListener('load', function (e) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
var player_data = JSON.parse(document.getElementById('player_data').innerHTML);
|
||||
var video_data = JSON.parse(document.getElementById('video_data').innerHTML);
|
||||
'use strict';
|
||||
var player_data = JSON.parse(document.getElementById('player_data').textContent);
|
||||
var video_data = JSON.parse(document.getElementById('video_data').textContent);
|
||||
|
||||
var options = {
|
||||
preload: 'auto',
|
||||
@ -27,7 +28,7 @@ var options = {
|
||||
overrideNative: true
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (player_data.aspect_ratio) {
|
||||
options.aspectRatio = player_data.aspect_ratio;
|
||||
@ -38,7 +39,7 @@ embed_url.searchParams.delete('v');
|
||||
var short_url = location.origin + '/' + video_data.id + embed_url.search;
|
||||
embed_url = location.origin + '/embed/' + video_data.id + embed_url.search;
|
||||
|
||||
var save_player_pos_key = "save_player_pos";
|
||||
var save_player_pos_key = 'save_player_pos';
|
||||
|
||||
videojs.Vhs.xhr.beforeRequest = function(options) {
|
||||
if (options.uri.indexOf('videoplayback') === -1 && options.uri.indexOf('local=true') === -1) {
|
||||
@ -111,12 +112,12 @@ var shareOptions = {
|
||||
description: player_data.description,
|
||||
image: player_data.thumbnail,
|
||||
get embedCode() {
|
||||
return "<iframe id='ivplayer' width='640' height='360' src='" +
|
||||
addCurrentTimeToURL(embed_url) + "' style='border:none;'></iframe>";
|
||||
return '<iframe id="ivplayer" width="640" height="360" src="' +
|
||||
addCurrentTimeToURL(embed_url) + '" style="border:none;"></iframe>';
|
||||
}
|
||||
};
|
||||
|
||||
const storage = (() => {
|
||||
const storage = (function () {
|
||||
try { if (localStorage.length !== -1) return localStorage; }
|
||||
catch (e) { console.info('No storage available: ' + e); }
|
||||
|
||||
@ -137,57 +138,57 @@ if (location.pathname.startsWith('/embed/')) {
|
||||
// Detection code taken from https://stackoverflow.com/a/20293441
|
||||
|
||||
function isMobile() {
|
||||
try{ document.createEvent("TouchEvent"); return true; }
|
||||
try{ document.createEvent('TouchEvent'); return true; }
|
||||
catch(e){ return false; }
|
||||
}
|
||||
|
||||
if (isMobile()) {
|
||||
player.mobileUi();
|
||||
|
||||
buttons = ["playToggle", "volumePanel", "captionsButton"];
|
||||
var 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");
|
||||
const ControlBar = videojs.getComponent('controlBar');
|
||||
let operations_bar = new ControlBar(player, {
|
||||
children: [],
|
||||
playbackRates: [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0]
|
||||
});
|
||||
buttons.slice(1).forEach(child => operations_bar.addChild(child))
|
||||
buttons.slice(1).forEach(function (child) {operations_bar.addChild(child);});
|
||||
|
||||
// Remove operation buttons from primary control bar
|
||||
primary_control_bar = player.getChild("controlBar");
|
||||
buttons.forEach(child => primary_control_bar.removeChild(child));
|
||||
var primary_control_bar = player.getChild('controlBar');
|
||||
buttons.forEach(function (child) {primary_control_bar.removeChild(child);});
|
||||
|
||||
operations_bar_element = operations_bar.el();
|
||||
operations_bar_element.className += " mobile-operations-bar"
|
||||
player.addChild(operations_bar)
|
||||
var operations_bar_element = operations_bar.el();
|
||||
operations_bar_element.className += ' mobile-operations-bar';
|
||||
player.addChild(operations_bar);
|
||||
|
||||
// Playback menu doesn't work when it's initialized outside of the primary control bar
|
||||
playback_element = document.getElementsByClassName("vjs-playback-rate")[0]
|
||||
operations_bar_element.append(playback_element)
|
||||
var playback_element = document.getElementsByClassName('vjs-playback-rate')[0];
|
||||
operations_bar_element.append(playback_element);
|
||||
|
||||
// The share and http source selector element can't be fetched till the players ready.
|
||||
player.one("playing", () => {
|
||||
share_element = document.getElementsByClassName("vjs-share-control")[0]
|
||||
operations_bar_element.append(share_element)
|
||||
player.one('playing', function () {
|
||||
var share_element = document.getElementsByClassName('vjs-share-control')[0];
|
||||
operations_bar_element.append(share_element);
|
||||
|
||||
if (video_data.params.quality === 'dash') {
|
||||
http_source_selector = document.getElementsByClassName("vjs-http-source-selector vjs-menu-button")[0]
|
||||
operations_bar_element.append(http_source_selector)
|
||||
}
|
||||
})
|
||||
if (video_data.params.quality === 'dash') {
|
||||
var http_source_selector = document.getElementsByClassName('vjs-http-source-selector vjs-menu-button')[0];
|
||||
operations_bar_element.append(http_source_selector);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Enable VR video support
|
||||
if (!video_data.params.listen && video_data.vr && video_data.params.vr_mode) {
|
||||
player.crossOrigin("anonymous")
|
||||
player.crossOrigin('anonymous');
|
||||
switch (video_data.projection_type) {
|
||||
case "EQUIRECTANGULAR":
|
||||
player.vr({projection: "equirectangular"});
|
||||
default: // Should only be "MESH" but we'll use this as a fallback.
|
||||
player.vr({projection: "EAC"});
|
||||
case 'EQUIRECTANGULAR':
|
||||
player.vr({projection: 'equirectangular'});
|
||||
default: // Should only be 'MESH' but we'll use this as a fallback.
|
||||
player.vr({projection: 'EAC'});
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,27 +223,27 @@ player.playbackRate(video_data.params.speed);
|
||||
* @returns cookieValue
|
||||
*/
|
||||
function getCookieValue(name) {
|
||||
var value = document.cookie.split(";").filter(item => item.includes(name + "="));
|
||||
var value = document.cookie.split(';').filter(function (item) {return item.includes(name + '=');});
|
||||
|
||||
return (value != null && value.length >= 1)
|
||||
? value[0].substring((name + "=").length, value[0].length)
|
||||
return (value.length >= 1)
|
||||
? value[0].substring((name + '=').length, value[0].length)
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for updating the "PREFS" cookie (or creating it if missing)
|
||||
* Method for updating the 'PREFS' cookie (or creating it 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 volumeValue = newVolume !== null ? newVolume : video_data.params.volume;
|
||||
var speedValue = newSpeed !== null ? newSpeed : video_data.params.speed;
|
||||
|
||||
var cookieValue = getCookieValue('PREFS');
|
||||
var cookieData;
|
||||
|
||||
if (cookieValue != null) {
|
||||
if (cookieValue !== null) {
|
||||
var cookieJson = JSON.parse(decodeURIComponent(cookieValue));
|
||||
cookieJson.volume = volumeValue;
|
||||
cookieJson.speed = speedValue;
|
||||
@ -259,7 +260,7 @@ function updateCookie(newVolume, newSpeed) {
|
||||
var domainUsed = window.location.hostname;
|
||||
|
||||
// Fix for a bug in FF where the leading dot in the FQDN is not ignored
|
||||
if (domainUsed.charAt(0) != '.' && !ipRegex.test(domainUsed) && domainUsed != 'localhost')
|
||||
if (domainUsed.charAt(0) !== '.' && !ipRegex.test(domainUsed) && domainUsed !== 'localhost')
|
||||
domainUsed = '.' + window.location.hostname;
|
||||
|
||||
document.cookie = 'PREFS=' + cookieData + '; SameSite=Strict; path=/; domain=' +
|
||||
@ -279,7 +280,7 @@ player.on('volumechange', function () {
|
||||
|
||||
player.on('waiting', function () {
|
||||
if (player.playbackRate() > 1 && player.liveTracker.isLive() && player.liveTracker.atLiveEdge()) {
|
||||
console.log('Player has caught up to source, resetting playbackRate.')
|
||||
console.info('Player has caught up to source, resetting playbackRate.');
|
||||
player.playbackRate(1);
|
||||
}
|
||||
});
|
||||
@ -290,13 +291,13 @@ if (video_data.premiere_timestamp && Math.round(new Date() / 1000) < video_data.
|
||||
|
||||
if (video_data.params.save_player_pos) {
|
||||
const url = new URL(location);
|
||||
const hasTimeParam = url.searchParams.has("t");
|
||||
const hasTimeParam = url.searchParams.has('t');
|
||||
const remeberedTime = get_video_time();
|
||||
let lastUpdated = 0;
|
||||
|
||||
if(!hasTimeParam) set_seconds_after_start(remeberedTime);
|
||||
|
||||
const updateTime = () => {
|
||||
const updateTime = function () {
|
||||
const raw = player.currentTime();
|
||||
const time = Math.floor(raw);
|
||||
|
||||
@ -306,7 +307,7 @@ if (video_data.params.save_player_pos) {
|
||||
}
|
||||
};
|
||||
|
||||
player.on("timeupdate", updateTime);
|
||||
player.on('timeupdate', updateTime);
|
||||
}
|
||||
else remove_all_video_times();
|
||||
|
||||
@ -316,13 +317,13 @@ if (video_data.params.autoplay) {
|
||||
|
||||
player.ready(function () {
|
||||
new Promise(function (resolve, reject) {
|
||||
setTimeout(() => resolve(1), 1);
|
||||
setTimeout(function () {resolve(1);}, 1);
|
||||
}).then(function (result) {
|
||||
var promise = player.play();
|
||||
|
||||
if (promise !== undefined) {
|
||||
promise.then(_ => {
|
||||
}).catch(error => {
|
||||
promise.then(function () {
|
||||
}).catch(function (error) {
|
||||
bpb.show();
|
||||
});
|
||||
}
|
||||
@ -333,16 +334,16 @@ 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);
|
||||
if (video_data.params.quality_dash !== 'auto') {
|
||||
player.ready(function () {
|
||||
player.on('loadedmetadata', function () {
|
||||
const qualityLevels = Array.from(player.qualityLevels()).sort(function (a, b) {return a.height - b.height;});
|
||||
let targetQualityLevel;
|
||||
switch (video_data.params.quality_dash) {
|
||||
case "best":
|
||||
case 'best':
|
||||
targetQualityLevel = qualityLevels.length - 1;
|
||||
break;
|
||||
case "worst":
|
||||
case 'worst':
|
||||
targetQualityLevel = 0;
|
||||
break;
|
||||
default:
|
||||
@ -356,7 +357,7 @@ if (!video_data.params.listen && video_data.params.quality === 'dash') {
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < qualityLevels.length; i++) {
|
||||
qualityLevels[i].enabled = (i == targetQualityLevel);
|
||||
qualityLevels[i].enabled = (i === targetQualityLevel);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -390,10 +391,12 @@ if (!video_data.params.listen && video_data.params.annotations) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('__ar_annotation_click', e => {
|
||||
const { url, target, seconds } = e.detail;
|
||||
window.addEventListener('__ar_annotation_click', function (e) {
|
||||
const url = e.detail.url,
|
||||
target = e.detail.target,
|
||||
seconds = e.detail.seconds;
|
||||
var path = new URL(url);
|
||||
|
||||
if (path.href.startsWith('https://www.youtube.com/watch?') && seconds) {
|
||||
@ -463,7 +466,7 @@ function get_video_time() {
|
||||
|
||||
return timestamp || 0;
|
||||
}
|
||||
catch {
|
||||
catch (e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -474,7 +477,7 @@ function set_all_video_times(times) {
|
||||
try {
|
||||
storage.setItem(save_player_pos_key, JSON.stringify(times));
|
||||
} catch (e) {
|
||||
console.debug('set_all_video_times: ' + e);
|
||||
console.warn('set_all_video_times: ' + e);
|
||||
}
|
||||
} else {
|
||||
storage.removeItem(save_player_pos_key);
|
||||
@ -489,7 +492,7 @@ function get_all_video_times() {
|
||||
try {
|
||||
return JSON.parse(raw);
|
||||
} catch (e) {
|
||||
console.debug('get_all_video_times: ' + e);
|
||||
console.warn('get_all_video_times: ' + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -583,7 +586,7 @@ function increase_playback_rate(steps) {
|
||||
player.playbackRate(options.playbackRates[newIndex]);
|
||||
}
|
||||
|
||||
window.addEventListener('keydown', e => {
|
||||
window.addEventListener('keydown', function (e) {
|
||||
if (e.target.tagName.toLowerCase() === 'input') {
|
||||
// Ignore input when focus is on certain elements, e.g. form fields.
|
||||
return;
|
||||
@ -702,7 +705,7 @@ window.addEventListener('keydown', e => {
|
||||
|
||||
var volumeHover = false;
|
||||
var volumeSelector = pEl.querySelector('.vjs-volume-menu-button') || pEl.querySelector('.vjs-volume-panel');
|
||||
if (volumeSelector != null) {
|
||||
if (volumeSelector !== null) {
|
||||
volumeSelector.onmouseover = function () { volumeHover = true; };
|
||||
volumeSelector.onmouseout = function () { volumeHover = false; };
|
||||
}
|
||||
@ -722,9 +725,9 @@ window.addEventListener('keydown', e => {
|
||||
var delta = Math.max(-1, Math.min(1, (event.wheelDelta || -event.detail)));
|
||||
event.preventDefault();
|
||||
|
||||
if (delta == 1) {
|
||||
if (delta === 1) {
|
||||
increase_volume(volumeStep);
|
||||
} else if (delta == -1) {
|
||||
} else if (delta === -1) {
|
||||
increase_volume(-volumeStep);
|
||||
}
|
||||
}
|
||||
@ -733,7 +736,7 @@ window.addEventListener('keydown', e => {
|
||||
};
|
||||
|
||||
player.on('mousewheel', mouseScroll);
|
||||
player.on("DOMMouseScroll", mouseScroll);
|
||||
player.on('DOMMouseScroll', mouseScroll);
|
||||
}());
|
||||
|
||||
// Since videojs-share can sometimes be blocked, we defer it until last
|
||||
@ -743,13 +746,13 @@ if (player.share) {
|
||||
|
||||
// show the preferred caption by default
|
||||
if (player_data.preferred_caption_found) {
|
||||
player.ready(() => {
|
||||
player.ready(function () {
|
||||
player.textTracks()[1].mode = 'showing';
|
||||
});
|
||||
}
|
||||
|
||||
// Safari audio double duration fix
|
||||
if (navigator.vendor == "Apple Computer, Inc." && video_data.params.listen) {
|
||||
if (navigator.vendor === 'Apple Computer, Inc.' && video_data.params.listen) {
|
||||
player.on('loadedmetadata', function () {
|
||||
player.on('timeupdate', function () {
|
||||
if (player.remainingTime() < player.duration() / 2 && player.remainingTime() >= 2) {
|
||||
@ -760,18 +763,18 @@ if (navigator.vendor == "Apple Computer, Inc." && video_data.params.listen) {
|
||||
}
|
||||
|
||||
// Watch on Invidious link
|
||||
if (window.location.pathname.startsWith("/embed/")) {
|
||||
if (window.location.pathname.startsWith('/embed/')) {
|
||||
const Button = videojs.getComponent('Button');
|
||||
let watch_on_invidious_button = new Button(player);
|
||||
|
||||
// Create hyperlink for current instance
|
||||
redirect_element = document.createElement("a");
|
||||
redirect_element.setAttribute("href", `//${window.location.host}/watch?v=${window.location.pathname.replace("/embed/","")}`)
|
||||
redirect_element.appendChild(document.createTextNode("Invidious"))
|
||||
var redirect_element = document.createElement('a');
|
||||
redirect_element.setAttribute('href', location.pathname.replace('/embed/', '/watch?v='));
|
||||
redirect_element.appendChild(document.createTextNode('Invidious'));
|
||||
|
||||
watch_on_invidious_button.el().appendChild(redirect_element)
|
||||
watch_on_invidious_button.addClass("watch-on-invidious")
|
||||
watch_on_invidious_button.el().appendChild(redirect_element);
|
||||
watch_on_invidious_button.addClass('watch-on-invidious');
|
||||
|
||||
cb = player.getChild('ControlBar')
|
||||
cb.addChild(watch_on_invidious_button)
|
||||
};
|
||||
var cb = player.getChild('ControlBar');
|
||||
cb.addChild(watch_on_invidious_button);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
var playlist_data = JSON.parse(document.getElementById('playlist_data').innerHTML);
|
||||
'use strict';
|
||||
var playlist_data = JSON.parse(document.getElementById('playlist_data').textContent);
|
||||
|
||||
function add_playlist_video(target) {
|
||||
var select = target.parentNode.children[0].children[1];
|
||||
@ -14,12 +15,12 @@ function add_playlist_video(target) {
|
||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status == 200) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
option.innerText = '✓' + option.innerText;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send('csrf_token=' + playlist_data.csrf_token);
|
||||
}
|
||||
@ -38,12 +39,12 @@ function add_playlist_item(target) {
|
||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status != 200) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status !== 200) {
|
||||
tile.style.display = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send('csrf_token=' + playlist_data.csrf_token);
|
||||
}
|
||||
@ -62,12 +63,12 @@ function remove_playlist_item(target) {
|
||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status != 200) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status !== 200) {
|
||||
tile.style.display = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send('csrf_token=' + playlist_data.csrf_token);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
var subscribe_data = JSON.parse(document.getElementById('subscribe_data').innerHTML);
|
||||
'use strict';
|
||||
var subscribe_data = JSON.parse(document.getElementById('subscribe_data').textContent);
|
||||
|
||||
var subscribe_button = document.getElementById('subscribe');
|
||||
subscribe_button.parentNode['action'] = 'javascript:void(0)';
|
||||
@ -9,9 +10,11 @@ if (subscribe_button.getAttribute('data-type') === 'subscribe') {
|
||||
subscribe_button.onclick = unsubscribe;
|
||||
}
|
||||
|
||||
function subscribe(retries = 5) {
|
||||
function subscribe(retries) {
|
||||
if (retries === undefined) retries = 5;
|
||||
|
||||
if (retries <= 0) {
|
||||
console.log('Failed to subscribe.');
|
||||
console.warn('Failed to subscribe.');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -28,30 +31,33 @@ function subscribe(retries = 5) {
|
||||
subscribe_button.innerHTML = '<b>' + subscribe_data.unsubscribe_text + ' | ' + subscribe_data.sub_count_text + '</b>';
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status != 200) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status !== 200) {
|
||||
subscribe_button.onclick = subscribe;
|
||||
subscribe_button.innerHTML = fallback;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
console.log('Subscribing failed... ' + retries + '/5');
|
||||
setTimeout(function () { subscribe(retries - 1) }, 1000);
|
||||
}
|
||||
console.warn('Subscribing failed... ' + retries + '/5');
|
||||
setTimeout(function () { subscribe(retries - 1); }, 1000);
|
||||
};
|
||||
|
||||
xhr.ontimeout = function () {
|
||||
console.log('Subscribing failed... ' + retries + '/5');
|
||||
console.warn('Subscribing failed... ' + retries + '/5');
|
||||
subscribe(retries - 1);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send('csrf_token=' + subscribe_data.csrf_token);
|
||||
}
|
||||
|
||||
function unsubscribe(retries = 5) {
|
||||
function unsubscribe(retries) {
|
||||
if (retries === undefined)
|
||||
retries = 5;
|
||||
|
||||
if (retries <= 0) {
|
||||
console.log('Failed to subscribe');
|
||||
console.warn('Failed to subscribe');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -68,23 +74,23 @@ function unsubscribe(retries = 5) {
|
||||
subscribe_button.innerHTML = '<b>' + subscribe_data.subscribe_text + ' | ' + subscribe_data.sub_count_text + '</b>';
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status != 200) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status !== 200) {
|
||||
subscribe_button.onclick = unsubscribe;
|
||||
subscribe_button.innerHTML = fallback;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
console.log('Unsubscribing failed... ' + retries + '/5');
|
||||
setTimeout(function () { unsubscribe(retries - 1) }, 1000);
|
||||
}
|
||||
console.warn('Unsubscribing failed... ' + retries + '/5');
|
||||
setTimeout(function () { unsubscribe(retries - 1); }, 1000);
|
||||
};
|
||||
|
||||
xhr.ontimeout = function () {
|
||||
console.log('Unsubscribing failed... ' + retries + '/5');
|
||||
console.warn('Unsubscribing failed... ' + retries + '/5');
|
||||
unsubscribe(retries - 1);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send('csrf_token=' + subscribe_data.csrf_token);
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
'use strict';
|
||||
var toggle_theme = document.getElementById('toggle_theme');
|
||||
toggle_theme.href = 'javascript:void(0);';
|
||||
|
||||
toggle_theme.addEventListener('click', function () {
|
||||
var dark_mode = document.body.classList.contains("light-theme");
|
||||
var dark_mode = document.body.classList.contains('light-theme');
|
||||
|
||||
var url = '/toggle_theme?redirect=false';
|
||||
var xhr = new XMLHttpRequest();
|
||||
@ -13,7 +14,7 @@ toggle_theme.addEventListener('click', function () {
|
||||
set_mode(dark_mode);
|
||||
try {
|
||||
window.localStorage.setItem('dark_mode', dark_mode ? 'dark' : 'light');
|
||||
} catch {}
|
||||
} catch (e) {}
|
||||
|
||||
xhr.send();
|
||||
});
|
||||
@ -29,7 +30,7 @@ window.addEventListener('DOMContentLoaded', function () {
|
||||
try {
|
||||
// Update localStorage if dark mode preference changed on preferences page
|
||||
window.localStorage.setItem('dark_mode', dark_mode);
|
||||
} catch {}
|
||||
} catch (e) {}
|
||||
update_mode(dark_mode);
|
||||
});
|
||||
|
||||
@ -46,11 +47,11 @@ function scheme_switch (e) {
|
||||
if (localStorage.getItem('dark_mode')) {
|
||||
return;
|
||||
}
|
||||
} catch {}
|
||||
} catch (exception) {}
|
||||
if (e.matches) {
|
||||
if (e.media.includes("dark")) {
|
||||
if (e.media.includes('dark')) {
|
||||
set_mode(true);
|
||||
} else if (e.media.includes("light")) {
|
||||
} else if (e.media.includes('light')) {
|
||||
set_mode(false);
|
||||
}
|
||||
}
|
||||
@ -77,15 +78,13 @@ function update_mode (mode) {
|
||||
// If preference for dark mode indicated
|
||||
set_mode(true);
|
||||
}
|
||||
else if (mode === 'false' /* for backwards compatibility */ || mode === 'light') {
|
||||
// If preference for light mode indicated
|
||||
set_mode(false);
|
||||
}
|
||||
else if (mode === 'false' /* for backwards compatibility */ || mode === 'light') {
|
||||
// If preference for light mode indicated
|
||||
set_mode(false);
|
||||
}
|
||||
else if (document.getElementById('dark_mode_pref').textContent === '' && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
// If no preference indicated here and no preference indicated on the preferences page (backend), but the browser tells us that the operating system has a dark theme
|
||||
set_mode(true);
|
||||
}
|
||||
// else do nothing, falling back to the mode defined by the `dark_mode` preference on the preferences page (backend)
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,31 +1,32 @@
|
||||
var video_data = JSON.parse(document.getElementById('video_data').innerHTML);
|
||||
'use strict';
|
||||
var video_data = JSON.parse(document.getElementById('video_data').textContent);
|
||||
|
||||
String.prototype.supplant = function (o) {
|
||||
return this.replace(/{([^{}]*)}/g, function (a, b) {
|
||||
var r = o[b];
|
||||
return typeof r === 'string' || typeof r === 'number' ? r : a;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function toggle_parent(target) {
|
||||
body = target.parentNode.parentNode.children[1];
|
||||
var body = target.parentNode.parentNode.children[1];
|
||||
if (body.style.display === null || body.style.display === '') {
|
||||
target.innerHTML = '[ + ]';
|
||||
target.textContent = '[ + ]';
|
||||
body.style.display = 'none';
|
||||
} else {
|
||||
target.innerHTML = '[ - ]';
|
||||
target.textContent = '[ − ]';
|
||||
body.style.display = '';
|
||||
}
|
||||
}
|
||||
|
||||
function toggle_comments(event) {
|
||||
var target = event.target;
|
||||
body = target.parentNode.parentNode.parentNode.children[1];
|
||||
var body = target.parentNode.parentNode.parentNode.children[1];
|
||||
if (body.style.display === null || body.style.display === '') {
|
||||
target.innerHTML = '[ + ]';
|
||||
target.textContent = '[ + ]';
|
||||
body.style.display = 'none';
|
||||
} else {
|
||||
target.innerHTML = '[ - ]';
|
||||
target.textContent = '[ − ]';
|
||||
body.style.display = '';
|
||||
}
|
||||
}
|
||||
@ -43,13 +44,13 @@ function swap_comments(event) {
|
||||
function hide_youtube_replies(event) {
|
||||
var target = event.target;
|
||||
|
||||
sub_text = target.getAttribute('data-inner-text');
|
||||
inner_text = target.getAttribute('data-sub-text');
|
||||
var sub_text = target.getAttribute('data-inner-text');
|
||||
var inner_text = target.getAttribute('data-sub-text');
|
||||
|
||||
body = target.parentNode.parentNode.children[1];
|
||||
var body = target.parentNode.parentNode.children[1];
|
||||
body.style.display = 'none';
|
||||
|
||||
target.innerHTML = sub_text;
|
||||
target.textContent = sub_text;
|
||||
target.onclick = show_youtube_replies;
|
||||
target.setAttribute('data-inner-text', inner_text);
|
||||
target.setAttribute('data-sub-text', sub_text);
|
||||
@ -58,13 +59,13 @@ function hide_youtube_replies(event) {
|
||||
function show_youtube_replies(event) {
|
||||
var target = event.target;
|
||||
|
||||
sub_text = target.getAttribute('data-inner-text');
|
||||
inner_text = target.getAttribute('data-sub-text');
|
||||
var sub_text = target.getAttribute('data-inner-text');
|
||||
var inner_text = target.getAttribute('data-sub-text');
|
||||
|
||||
body = target.parentNode.parentNode.children[1];
|
||||
var body = target.parentNode.parentNode.children[1];
|
||||
body.style.display = '';
|
||||
|
||||
target.innerHTML = sub_text;
|
||||
target.textContent = sub_text;
|
||||
target.onclick = hide_youtube_replies;
|
||||
target.setAttribute('data-inner-text', inner_text);
|
||||
target.setAttribute('data-sub-text', sub_text);
|
||||
@ -116,25 +117,26 @@ function number_with_separator(val) {
|
||||
}
|
||||
|
||||
function get_playlist(plid, retries) {
|
||||
if (retries == undefined) retries = 5;
|
||||
playlist = document.getElementById('playlist');
|
||||
if (retries === undefined) retries = 5;
|
||||
var playlist = document.getElementById('playlist');
|
||||
|
||||
if (retries <= 0) {
|
||||
console.log('Failed to pull playlist');
|
||||
console.warn('Failed to pull playlist');
|
||||
playlist.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
playlist.innerHTML = ' \
|
||||
<h3 style="text-align:center"><div class="loading"><i class="icon ion-ios-refresh"></i></div></h3> \
|
||||
<hr>'
|
||||
<hr>';
|
||||
|
||||
var plid_url;
|
||||
if (plid.startsWith('RD')) {
|
||||
var plid_url = '/api/v1/mixes/' + plid +
|
||||
plid_url = '/api/v1/mixes/' + plid +
|
||||
'?continuation=' + video_data.id +
|
||||
'&format=html&hl=' + video_data.preferences.locale;
|
||||
} else {
|
||||
var plid_url = '/api/v1/playlists/' + plid +
|
||||
plid_url = '/api/v1/playlists/' + plid +
|
||||
'?index=' + video_data.index +
|
||||
'&continuation=' + video_data.id +
|
||||
'&format=html&hl=' + video_data.preferences.locale;
|
||||
@ -146,8 +148,8 @@ function get_playlist(plid, retries) {
|
||||
xhr.open('GET', plid_url, true);
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status == 200) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
playlist.innerHTML = xhr.response.playlistHtml;
|
||||
var nextVideo = document.getElementById(xhr.response.nextVideo);
|
||||
nextVideo.parentNode.parentNode.scrollTop = nextVideo.offsetTop;
|
||||
@ -185,35 +187,35 @@ function get_playlist(plid, retries) {
|
||||
document.getElementById('continue').style.display = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
playlist = document.getElementById('playlist');
|
||||
playlist.innerHTML =
|
||||
'<h3 style="text-align:center"><div class="loading"><i class="icon ion-ios-refresh"></i></div></h3><hr>';
|
||||
|
||||
console.log('Pulling playlist timed out... ' + retries + '/5');
|
||||
setTimeout(function () { get_playlist(plid, retries - 1) }, 1000);
|
||||
}
|
||||
console.warn('Pulling playlist timed out... ' + retries + '/5');
|
||||
setTimeout(function () { get_playlist(plid, retries - 1); }, 1000);
|
||||
};
|
||||
|
||||
xhr.ontimeout = function () {
|
||||
playlist = document.getElementById('playlist');
|
||||
playlist.innerHTML =
|
||||
'<h3 style="text-align:center"><div class="loading"><i class="icon ion-ios-refresh"></i></div></h3><hr>';
|
||||
|
||||
console.log('Pulling playlist timed out... ' + retries + '/5');
|
||||
console.warn('Pulling playlist timed out... ' + retries + '/5');
|
||||
get_playlist(plid, retries - 1);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function get_reddit_comments(retries) {
|
||||
if (retries == undefined) retries = 5;
|
||||
comments = document.getElementById('comments');
|
||||
if (retries === undefined) retries = 5;
|
||||
var comments = document.getElementById('comments');
|
||||
|
||||
if (retries <= 0) {
|
||||
console.log('Failed to pull comments');
|
||||
console.warn('Failed to pull comments');
|
||||
comments.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
@ -231,12 +233,12 @@ function get_reddit_comments(retries) {
|
||||
xhr.open('GET', url, true);
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status == 200) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
comments.innerHTML = ' \
|
||||
<div> \
|
||||
<h3> \
|
||||
<a href="javascript:void(0)">[ - ]</a> \
|
||||
<a href="javascript:void(0)">[ − ]</a> \
|
||||
{title} \
|
||||
</h3> \
|
||||
<p> \
|
||||
@ -263,34 +265,34 @@ function get_reddit_comments(retries) {
|
||||
comments.children[0].children[1].children[0].onclick = swap_comments;
|
||||
} else {
|
||||
if (video_data.params.comments[1] === 'youtube') {
|
||||
console.log('Pulling comments failed... ' + retries + '/5');
|
||||
setTimeout(function () { get_youtube_comments(retries - 1) }, 1000);
|
||||
console.warn('Pulling comments failed... ' + retries + '/5');
|
||||
setTimeout(function () { get_youtube_comments(retries - 1); }, 1000);
|
||||
} else {
|
||||
comments.innerHTML = fallback;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
console.log('Pulling comments failed... ' + retries + '/5');
|
||||
setTimeout(function () { get_reddit_comments(retries - 1) }, 1000);
|
||||
}
|
||||
console.warn('Pulling comments failed... ' + retries + '/5');
|
||||
setTimeout(function () { get_reddit_comments(retries - 1); }, 1000);
|
||||
};
|
||||
|
||||
xhr.ontimeout = function () {
|
||||
console.log('Pulling comments failed... ' + retries + '/5');
|
||||
console.warn('Pulling comments failed... ' + retries + '/5');
|
||||
get_reddit_comments(retries - 1);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function get_youtube_comments(retries) {
|
||||
if (retries == undefined) retries = 5;
|
||||
comments = document.getElementById('comments');
|
||||
if (retries === undefined) retries = 5;
|
||||
var comments = document.getElementById('comments');
|
||||
|
||||
if (retries <= 0) {
|
||||
console.log('Failed to pull comments');
|
||||
console.warn('Failed to pull comments');
|
||||
comments.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
@ -309,12 +311,12 @@ function get_youtube_comments(retries) {
|
||||
xhr.open('GET', url, true);
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status == 200) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
comments.innerHTML = ' \
|
||||
<div> \
|
||||
<h3> \
|
||||
<a href="javascript:void(0)">[ - ]</a> \
|
||||
<a href="javascript:void(0)">[ − ]</a> \
|
||||
{commentsText} \
|
||||
</h3> \
|
||||
<b> \
|
||||
@ -336,27 +338,27 @@ function get_youtube_comments(retries) {
|
||||
comments.children[0].children[1].children[0].onclick = swap_comments;
|
||||
} else {
|
||||
if (video_data.params.comments[1] === 'youtube') {
|
||||
setTimeout(function () { get_youtube_comments(retries - 1) }, 1000);
|
||||
setTimeout(function () { get_youtube_comments(retries - 1); }, 1000);
|
||||
} else {
|
||||
comments.innerHTML = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
comments.innerHTML =
|
||||
'<h3 style="text-align:center"><div class="loading"><i class="icon ion-ios-refresh"></i></div></h3>';
|
||||
console.log('Pulling comments failed... ' + retries + '/5');
|
||||
setTimeout(function () { get_youtube_comments(retries - 1) }, 1000);
|
||||
}
|
||||
console.warn('Pulling comments failed... ' + retries + '/5');
|
||||
setTimeout(function () { get_youtube_comments(retries - 1); }, 1000);
|
||||
};
|
||||
|
||||
xhr.ontimeout = function () {
|
||||
comments.innerHTML =
|
||||
'<h3 style="text-align:center"><div class="loading"><i class="icon ion-ios-refresh"></i></div></h3>';
|
||||
console.log('Pulling comments failed... ' + retries + '/5');
|
||||
console.warn('Pulling comments failed... ' + retries + '/5');
|
||||
get_youtube_comments(retries - 1);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
}
|
||||
@ -373,7 +375,7 @@ function get_youtube_replies(target, load_more, load_replies) {
|
||||
'?format=html' +
|
||||
'&hl=' + video_data.preferences.locale +
|
||||
'&thin_mode=' + video_data.preferences.thin_mode +
|
||||
'&continuation=' + continuation
|
||||
'&continuation=' + continuation;
|
||||
if (load_replies) {
|
||||
url += '&action=action_get_comment_replies';
|
||||
}
|
||||
@ -383,8 +385,8 @@ function get_youtube_replies(target, load_more, load_replies) {
|
||||
xhr.open('GET', url, true);
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status == 200) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
if (load_more) {
|
||||
body = body.parentNode.parentNode;
|
||||
body.removeChild(body.lastElementChild);
|
||||
@ -412,12 +414,12 @@ function get_youtube_replies(target, load_more, load_replies) {
|
||||
body.innerHTML = fallback;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.ontimeout = function () {
|
||||
console.log('Pulling comments failed.');
|
||||
console.warn('Pulling comments failed.');
|
||||
body.innerHTML = fallback;
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
}
|
||||
@ -461,7 +463,7 @@ window.addEventListener('load', function (e) {
|
||||
} else if (video_data.params.comments[1] === 'reddit') {
|
||||
get_reddit_comments();
|
||||
} else {
|
||||
comments = document.getElementById('comments');
|
||||
var comments = document.getElementById('comments');
|
||||
comments.innerHTML = '';
|
||||
}
|
||||
});
|
||||
|
@ -1,4 +1,5 @@
|
||||
var watched_data = JSON.parse(document.getElementById('watched_data').innerHTML);
|
||||
'use strict';
|
||||
var watched_data = JSON.parse(document.getElementById('watched_data').textContent);
|
||||
|
||||
function mark_watched(target) {
|
||||
var tile = target.parentNode.parentNode.parentNode.parentNode.parentNode;
|
||||
@ -13,12 +14,12 @@ function mark_watched(target) {
|
||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status != 200) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status !== 200) {
|
||||
tile.style.display = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send('csrf_token=' + watched_data.csrf_token);
|
||||
}
|
||||
@ -26,7 +27,7 @@ function mark_watched(target) {
|
||||
function mark_unwatched(target) {
|
||||
var tile = target.parentNode.parentNode.parentNode.parentNode.parentNode;
|
||||
tile.style.display = 'none';
|
||||
var count = document.getElementById('count')
|
||||
var count = document.getElementById('count');
|
||||
count.innerText = count.innerText - 1;
|
||||
|
||||
var url = '/watch_ajax?action_mark_unwatched=1&redirect=false' +
|
||||
@ -38,13 +39,13 @@ function mark_unwatched(target) {
|
||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status != 200) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status !== 200) {
|
||||
count.innerText = count.innerText - 1 + 2;
|
||||
tile.style.display = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send('csrf_token=' + watched_data.csrf_token);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user