Skip to content

Instantly share code, notes, and snippets.

@NexAdn
Created October 31, 2018 22:47
Show Gist options
  • Save NexAdn/c4bdcd8a3f9a54ecbb7f49ab70a97082 to your computer and use it in GitHub Desktop.
Save NexAdn/c4bdcd8a3f9a54ecbb7f49ab70a97082 to your computer and use it in GitHub Desktop.
KT-Chat Helper JS
// Eigener Benutzername, exakt angeben
var ownUsername = "";
// Nicknamen in "", gefolgt von einem Komma, kürzeste Variante ist hinreichend. Zu kurze Angaben können zu falsch positiven Ergebnissen führen (Nachrichten werden fälschlicherweise markiert).
var nicknames = [
"",
];
// HTML5-Sounds aktivieren. Achtung! Flash-Sounds bleiben weiterhin aktiv. Flash ggf. deinstallieren!
var audioEnable = true;
// Visuelle Benachrichtigungen:
// 0: keine Benachrichtigungen
// 1: Benachrichtigungen komplett
// 2: Benachrichtigungen nur bei Erwähnungen
var notifications = 2;
var audioEnter = new Audio("http://kt-forum.de/chat/sounds/sound_1.mp3");
var audioLeave = new Audio("http://kt-forum.de/chat/sounds/sound_2.mp3");
var audioError = new Audio("http://kt-forum.de/chat/sounds/sound_3.mp3");
var audioChatBot = new Audio("http://kt-forum.de/chat/sounds/sound_4.mp3");
var audioMention = new Audio("http://kt-forum.de/chat/sounds/sound_5.mp3");
var audioReceive = new Audio("http://kt-forum.de/chat/sounds/sound_6.mp3");
var originalTitle = document.title;
var unread = 0;
var windowActive = false;
setTimeout(function() {
ajaxChat.blinkUpdate = function(blinkStr) {};
}, 1000);
setTimeout(function() {
ajaxChat.customOnNewMessage = function(dateObject, userID, userName, userRole, messageID, messageText, channelID, ip) {
if (notifications > 0) {
if (notifications == 1) {
unread++;
updateBadge(windowActive ? 0 : unread);
}
} else {
updateBadge(0);
}
if (ajaxChat.settings['audio'] && ajaxChat.lastID && audioEnable) {
switch (userID) {
case ajaxChat.chatBotID:
var messageParts = messageText.split(' ', 1);
switch (messageParts[0]) {
case '/login':
case '/channelEnter':
audioEnter.play();
break;
case '/logout':
case '/channelLeave':
case '/kick':
audioLeave.play();
break;
case '/error':
audioError.play();
break;
default:
audioChatBot.play();
}
break;
case ajaxChat.userID:
//audioSend.play();
break;
default:
audioReceive.play();
break;
}
}
if (userName != ownUsername) {
// User mentioned
if (messageText.toLowerCase().includes(ownUsername.toLowerCase()))
userMention(messageID);
for (var i = 0; i < nicknames.length; i++) {
if (messageText.toLowerCase().includes(nicknames[i].toLowerCase()))
userMention(messageID);
}
}
if (messageText.includes('/privmsg')) {
// Whisper
userWhisper(messageID);
}
return true;
}
}, 1000);
window.addEventListener('focus', function() {
windowActive = true;
updateBadge(0);
document.getElementById('copyright').innerHTML = "active";
});
window.addEventListener('blur', function() {
windowActive = false;
document.getElementById('copyright').innerHTML = "inactive";
});
setTimeout(function() {
var oldHandler = document.getElementById('submitButton').onclick;
document.getElementById('submitButton').onclick = function(event) {
oldHandler(event);
updateBadge(0);
};
}, 1000);
document.body.onclick = updateBadge(0);
function userMention(messageID) {
if (notifications >= 2) {
unread++;
updateBadge(windowActive ? 0 : unread);
}
if (ajaxChat.settings['audio'] && ajaxChat.lastID && audioEnable)
audioMention.play();
setTimeout(function() {
document.getElementById("ajaxChat_m_" + messageID).innerHTML = "<span style=\"font-weight: bold; color: #f00;\">" + document.getElementById("ajaxChat_m_" + messageID).innerHTML + "</span>";
}, 100);
}
function userWhisper(messageID) {
setTimeout(function() {
document.getElementById("ajaxChat_m_" + messageID).innerHTML = "<span style=\"color: #fa0;\">" + document.getElementById("ajaxChat_m_" + messageID).innerHTML + "</span>";
}, 100);
}
function updateBadge(e) {
document.title = e >= 1 ? "(" + e + ") " + originalTitle : originalTitle;
unread = e;
}
function updateBadgeRaw(e) {
document.title = "(" + e + ")" + originalTitle;
}
setInterval(function() {
updateBadge(unread);
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment