2020-03-15 14:46:08 -07:00
|
|
|
'use strict';
|
|
|
|
|
2020-03-15 15:52:49 -07:00
|
|
|
(function () {
|
2020-03-27 07:47:46 -07:00
|
|
|
var video_player = document.getElementById('player_html5_api');
|
2020-03-15 14:46:08 -07:00
|
|
|
if (video_player) {
|
2020-03-15 15:52:49 -07:00
|
|
|
video_player.onmouseenter = function () { video_player['data-title'] = video_player['title']; video_player['title'] = ''; };
|
|
|
|
video_player.onmouseleave = function () { video_player['title'] = video_player['data-title']; video_player['data-title'] = ''; };
|
|
|
|
video_player.oncontextmenu = function () { video_player['title'] = video_player['data-title']; };
|
2020-03-15 14:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// For dynamically inserted elements
|
2022-05-05 18:46:59 -07:00
|
|
|
addEventListener('click', function (e) {
|
|
|
|
if (!e || !e.target) return;
|
2022-05-01 10:08:11 -07:00
|
|
|
|
|
|
|
var t = e.target;
|
|
|
|
var handler_name = t.getAttribute('data-onclick');
|
|
|
|
|
2020-03-15 14:46:08 -07:00
|
|
|
switch (handler_name) {
|
2020-03-15 15:52:49 -07:00
|
|
|
case 'jump_to_time':
|
2022-05-01 10:08:11 -07:00
|
|
|
e.preventDefault();
|
|
|
|
var time = t.getAttribute('data-jump-time');
|
2020-03-15 15:52:49 -07:00
|
|
|
player.currentTime(time);
|
|
|
|
break;
|
|
|
|
case 'get_youtube_replies':
|
2022-05-01 10:08:11 -07:00
|
|
|
var load_more = t.getAttribute('data-load-more') !== null;
|
|
|
|
var load_replies = t.getAttribute('data-load-replies') !== null;
|
|
|
|
get_youtube_replies(t, load_more, load_replies);
|
2020-03-15 15:52:49 -07:00
|
|
|
break;
|
|
|
|
case 'toggle_parent':
|
2022-05-05 18:46:59 -07:00
|
|
|
e.preventDefault();
|
2022-05-01 10:08:11 -07:00
|
|
|
toggle_parent(t);
|
2020-03-15 15:52:49 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2020-03-15 14:46:08 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-05-05 18:46:59 -07:00
|
|
|
document.querySelectorAll('[data-mouse="switch_classes"]').forEach(function (el) {
|
|
|
|
var classes = el.getAttribute('data-switch-classes').split(',');
|
|
|
|
var classOnEnter = classes[0];
|
|
|
|
var classOnLeave = classes[1];
|
|
|
|
function toggle_classes(toAdd, toRemove) {
|
|
|
|
el.classList.add(toAdd);
|
|
|
|
el.classList.remove(toRemove);
|
|
|
|
}
|
|
|
|
el.onmouseenter = function () { toggle_classes(classOnEnter, classOnLeave); };
|
|
|
|
el.onmouseleave = function () { toggle_classes(classOnLeave, classOnEnter); };
|
2020-03-15 14:46:08 -07:00
|
|
|
});
|
|
|
|
|
2022-05-05 18:46:59 -07:00
|
|
|
document.querySelectorAll('[data-onsubmit="return_false"]').forEach(function (el) {
|
|
|
|
el.onsubmit = function () { return false; };
|
2020-03-15 14:46:08 -07:00
|
|
|
});
|
|
|
|
|
2022-05-05 18:46:59 -07:00
|
|
|
document.querySelectorAll('[data-onclick="mark_watched"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { mark_watched(el); };
|
2020-03-15 14:46:08 -07:00
|
|
|
});
|
2022-05-05 18:46:59 -07:00
|
|
|
document.querySelectorAll('[data-onclick="mark_unwatched"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { mark_unwatched(el); };
|
2020-03-15 14:46:08 -07:00
|
|
|
});
|
2022-05-05 18:46:59 -07:00
|
|
|
document.querySelectorAll('[data-onclick="add_playlist_video"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { add_playlist_video(el); };
|
2020-04-07 11:34:40 -07:00
|
|
|
});
|
2022-05-05 18:46:59 -07:00
|
|
|
document.querySelectorAll('[data-onclick="add_playlist_item"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { add_playlist_item(el); };
|
2020-03-15 14:46:08 -07:00
|
|
|
});
|
2022-05-05 18:46:59 -07:00
|
|
|
document.querySelectorAll('[data-onclick="remove_playlist_item"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { remove_playlist_item(el); };
|
2020-03-15 14:46:08 -07:00
|
|
|
});
|
2022-05-05 18:46:59 -07:00
|
|
|
document.querySelectorAll('[data-onclick="revoke_token"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { revoke_token(el); };
|
2020-03-15 14:46:08 -07:00
|
|
|
});
|
2022-05-05 18:46:59 -07:00
|
|
|
document.querySelectorAll('[data-onclick="remove_subscription"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { remove_subscription(el); };
|
2020-03-15 14:46:08 -07:00
|
|
|
});
|
2022-05-05 18:46:59 -07:00
|
|
|
document.querySelectorAll('[data-onclick="notification_requestPermission"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { Notification.requestPermission(); };
|
2020-03-15 14:46:08 -07:00
|
|
|
});
|
|
|
|
|
2022-05-05 18:46:59 -07:00
|
|
|
document.querySelectorAll('[data-onrange="update_volume_value"]').forEach(function (el) {
|
|
|
|
function update_volume_value() {
|
2022-05-21 03:35:41 -07:00
|
|
|
document.getElementById('volume-value').textContent = el.value;
|
2022-05-05 18:46:59 -07:00
|
|
|
}
|
|
|
|
el.oninput = update_volume_value;
|
|
|
|
el.onchange = update_volume_value;
|
2020-03-15 14:46:08 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function revoke_token(target) {
|
|
|
|
var row = target.parentNode.parentNode.parentNode.parentNode.parentNode;
|
|
|
|
row.style.display = 'none';
|
|
|
|
var count = document.getElementById('count');
|
2022-05-21 03:35:41 -07:00
|
|
|
count.textContent--;
|
2020-03-15 14:46:08 -07:00
|
|
|
|
|
|
|
var url = '/token_ajax?action_revoke_token=1&redirect=false' +
|
2022-05-05 18:46:59 -07:00
|
|
|
'&referer=' + encodeURIComponent(location.href) +
|
2020-03-15 14:46:08 -07:00
|
|
|
'&session=' + target.getAttribute('data-session');
|
|
|
|
|
2022-05-05 18:46:59 -07:00
|
|
|
var payload = 'csrf_token=' + target.parentNode.querySelector('input[name="csrf_token"]').value;
|
|
|
|
|
|
|
|
helpers.xhr('POST', url, {payload: payload}, {
|
|
|
|
onNon200: function (xhr) {
|
2022-05-21 03:35:41 -07:00
|
|
|
count.textContent++;
|
2022-05-05 18:46:59 -07:00
|
|
|
row.style.display = '';
|
|
|
|
}
|
|
|
|
});
|
2020-03-15 14:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function remove_subscription(target) {
|
|
|
|
var row = target.parentNode.parentNode.parentNode.parentNode.parentNode;
|
|
|
|
row.style.display = 'none';
|
|
|
|
var count = document.getElementById('count');
|
2022-05-21 03:35:41 -07:00
|
|
|
count.textContent--;
|
2020-03-15 14:46:08 -07:00
|
|
|
|
|
|
|
var url = '/subscription_ajax?action_remove_subscriptions=1&redirect=false' +
|
2022-05-05 18:46:59 -07:00
|
|
|
'&referer=' + encodeURIComponent(location.href) +
|
2020-03-15 14:46:08 -07:00
|
|
|
'&c=' + target.getAttribute('data-ucid');
|
|
|
|
|
2022-05-05 18:46:59 -07:00
|
|
|
var payload = 'csrf_token=' + target.parentNode.querySelector('input[name="csrf_token"]').value;
|
|
|
|
|
|
|
|
helpers.xhr('POST', url, {payload: payload}, {
|
|
|
|
onNon200: function (xhr) {
|
2022-05-21 03:35:41 -07:00
|
|
|
count.textContent++;
|
2022-05-05 18:46:59 -07:00
|
|
|
row.style.display = '';
|
|
|
|
}
|
|
|
|
});
|
2020-03-15 14:46:08 -07:00
|
|
|
}
|
2022-01-13 13:20:10 -08:00
|
|
|
|
|
|
|
// Handle keypresses
|
2022-05-05 18:46:59 -07:00
|
|
|
addEventListener('keydown', function (event) {
|
2022-01-13 13:20:10 -08:00
|
|
|
// Ignore modifier keys
|
2022-01-28 09:19:32 -08:00
|
|
|
if (event.ctrlKey || event.metaKey) return;
|
|
|
|
|
|
|
|
// Ignore shortcuts if any text input is focused
|
|
|
|
let focused_tag = document.activeElement.tagName.toLowerCase();
|
2022-02-07 15:04:02 -08:00
|
|
|
const allowed = /^(button|checkbox|file|radio|submit)$/;
|
2022-01-28 09:19:32 -08:00
|
|
|
|
2022-04-20 02:49:05 -07:00
|
|
|
if (focused_tag === 'textarea') return;
|
|
|
|
if (focused_tag === 'input') {
|
2022-02-07 15:04:02 -08:00
|
|
|
let focused_type = document.activeElement.type.toLowerCase();
|
2023-03-23 15:10:53 -07:00
|
|
|
if (!allowed.test(focused_type)) return;
|
2022-02-07 15:04:02 -08:00
|
|
|
}
|
2022-01-13 13:20:10 -08:00
|
|
|
|
|
|
|
// Focus search bar on '/'
|
2022-04-20 02:49:05 -07:00
|
|
|
if (event.key === '/') {
|
2022-01-13 13:20:10 -08:00
|
|
|
document.getElementById('searchbox').focus();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
2020-03-15 14:46:08 -07:00
|
|
|
})();
|