2020-03-15 17:46:08 -04:00
|
|
|
'use strict';
|
|
|
|
|
2020-03-15 18:52:49 -04:00
|
|
|
(function () {
|
2020-03-27 10:47:46 -04:00
|
|
|
var video_player = document.getElementById('player_html5_api');
|
2020-03-15 17:46:08 -04:00
|
|
|
if (video_player) {
|
2020-03-15 18:52:49 -04: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 17:46:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// For dynamically inserted elements
|
2022-05-05 21:46:59 -04:00
|
|
|
addEventListener('click', function (e) {
|
|
|
|
if (!e || !e.target) return;
|
2022-05-01 13:08:11 -04:00
|
|
|
|
|
|
|
var t = e.target;
|
|
|
|
var handler_name = t.getAttribute('data-onclick');
|
|
|
|
|
2020-03-15 17:46:08 -04:00
|
|
|
switch (handler_name) {
|
2020-03-15 18:52:49 -04:00
|
|
|
case 'jump_to_time':
|
2022-05-01 13:08:11 -04:00
|
|
|
e.preventDefault();
|
|
|
|
var time = t.getAttribute('data-jump-time');
|
2020-03-15 18:52:49 -04:00
|
|
|
player.currentTime(time);
|
|
|
|
break;
|
|
|
|
case 'get_youtube_replies':
|
2022-05-01 13:08:11 -04: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 18:52:49 -04:00
|
|
|
break;
|
|
|
|
case 'toggle_parent':
|
2022-05-05 21:46:59 -04:00
|
|
|
e.preventDefault();
|
2022-05-01 13:08:11 -04:00
|
|
|
toggle_parent(t);
|
2020-03-15 18:52:49 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2020-03-15 17:46:08 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-05-05 21:46:59 -04: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 17:46:08 -04:00
|
|
|
});
|
|
|
|
|
2022-05-05 21:46:59 -04:00
|
|
|
document.querySelectorAll('[data-onsubmit="return_false"]').forEach(function (el) {
|
|
|
|
el.onsubmit = function () { return false; };
|
2020-03-15 17:46:08 -04:00
|
|
|
});
|
|
|
|
|
2022-05-05 21:46:59 -04:00
|
|
|
document.querySelectorAll('[data-onclick="mark_watched"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { mark_watched(el); };
|
2020-03-15 17:46:08 -04:00
|
|
|
});
|
2022-05-05 21:46:59 -04:00
|
|
|
document.querySelectorAll('[data-onclick="mark_unwatched"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { mark_unwatched(el); };
|
2020-03-15 17:46:08 -04:00
|
|
|
});
|
2022-05-05 21:46:59 -04:00
|
|
|
document.querySelectorAll('[data-onclick="add_playlist_video"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { add_playlist_video(el); };
|
2020-04-07 14:34:40 -04:00
|
|
|
});
|
2022-05-05 21:46:59 -04:00
|
|
|
document.querySelectorAll('[data-onclick="add_playlist_item"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { add_playlist_item(el); };
|
2020-03-15 17:46:08 -04:00
|
|
|
});
|
2022-05-05 21:46:59 -04:00
|
|
|
document.querySelectorAll('[data-onclick="remove_playlist_item"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { remove_playlist_item(el); };
|
2020-03-15 17:46:08 -04:00
|
|
|
});
|
2022-05-05 21:46:59 -04:00
|
|
|
document.querySelectorAll('[data-onclick="revoke_token"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { revoke_token(el); };
|
2020-03-15 17:46:08 -04:00
|
|
|
});
|
2022-05-05 21:46:59 -04:00
|
|
|
document.querySelectorAll('[data-onclick="remove_subscription"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { remove_subscription(el); };
|
2020-03-15 17:46:08 -04:00
|
|
|
});
|
2022-05-05 21:46:59 -04:00
|
|
|
document.querySelectorAll('[data-onclick="notification_requestPermission"]').forEach(function (el) {
|
|
|
|
el.onclick = function () { Notification.requestPermission(); };
|
2020-03-15 17:46:08 -04:00
|
|
|
});
|
|
|
|
|
2022-05-05 21:46:59 -04:00
|
|
|
document.querySelectorAll('[data-onrange="update_volume_value"]').forEach(function (el) {
|
|
|
|
function update_volume_value() {
|
|
|
|
document.getElementById('volume-value').innerText = el.value;
|
|
|
|
}
|
|
|
|
el.oninput = update_volume_value;
|
|
|
|
el.onchange = update_volume_value;
|
2020-03-15 17:46:08 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function revoke_token(target) {
|
|
|
|
var row = target.parentNode.parentNode.parentNode.parentNode.parentNode;
|
|
|
|
row.style.display = 'none';
|
|
|
|
var count = document.getElementById('count');
|
2022-05-05 21:46:59 -04:00
|
|
|
count.innerText = parseInt(count.innerText) - 1;
|
2020-03-15 17:46:08 -04:00
|
|
|
|
|
|
|
var url = '/token_ajax?action_revoke_token=1&redirect=false' +
|
2022-05-05 21:46:59 -04:00
|
|
|
'&referer=' + encodeURIComponent(location.href) +
|
2020-03-15 17:46:08 -04:00
|
|
|
'&session=' + target.getAttribute('data-session');
|
|
|
|
|
2022-05-05 21:46:59 -04:00
|
|
|
var payload = 'csrf_token=' + target.parentNode.querySelector('input[name="csrf_token"]').value;
|
|
|
|
|
|
|
|
helpers.xhr('POST', url, {payload: payload}, {
|
|
|
|
onNon200: function (xhr) {
|
|
|
|
count.innerText = parseInt(count.innerText) + 1;
|
|
|
|
row.style.display = '';
|
|
|
|
}
|
|
|
|
});
|
2020-03-15 17:46:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function remove_subscription(target) {
|
|
|
|
var row = target.parentNode.parentNode.parentNode.parentNode.parentNode;
|
|
|
|
row.style.display = 'none';
|
|
|
|
var count = document.getElementById('count');
|
2022-05-05 21:46:59 -04:00
|
|
|
count.innerText = parseInt(count.innerText) - 1;
|
2020-03-15 17:46:08 -04:00
|
|
|
|
|
|
|
var url = '/subscription_ajax?action_remove_subscriptions=1&redirect=false' +
|
2022-05-05 21:46:59 -04:00
|
|
|
'&referer=' + encodeURIComponent(location.href) +
|
2020-03-15 17:46:08 -04:00
|
|
|
'&c=' + target.getAttribute('data-ucid');
|
|
|
|
|
2022-05-05 21:46:59 -04:00
|
|
|
var payload = 'csrf_token=' + target.parentNode.querySelector('input[name="csrf_token"]').value;
|
|
|
|
|
|
|
|
helpers.xhr('POST', url, {payload: payload}, {
|
|
|
|
onNon200: function (xhr) {
|
|
|
|
count.innerText = parseInt(count.innerText) + 1;
|
|
|
|
row.style.display = '';
|
|
|
|
}
|
|
|
|
});
|
2020-03-15 17:46:08 -04:00
|
|
|
}
|
2022-01-13 16:20:10 -05:00
|
|
|
|
|
|
|
// Handle keypresses
|
2022-05-05 21:46:59 -04:00
|
|
|
addEventListener('keydown', function (event) {
|
2022-01-13 16:20:10 -05:00
|
|
|
// Ignore modifier keys
|
2022-01-28 12:19:32 -05: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 18:04:02 -05:00
|
|
|
const allowed = /^(button|checkbox|file|radio|submit)$/;
|
2022-01-28 12:19:32 -05:00
|
|
|
|
2022-04-20 05:49:05 -04:00
|
|
|
if (focused_tag === 'textarea') return;
|
|
|
|
if (focused_tag === 'input') {
|
2022-02-07 18:04:02 -05:00
|
|
|
let focused_type = document.activeElement.type.toLowerCase();
|
|
|
|
if (!focused_type.match(allowed)) return;
|
|
|
|
}
|
2022-01-13 16:20:10 -05:00
|
|
|
|
|
|
|
// Focus search bar on '/'
|
2022-04-20 05:49:05 -04:00
|
|
|
if (event.key === '/') {
|
2022-01-13 16:20:10 -05:00
|
|
|
document.getElementById('searchbox').focus();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
2020-03-15 17:46:08 -04:00
|
|
|
})();
|