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