CyTube/www/js/ui.js

945 lines
28 KiB
JavaScript
Raw Normal View History

2013-06-20 04:42:20 +00:00
/* window focus/blur */
2018-11-16 06:40:01 +00:00
CyTube.ui.onPageFocus = function () {
FOCUSED = true;
clearInterval(TITLE_BLINK);
TITLE_BLINK = false;
document.title = PAGETITLE;
};
CyTube.ui.onPageBlur = function (event) {
FOCUSED = false;
};
2022-01-23 00:18:51 +00:00
$(window).on('focus', CyTube.ui.onPageFocus).on('blur', CyTube.ui.onPageBlur);
2018-11-16 06:40:01 +00:00
// See #783
2022-01-23 00:18:51 +00:00
$(".modal").on('focus', CyTube.ui.onPageFocus);
2013-06-20 04:42:20 +00:00
2022-01-23 00:18:51 +00:00
$("#togglemotd").on('click', function () {
var hidden = $("#motd")[0].style.display === "none";
2013-10-03 03:26:28 +00:00
$("#motd").toggle();
if (hidden) {
$("#togglemotd").find(".glyphicon-plus")
.removeClass("glyphicon-plus")
.addClass("glyphicon-minus");
2013-10-03 03:26:28 +00:00
} else {
$("#togglemotd").find(".glyphicon-minus")
.removeClass("glyphicon-minus")
.addClass("glyphicon-plus");
2013-10-03 03:26:28 +00:00
}
});
2013-06-07 03:13:24 +00:00
/* chatbox */
2022-01-23 00:18:51 +00:00
$("#modflair").on('click', function () {
var m = $("#modflair");
if (m.hasClass("label-success")) {
USEROPTS.modhat = false;
m.removeClass("label-success");
if (SUPERADMIN) {
USEROPTS.adminhat = true;
m.addClass("label-danger");
} else {
m.addClass("label-default");
}
} else if (m.hasClass("label-danger")) {
USEROPTS.adminhat = false;
2013-12-19 17:14:48 +00:00
m.removeClass("label-danger")
.addClass("label-default");
} else {
USEROPTS.modhat = true;
m.removeClass("label-default")
.addClass("label-success");
}
$("#us-modflair").prop("checked", USEROPTS.modhat);
setOpt('modhat', USEROPTS.modhat);
});
2022-01-23 00:18:51 +00:00
$("#usercount").on('mouseenter', function (ev) {
var breakdown = calcUserBreakdown();
// re-using profile-box class for convenience
var popup = $("<div/>")
.addClass("profile-box")
2014-01-30 04:50:14 +00:00
.css("top", (ev.clientY + 5) + "px")
.css("left", (ev.clientX) + "px")
.appendTo($("#usercount"));
var contents = "";
for(var key in breakdown) {
contents += "<strong>" + key + ":&nbsp;</strong>" + breakdown[key];
contents += "<br>"
}
popup.html(contents);
});
2022-01-23 00:18:51 +00:00
$("#usercount").on('mousemove', function (ev) {
var popup = $("#usercount").find(".profile-box");
if(popup.length == 0)
return;
2014-01-30 04:50:14 +00:00
popup.css("top", (ev.clientY + 5) + "px");
popup.css("left", (ev.clientX) + "px");
});
2022-01-23 00:18:51 +00:00
$("#usercount").on('mouseleave', function () {
$("#usercount").find(".profile-box").remove();
});
2022-01-23 00:18:51 +00:00
$("#messagebuffer").on('scroll', function (ev) {
2015-12-06 01:57:33 +00:00
if (IGNORE_SCROLL_EVENT) {
// Skip event, this was triggered by scrollChat() and not by a user action.
// Reset for next event.
IGNORE_SCROLL_EVENT = false;
return;
}
var m = $("#messagebuffer");
var lastChildHeight = 0;
var messages = m.children();
if (messages.length > 0) {
lastChildHeight = messages[messages.length - 1].clientHeight || 0;
}
var isCaughtUp = m.height() + m.scrollTop() >= m.prop("scrollHeight") - lastChildHeight;
if (isCaughtUp) {
SCROLLCHAT = true;
$("#newmessages-indicator").remove();
} else {
SCROLLCHAT = false;
}
});
2013-06-20 04:42:20 +00:00
2022-01-23 00:18:51 +00:00
$("#guestname").on('keydown', function (ev) {
2014-01-06 15:55:12 +00:00
if (ev.keyCode === 13) {
socket.emit("login", {
name: $("#guestname").val()
});
}
});
CyTube.chatTabCompleteData = {
context: {}
};
2020-03-14 00:43:25 +00:00
function chatTabComplete(chatline) {
if (!CyTube.tabCompleteMethods) {
console.error('Missing CyTube.tabCompleteMethods!');
return;
}
var currentText = chatline.value;
var currentPosition = chatline.selectionEnd;
if (typeof currentPosition !== 'number' || !chatline.setSelectionRange) {
// Bail, we're on IE8 or something similarly dysfunctional
return;
}
var firstWord = !/\s/.test(currentText.trim());
var options = [];
var userlistElems = document.getElementById("userlist").children;
for (var i = 0; i < userlistElems.length; i++) {
var username = userlistElems[i].children[1].textContent;
if (firstWord) {
username += ':';
}
options.push(username);
}
CHANNEL.emotes.forEach(function (emote) {
options.push(emote.name);
});
var method = USEROPTS.chat_tab_method;
if (!CyTube.tabCompleteMethods[method]) {
console.error("Unknown chat tab completion method '" + method + "', using default");
method = "Cycle options";
}
var result = CyTube.tabCompleteMethods[method](
currentText,
currentPosition,
options,
CyTube.chatTabCompleteData.context
);
chatline.value = result.text;
chatline.setSelectionRange(result.newPosition, result.newPosition);
}
2022-01-23 00:18:51 +00:00
$("#chatline").on('keydown', function(ev) {
2013-12-15 03:59:47 +00:00
// Enter/return
2013-06-07 03:13:24 +00:00
if(ev.keyCode == 13) {
2013-11-19 21:14:40 +00:00
if (CHATTHROTTLE) {
return;
}
2013-06-07 03:13:24 +00:00
var msg = $("#chatline").val();
if(msg.trim()) {
2013-11-17 19:12:56 +00:00
var meta = {};
if (USEROPTS.adminhat && CLIENT.rank >= 255) {
msg = "/a " + msg;
2013-11-17 19:12:56 +00:00
} else if (USEROPTS.modhat && CLIENT.rank >= Rank.Moderator) {
meta.modflair = CLIENT.rank;
2013-06-07 03:13:24 +00:00
}
2013-12-15 03:59:47 +00:00
// The /m command no longer exists, so emulate it clientside
2013-11-17 19:12:56 +00:00
if (CLIENT.rank >= 2 && msg.indexOf("/m ") === 0) {
meta.modflair = CLIENT.rank;
2013-11-21 23:46:33 +00:00
msg = msg.substring(3);
2013-11-17 19:12:56 +00:00
}
2013-06-07 03:13:24 +00:00
socket.emit("chatMsg", {
2013-11-17 19:12:56 +00:00
msg: msg,
meta: meta
2013-06-07 03:13:24 +00:00
});
CHATHIST.push($("#chatline").val());
2013-06-19 21:54:27 +00:00
CHATHISTIDX = CHATHIST.length;
2013-06-07 03:13:24 +00:00
$("#chatline").val("");
}
return;
}
2013-12-15 03:59:47 +00:00
else if(ev.keyCode == 9) { // Tab completion
try {
2020-03-14 00:43:25 +00:00
chatTabComplete(ev.target);
} catch (error) {
console.error(error);
}
2013-06-07 03:13:24 +00:00
ev.preventDefault();
return false;
}
2013-12-15 03:59:47 +00:00
else if(ev.keyCode == 38) { // Up arrow (input history)
2013-06-07 03:13:24 +00:00
if(CHATHISTIDX == CHATHIST.length) {
CHATHIST.push($("#chatline").val());
}
if(CHATHISTIDX > 0) {
CHATHISTIDX--;
$("#chatline").val(CHATHIST[CHATHISTIDX]);
}
ev.preventDefault();
return false;
}
2013-12-15 03:59:47 +00:00
else if(ev.keyCode == 40) { // Down arrow (input history)
2013-06-07 03:13:24 +00:00
if(CHATHISTIDX < CHATHIST.length - 1) {
CHATHISTIDX++;
$("#chatline").val(CHATHIST[CHATHISTIDX]);
}
ev.preventDefault();
return false;
}
});
/* poll controls */
2022-01-23 00:18:51 +00:00
$("#newpollbtn").on('click', showPollMenu);
2013-06-07 03:13:24 +00:00
/* search controls */
2022-01-23 00:18:51 +00:00
$("#library_search").on('click', function() {
if (!hasPermission("seeplaylist")) {
$("#searchcontrol .alert").remove();
var al = makeAlert("Permission Denied",
"This channel does not allow you to search its library",
"alert-danger");
al.find(".alert").insertAfter($("#library_query").parent());
return;
}
2013-06-07 03:13:24 +00:00
socket.emit("searchMedia", {
source: "library",
query: $("#library_query").val().toLowerCase()
});
});
2022-01-23 00:18:51 +00:00
$("#library_query").on('keydown', function(ev) {
2013-06-07 03:13:24 +00:00
if(ev.keyCode == 13) {
if (!hasPermission("seeplaylist")) {
$("#searchcontrol .alert").remove();
var al = makeAlert("Permission Denied",
"This channel does not allow you to search its library",
"alert-danger");
al.find(".alert").insertAfter($("#library_query").parent());
return;
}
2013-06-07 03:13:24 +00:00
socket.emit("searchMedia", {
source: "library",
query: $("#library_query").val().toLowerCase()
});
}
});
2022-01-23 00:18:51 +00:00
$("#youtube_search").on('click', function () {
var query = $("#library_query").val().toLowerCase();
2019-04-07 23:32:58 +00:00
try {
parseMediaLink(query);
makeAlert("Media Link", "If you already have the link, paste it " +
"in the 'Media URL' box under Playlist Controls. This "+
"searchbar works like YouTube's search function.",
2013-12-15 03:59:47 +00:00
"alert-danger")
.insertBefore($("#library"));
2019-04-07 23:32:58 +00:00
} catch (e) {}
2013-06-07 03:13:24 +00:00
socket.emit("searchMedia", {
source: "yt",
query: query
2013-06-07 03:13:24 +00:00
});
});
/* user playlists */
2022-01-23 00:18:51 +00:00
$("#userpl_save").on('click', function() {
2013-06-07 03:13:24 +00:00
if($("#userpl_name").val().trim() == "") {
2013-12-15 03:59:47 +00:00
makeAlert("Invalid Name", "Playlist name cannot be empty", "alert-danger")
2013-06-07 03:13:24 +00:00
.insertAfter($("#userpl_save").parent());
return;
}
2014-02-02 18:41:41 +00:00
socket.emit("clonePlaylist", {
2013-06-07 03:13:24 +00:00
name: $("#userpl_name").val()
});
});
2013-06-23 18:21:21 +00:00
/* video controls */
2022-01-23 00:18:51 +00:00
$("#mediarefresh").on('click', function() {
2015-05-02 22:55:00 +00:00
PLAYER.mediaType = "";
PLAYER.mediaId = "";
2013-12-15 03:59:47 +00:00
// playerReady triggers the server to send a changeMedia.
// the changeMedia handler then reloads the player
2013-06-30 19:56:41 +00:00
socket.emit("playerReady");
});
2013-06-07 03:13:24 +00:00
/* playlist controls */
2013-06-07 22:09:36 +00:00
2013-06-11 19:41:03 +00:00
$("#queue").sortable({
start: function(ev, ui) {
2013-06-29 22:09:20 +00:00
PL_FROM = ui.item.data("uid");
2013-06-11 19:41:03 +00:00
},
update: function(ev, ui) {
var prev = ui.item.prevAll();
if(prev.length == 0)
2013-06-29 22:09:20 +00:00
PL_AFTER = "prepend";
else
2013-06-29 22:09:20 +00:00
PL_AFTER = $(prev[0]).data("uid");
socket.emit("moveMedia", {
from: PL_FROM,
after: PL_AFTER
});
2013-10-04 03:11:47 +00:00
$("#queue").sortable("cancel");
2013-06-11 19:41:03 +00:00
}
2013-06-09 18:03:41 +00:00
});
2013-06-11 19:41:03 +00:00
$("#queue").disableSelection();
2013-06-09 18:03:41 +00:00
2014-01-14 06:52:56 +00:00
function queue(pos, src) {
if (!src) {
src = "url";
}
if (src === "customembed") {
var title = $("#customembed-title").val();
if (!title) {
title = false;
}
2014-01-14 06:52:56 +00:00
var content = $("#customembed-content").val();
2013-08-03 19:10:06 +00:00
socket.emit("queue", {
2014-01-14 06:52:56 +00:00
id: content,
title: title,
2014-01-14 06:52:56 +00:00
pos: pos,
2014-02-09 06:24:20 +00:00
type: "cu",
temp: $(".add-temp").prop("checked")
2013-08-03 19:10:06 +00:00
});
2014-01-14 06:52:56 +00:00
} else {
var linkList = $("#mediaurl").val();
var links = linkList.split(",http").map(function (link, i) {
if (i > 0) {
return "http" + link;
} else {
return link;
}
});
if (pos === "next") links = links.reverse();
if (pos === "next" && $("#queue li").length === 0) links.unshift(links.pop());
var emitQueue = [];
var addTemp = $(".add-temp").prop("checked");
var notification = document.getElementById("addfromurl-queue");
if (!notification) {
notification = document.createElement("div");
notification.id = "addfromurl-queue";
document.getElementById("addfromurl").appendChild(notification);
2014-06-04 04:21:00 +00:00
}
2014-02-10 02:10:11 +00:00
links.forEach(function (link) {
2019-04-07 23:32:58 +00:00
var data;
2017-12-24 19:19:30 +00:00
2019-04-07 23:32:58 +00:00
try {
data = parseMediaLink(link);
} catch (error) {
2017-12-24 19:19:30 +00:00
Callbacks.queueFail({
link: link,
2019-04-07 23:32:58 +00:00
msg: error.message
2017-12-24 19:19:30 +00:00
});
return;
}
2019-04-07 23:32:58 +00:00
var duration = undefined;
var title = undefined;
if (data.type === "fi") {
if (data.id.match(/^http:/)) {
Callbacks.queueFail({
link: data.id,
msg: "Raw files must begin with 'https'. Plain http is not supported."
});
return;
}
// Explicit checks for kissanime and mega.nz since everyone
// asks about them
if (data.id.match(/kissanime|kimcartoon|kisscartoon/i)) {
Callbacks.queueFail({
link: data.id,
msg: "Kisscartoon and Kissanime are not supported. See https://git.io/vxS9n" +
" for more information about why these cannot be supported."
});
return;
} else if (data.id.match(/mega\.nz/)) {
Callbacks.queueFail({
link: data.id,
msg: "Mega.nz is not supported. See https://git.io/fx6fz" +
" for more information about why mega.nz cannot be supported."
});
return;
}
// Raw files allow title overrides since the ffprobe tag data
// is not always correct.
title = $("#addfromurl-title-val").val();
}
if (data.id == null || data.type == null) {
makeAlert("Error", "Failed to parse link " + link +
". Please check that it is correct",
"alert-danger", true)
.insertAfter($("#addfromurl"));
} else {
emitQueue.push({
id: data.id,
type: data.type,
pos: pos,
duration: duration,
title: title,
temp: addTemp,
link: link
});
}
});
var nextQueueDelay = 1020;
function next() {
var data = emitQueue.shift();
if (!data) {
$("#mediaurl").val("");
$("#addfromurl-title").remove();
return;
}
var link = data.link;
delete data.link;
socket.emit("queue", data);
startQueueSpinner(data);
if (emitQueue.length > 0) {
notification.textContent = "Waiting to queue " + emitQueue[0].link;
} else {
notification.textContent = "";
}
setTimeout(next, nextQueueDelay);
}
next();
}
2013-06-07 22:09:36 +00:00
}
2022-01-23 00:18:51 +00:00
$("#queue_next").on('click', queue.bind(this, "next", "url"));
$("#queue_end").on('click', queue.bind(this, "end", "url"));
$("#ce_queue_next").on('click', queue.bind(this, "next", "customembed"));
$("#ce_queue_end").on('click', queue.bind(this, "end", "customembed"));
2013-06-07 22:09:36 +00:00
2022-01-23 00:18:51 +00:00
$("#mediaurl").on('keyup', function(ev) {
2014-01-14 06:52:56 +00:00
if (ev.keyCode === 13) {
queue("end", "url");
2014-02-10 02:10:11 +00:00
} else {
2019-04-07 23:32:58 +00:00
var editTitle = false;
try {
if (parseMediaLink($("#mediaurl").val()).type === "fi") {
editTitle = true;
}
} catch (error) {
}
if (editTitle) {
2014-06-04 04:21:00 +00:00
var title = $("#addfromurl-title");
if (title.length === 0) {
title = $("<div/>")
.attr("id", "addfromurl-title")
.appendTo($("#addfromurl"));
2019-04-07 23:32:58 +00:00
$("<span/>").text("Title (optional; for raw files only)")
2014-06-04 04:21:00 +00:00
.appendTo(title);
$("<input/>").addClass("form-control")
.attr("type", "text")
.attr("id", "addfromurl-title-val")
2022-01-23 00:18:51 +00:00
.on('keydown', function (ev) {
2014-06-04 04:21:00 +00:00
if (ev.keyCode === 13) {
queue("end", "url");
}
})
.appendTo($("#addfromurl-title"));
}
} else {
$("#addfromurl-title").remove();
}
2014-01-14 06:52:56 +00:00
}
2013-06-07 22:09:36 +00:00
});
2022-01-23 00:18:51 +00:00
$("#customembed-content").on('keydown', function(ev) {
2014-01-14 06:52:56 +00:00
if (ev.keyCode === 13) {
queue("end", "customembed");
2013-06-07 22:09:36 +00:00
}
});
2022-01-23 00:18:51 +00:00
$("#qlockbtn").on('click', function() {
2013-06-07 22:09:36 +00:00
socket.emit("togglePlaylistLock");
});
2022-01-23 00:18:51 +00:00
$("#voteskip").on('click', function() {
2013-06-18 20:18:41 +00:00
socket.emit("voteskip");
2013-07-24 19:11:50 +00:00
$("#voteskip").attr("disabled", true);
2013-06-18 20:18:41 +00:00
});
2022-01-23 00:18:51 +00:00
$("#getplaylist").on('click', function() {
2013-06-07 22:09:36 +00:00
var callback = function(data) {
var idx = socket.listeners("errorMsg").indexOf(errCallback);
if (idx >= 0) {
socket.listeners("errorMsg").splice(idx);
}
idx = socket.listeners("playlist").indexOf(callback);
if (idx >= 0) {
socket.listeners("playlist").splice(idx);
}
2013-06-07 22:09:36 +00:00
var list = [];
2013-06-11 19:41:03 +00:00
for(var i = 0; i < data.length; i++) {
2013-07-12 20:10:06 +00:00
var entry = formatURL(data[i].media);
2013-06-07 22:09:36 +00:00
list.push(entry);
}
var urls = list.join(",");
2013-12-15 03:59:47 +00:00
var outer = $("<div/>").addClass("modal fade")
2013-06-07 22:09:36 +00:00
.appendTo($("body"));
2013-12-15 03:59:47 +00:00
modal = $("<div/>").addClass("modal-dialog").appendTo(outer);
modal = $("<div/>").addClass("modal-content").appendTo(modal);
2013-06-07 22:09:36 +00:00
var head = $("<div/>").addClass("modal-header")
.appendTo(modal);
$("<button/>").addClass("close")
.attr("data-dismiss", "modal")
.attr("aria-hidden", "true")
.html("&times;")
.appendTo(head);
$("<h3/>").text("Playlist URLs").appendTo(head);
var body = $("<div/>").addClass("modal-body").appendTo(modal);
2013-12-15 03:59:47 +00:00
$("<input/>").addClass("form-control").attr("type", "text")
2013-06-07 22:09:36 +00:00
.val(urls)
.appendTo(body);
$("<div/>").addClass("modal-footer").appendTo(modal);
outer.on("hidden.bs.modal", function() {
2013-12-15 03:59:47 +00:00
outer.remove();
2013-06-07 22:09:36 +00:00
});
2013-12-15 03:59:47 +00:00
outer.modal();
};
2013-06-07 22:09:36 +00:00
socket.on("playlist", callback);
var errCallback = function(data) {
if (data.code !== "REQ_PLAYLIST_LIMIT_REACHED") {
return;
}
var idx = socket.listeners("errorMsg").indexOf(errCallback);
if (idx >= 0) {
socket.listeners("errorMsg").splice(idx);
}
idx = socket.listeners("playlist").indexOf(callback);
if (idx >= 0) {
socket.listeners("playlist").splice(idx);
}
};
socket.on("errorMsg", errCallback);
2013-06-07 22:09:36 +00:00
socket.emit("requestPlaylist");
});
2022-01-23 00:18:51 +00:00
$("#clearplaylist").on('click', function() {
2013-06-07 22:09:36 +00:00
var clear = confirm("Are you sure you want to clear the playlist?");
if(clear) {
socket.emit("clearPlaylist");
}
});
2022-01-23 00:18:51 +00:00
$("#shuffleplaylist").on('click', function() {
2013-06-11 19:41:03 +00:00
var shuffle = confirm("Are you sure you want to shuffle the playlist?");
if(shuffle) {
2013-06-07 22:09:36 +00:00
socket.emit("shufflePlaylist");
}
});
2013-06-11 15:29:21 +00:00
2014-01-09 05:45:26 +00:00
/* channel ranks stuff */
2014-01-09 23:16:09 +00:00
function chanrankSubmit(rank) {
2014-01-09 05:45:26 +00:00
var name = $("#cs-chanranks-name").val();
socket.emit("setChannelRank", {
2014-05-21 03:11:40 +00:00
name: name,
2014-01-09 05:45:26 +00:00
rank: rank
});
2014-01-09 23:16:09 +00:00
}
2022-01-23 00:18:51 +00:00
$("#cs-chanranks-mod").on('click', chanrankSubmit.bind(this, 2));
$("#cs-chanranks-adm").on('click', chanrankSubmit.bind(this, 3));
$("#cs-chanranks-owner").on('click', chanrankSubmit.bind(this, 4));
2014-01-14 00:31:12 +00:00
2014-02-02 18:41:41 +00:00
["#showmediaurl", "#showsearch", "#showcustomembed", "#showplaylistmanager"]
.forEach(function (id) {
2022-01-23 00:18:51 +00:00
$(id).on('click', function () {
2014-01-22 05:04:06 +00:00
var wasActive = $(id).hasClass("active");
2014-01-14 00:31:12 +00:00
$(".plcontrol-collapse").collapse("hide");
2014-01-22 05:04:06 +00:00
$("#plcontrol button.active").button("toggle");
if (!wasActive) {
$(id).button("toggle");
}
2014-01-14 00:31:12 +00:00
});
});
2014-01-22 05:04:06 +00:00
$("#plcontrol button").button();
$("#plcontrol button").button("hide");
2014-01-14 00:31:12 +00:00
$(".plcontrol-collapse").collapse();
$(".plcontrol-collapse").collapse("hide");
2014-01-15 06:16:29 +00:00
2022-01-23 00:18:51 +00:00
$(".cs-checkbox").on('change', function () {
2014-01-15 06:16:29 +00:00
var box = $(this);
var key = box.attr("id").replace("cs-", "");
var value = box.prop("checked");
var data = {};
data[key] = value;
socket.emit("setOptions", data);
});
2022-01-23 00:18:51 +00:00
$(".cs-textbox").on('keyup', function () {
2014-01-15 06:16:29 +00:00
var box = $(this);
var key = box.attr("id").replace("cs-", "");
var value = box.val();
var lastkey = Date.now();
box.data("lastkey", lastkey);
setTimeout(function () {
if (box.data("lastkey") !== lastkey || box.val() !== value) {
return;
}
var data = {};
2014-01-16 17:53:34 +00:00
if (key.match(/chat_antiflood_(burst|sustained)/)) {
data = {
chat_antiflood_params: {
burst: $("#cs-chat_antiflood_burst").val(),
sustained: $("#cs-chat_antiflood_sustained").val()
}
};
} else {
data[key] = value;
}
2014-01-15 06:16:29 +00:00
socket.emit("setOptions", data);
}, 1000);
});
2014-01-16 17:53:34 +00:00
2022-01-23 00:18:51 +00:00
$(".cs-textbox-timeinput").on('keyup', function (event) {
var box = $(this);
var key = box.attr("id").replace("cs-", "");
var value = box.val();
var lastkey = Date.now();
box.data("lastkey", lastkey);
setTimeout(function () {
if (box.data("lastkey") !== lastkey || box.val() !== value) {
return;
}
$("#cs-textbox-timeinput-validation-error-" + key).remove();
$(event.target).parent().removeClass("has-error");
var data = {};
try {
data[key] = parseTimeout(value);
} catch (error) {
var msg = "Invalid timespan value '" + value + "'. Please use the format " +
"HH:MM:SS or enter a single number for the number of seconds.";
var validationError = $("<p/>").addClass("text-danger").text(msg)
.attr("id", "cs-textbox-timeinput-validation-error-" + key);
validationError.insertAfter(event.target);
$(event.target).parent().addClass("has-error");
return;
}
socket.emit("setOptions", data);
}, 1000);
});
2022-01-23 00:18:51 +00:00
$("#cs-chanlog-refresh").on('click', function () {
2014-01-16 17:53:34 +00:00
socket.emit("readChanLog");
});
2022-01-23 00:18:51 +00:00
$("#cs-chanlog-filter").on('change', filterChannelLog);
2014-01-16 17:53:34 +00:00
2022-01-23 00:18:51 +00:00
$("#cs-motdsubmit").on('click', function () {
2014-01-16 17:53:34 +00:00
socket.emit("setMotd", {
motd: $("#cs-motdtext").val()
});
});
2022-01-23 00:18:51 +00:00
$("#cs-csssubmit").on('click', function () {
2014-01-16 17:53:34 +00:00
socket.emit("setChannelCSS", {
css: $("#cs-csstext").val()
});
});
2022-01-23 00:18:51 +00:00
$("#cs-jssubmit").on('click', function () {
2014-01-16 17:53:34 +00:00
socket.emit("setChannelJS", {
js: $("#cs-jstext").val()
});
});
2014-01-19 02:18:00 +00:00
2022-01-23 00:18:51 +00:00
$("#cs-chatfilters-newsubmit").on('click', function () {
2014-01-19 02:18:00 +00:00
var name = $("#cs-chatfilters-newname").val();
var regex = $("#cs-chatfilters-newregex").val();
var flags = $("#cs-chatfilters-newflags").val();
var replace = $("#cs-chatfilters-newreplace").val();
2014-04-13 07:14:34 +00:00
var entcheck = checkEntitiesInStr(regex);
if (entcheck) {
alert("Warning: " + entcheck.src + " will be replaced by " +
entcheck.replace + " in the message preprocessor. This " +
"regular expression may not match what you intended it to " +
"match.");
}
2014-01-19 02:18:00 +00:00
2014-12-28 16:12:37 +00:00
socket.emit("addFilter", {
2014-01-19 02:18:00 +00:00
name: name,
source: regex,
flags: flags,
replace: replace,
active: true
});
2014-12-28 16:12:37 +00:00
socket.once("addFilterSuccess", function () {
$("#cs-chatfilters-newname").val("");
$("#cs-chatfilters-newregex").val("");
$("#cs-chatfilters-newflags").val("");
$("#cs-chatfilters-newreplace").val("");
});
2014-01-19 02:18:00 +00:00
});
2022-01-23 00:18:51 +00:00
$("#cs-emotes-newsubmit").on('click', function () {
2014-02-13 05:33:42 +00:00
var name = $("#cs-emotes-newname").val();
var image = $("#cs-emotes-newimage").val();
socket.emit("updateEmote", {
name: name,
image: image,
});
$("#cs-emotes-newname").val("");
$("#cs-emotes-newimage").val("");
});
2022-01-23 00:18:51 +00:00
$("#cs-chatfilters-export").on('click', function () {
2014-01-19 02:18:00 +00:00
var callback = function (data) {
socket.listeners("chatFilters").splice(
socket.listeners("chatFilters").indexOf(callback)
);
$("#cs-chatfilters-exporttext").val(JSON.stringify(data));
};
socket.on("chatFilters", callback);
socket.emit("requestChatFilters");
});
2022-01-23 00:18:51 +00:00
$("#cs-chatfilters-import").on('click', function () {
2014-01-19 02:18:00 +00:00
var text = $("#cs-chatfilters-exporttext").val();
var choose = confirm("You are about to import filters from the contents of the textbox below the import button. If this is empty, it will clear all of your filters. Are you sure you want to continue?");
if (!choose) {
return;
}
if (text.trim() === "") {
text = "[]";
}
var data;
try {
data = JSON.parse(text);
} catch (e) {
alert("Invalid import data: " + e);
return;
}
socket.emit("importFilters", data);
2014-01-19 02:18:00 +00:00
});
2014-01-25 19:49:34 +00:00
2022-01-23 00:18:51 +00:00
$("#cs-emotes-export").on('click', function () {
2014-02-13 05:33:42 +00:00
var em = CHANNEL.emotes.map(function (f) {
return {
name: f.name,
image: f.image
};
});
$("#cs-emotes-exporttext").val(JSON.stringify(em));
});
2022-01-23 00:18:51 +00:00
$("#cs-emotes-import").on('click', function () {
2014-02-13 05:33:42 +00:00
var text = $("#cs-emotes-exporttext").val();
var choose = confirm("You are about to import emotes from the contents of the textbox below the import button. If this is empty, it will clear all of your emotes. Are you sure you want to continue?");
if (!choose) {
return;
}
if (text.trim() === "") {
text = "[]";
}
var data;
try {
data = JSON.parse(text);
} catch (e) {
alert("Invalid import data: " + e);
return;
}
socket.emit("importEmotes", data);
});
2014-01-25 19:49:34 +00:00
var toggleUserlist = function () {
var direction = !USEROPTS.layout.match(/synchtube/) ? "glyphicon-chevron-right" : "glyphicon-chevron-left"
if ($("#userlist")[0].style.display === "none") {
2014-01-25 19:49:34 +00:00
$("#userlist").show();
$("#userlisttoggle").removeClass(direction).addClass("glyphicon-chevron-down");
2014-01-25 19:49:34 +00:00
} else {
$("#userlist").hide();
$("#userlisttoggle").removeClass("glyphicon-chevron-down").addClass(direction);
2014-01-25 19:49:34 +00:00
}
scrollChat();
};
2022-01-23 00:18:51 +00:00
$("#usercount").on('click', toggleUserlist);
$("#userlisttoggle").on('click', toggleUserlist);
2014-02-09 06:24:20 +00:00
2022-01-23 00:18:51 +00:00
$(".add-temp").on('change', function () {
2014-02-09 06:24:20 +00:00
$(".add-temp").prop("checked", $(this).prop("checked"));
});
2014-02-19 03:56:54 +00:00
2014-12-07 19:42:18 +00:00
/*
* Fixes #417 which is caused by changes in Bootstrap 3.3.0
* (see twbs/bootstrap#15136)
*
* Whenever the active tab in channel options is changed,
* the modal must be updated so that the backdrop is resized
* appropriately.
*/
$("#channeloptions li > a[data-toggle='tab']").on("shown.bs.tab", function () {
$("#channeloptions").data("bs.modal").handleUpdate();
});
2014-02-19 03:56:54 +00:00
applyOpts();
2014-11-11 04:43:49 +00:00
(function () {
2015-05-14 18:14:45 +00:00
var embed = document.querySelector("#videowrap .embed-responsive");
if (!embed) {
return;
}
2014-11-11 04:43:49 +00:00
if (typeof window.MutationObserver === "function") {
var mr = new MutationObserver(function (records) {
records.forEach(function (record) {
if (record.type !== "childList") return;
if (!record.addedNodes || record.addedNodes.length === 0) return;
var elem = record.addedNodes[0];
2014-11-12 01:48:08 +00:00
if (elem.id === "ytapiplayer") handleVideoResize();
2014-11-11 04:43:49 +00:00
});
});
2015-05-14 18:14:45 +00:00
mr.observe(embed, { childList: true });
2014-11-11 04:43:49 +00:00
} else {
/*
* DOMNodeInserted is deprecated. This code is here only as a fallback
* for browsers that do not support MutationObserver
*/
2015-05-14 18:14:45 +00:00
embed.addEventListener("DOMNodeInserted", function (ev) {
2014-11-11 04:43:49 +00:00
if (ev.target.id === "ytapiplayer") handleVideoResize();
});
}
})();
2015-05-12 18:50:59 +00:00
var EMOTELISTMODAL = $("#emotelist");
2022-01-23 00:18:51 +00:00
$("#emotelistbtn").on('click', function () {
EMOTELISTMODAL.modal();
2015-05-12 18:50:59 +00:00
});
2015-05-13 17:17:32 +00:00
EMOTELISTMODAL.on('shown.bs.modal', function () { $('.emotelist-search').trigger('focus') });
EMOTELISTMODAL.find(".emotelist-alphabetical").change(function () {
USEROPTS.emotelist_sort = this.checked;
setOpt("emotelist_sort", USEROPTS.emotelist_sort);
});
EMOTELISTMODAL.find(".emotelist-alphabetical").prop("checked", USEROPTS.emotelist_sort);
2022-01-23 00:18:51 +00:00
$("#fullscreenbtn").on('click', function () {
2015-07-07 00:35:04 +00:00
var elem = document.querySelector("#videowrap .embed-responsive");
// this shit is why frontend web development sucks
var fn = elem.requestFullscreen ||
elem.mozRequestFullScreen || // Mozilla has to be different and use a capital 'S'
elem.webkitRequestFullscreen ||
elem.msRequestFullscreen;
if (fn) {
fn.call(elem);
}
});
function handleCSSJSTooLarge(selector) {
if (this.value.length > 20000) {
let notice = document.querySelector(selector);
if (notice !== null) {
return;
}
notice = makeAlert("Maximum Size Exceeded", "Inline CSS and JavaScript are " +
"limited to 20,000 characters or less. If you need more room, you " +
"need to use the external CSS or JavaScript option.", "alert-danger")
.attr("id", selector.replace(/#/, ""));
// makeAlert returns jQuery
this.parentNode.insertBefore(notice[0], this);
} else {
let notice = document.querySelector(selector);
notice?.remove();
}
}
['#cs-csstext', '#cs-jstext'].forEach((selector)=>{
elem = document.querySelector(selector);
elem.addEventListener('input', handleCSSJSTooLarge.bind(elem, `${selector}-too-big`));
});
2022-01-23 00:18:51 +00:00
$("#resize-video-larger").on('click', function () {
try {
CyTube.ui.changeVideoWidth(1);
} catch (error) {
console.error(error);
}
});
2022-01-23 00:18:51 +00:00
$("#resize-video-smaller").on('click', function () {
try {
CyTube.ui.changeVideoWidth(-1);
} catch (error) {
console.error(error);
}
});