// ==UserScript== // @name TabsOfAvabur // @namespace Reltrakii_Magic_World // @version 2.1 // @description Tabs the channels it finds in chat, can be sorted, with notif for new messages // @author Reltorakii // @match https://*.avabur.com/game.php // @grant none // ==/UserScript== /* jshint -W097 */ 'use strict'; (function() { var options = { scriptSettings : { purge : true, channel_remove : false, preview : true, preview_reset : false, group_wires : false }, channelsSettings : { channelManager : {}, mutedChannels : [] } }; var channelLog = {}; var currentChannel = "Main"; var ServerMessagesChannel = "SML_325725_2338723_CHC"; var CMDResposeChannel = "CMDRC_4000_8045237_CHC"; var WhispersChannel = "UW_7593725_3480021_CHC"; var WiresChannel = "WC_0952340_3245901_CHC"; var showedMoTD = false; var lastMoTDContent = ""; var showingReconnectMsg = false; var hovering; var hoveringOverTab; function loadMessages() { $("#chatMessageList li:not(.processed)").each(function(i,e){ var plainText = $(e).text(); // lets get rid of staff stuff plainText = plainText.replace(/^\[X\]\s*/, ""); // now clean up spaces plainText = plainText.replace(/\s+/g, " "); // default message format [11:11:11] [Channel] (optional) the rest of the message var defaultMsg = plainText.match(/^\[([^\]]+)\]\s*(\[([^\]]+)\])?\s*(.*)/); // clan MoTD: [11 Nov, 1111] Clan Message of the Day: var isClanMoTD = plainText.replace(/^\[[0-9]+\s+[a-zA-Z]+\,\s*[0-9]+\]\s*/, "").indexOf("Clan Message of the Day:") === 0; // clan MoTD: [11 Nov, 1111] Message of the Day: var isRoAMoTD = plainText.replace(/^\[[0-9]+\s+[a-zA-Z]+\,\s*[0-9]+\]\s*/, "").indexOf("Message of the Day:") === 0; // Staff Server Messages [11:11:11] [ Whatever the hell. ] var isServerMsg = plainText.match(/^\[[^\]]+\]\s*\[\s+.*\s+]$/); // whisper detection var isWhisper = plainText.match(/^\[[^\]]+\]\s*Whisper\s*(to|from)\s*([^:]+)/); // wire detection var isWire = plainText.match(/^\[[^\]]+\]\s*(You|[a-zA-Z]+)\s*wired\s*.*\s*(you|[a-zA-Z]+)\.$/); var isChatNotif = $(e).children(".chat_notification").length > 0; var isChatReconnect = $(e).attr("id") === "websocket_reconnect_line"; var channel = currentChannel; var channelInfo = resolveChannelID(channel); if (defaultMsg !== null) { channel = defaultMsg[3] === undefined ? "Main" : defaultMsg[3]; channelInfo = resolveChannelID(channel); } if (isClanMoTD) { channel = "CLAN"; channelInfo = resolveChannelID("CLAN"); } else if (isServerMsg){ channel = "Server Messages"; channelInfo = resolveChannelID(channel); } else if (isWhisper){ channel = "Whispers Log"; channelInfo = resolveChannelID(channel); } else if (isWire && options.scriptSettings.group_wires){ channel = "Wires Log"; channelInfo = resolveChannelID(channel); } var channelID = channelInfo.cID; if ( channelID !== CMDResposeChannel && channelID !== ServerMessagesChannel && channelID !== WiresChannel && ( isChatNotif || isChatReconnect) ) { channelID = currentChannel; } if (channelID === CMDResposeChannel){ channel = "Info Channel"; } var channelColor = resolveChannelColor(channelID, channel); if (currentChannel !== channelID){ $(e).hide(); } else { $(e).show(); } $(e).addClass("processed"); $(e).addClass("chc_" + channelID); if (channelLog[channelID] === undefined) { channelLog[channelID] = { channelName: channel, channelID: channelID, channelColor: channelColor, messages: 0, newMessages: false, newMessagesCount: 0, muted: options.channelsSettings.mutedChannels.indexOf(channelID) !== -1 }; } if (channelID !== currentChannel){ channelLog[channelID].newMessages = true; channelLog[channelID].newMessagesCount++; } channelLog[channelID].messages++; if (options.channelsSettings.mutedChannels.indexOf(channelID) !== -1){ $(e).remove(); } updateChannelList(channelLog[channelID]); }); setTimeout(loadMessages, 500); } function init() { loadOptions(); loadDependencies(); prepareHTML(); addSettingsTab(); loadMessages(); $("#channelTabListWrapper").mCustomScrollbar({axis:"x",advanced:{autoExpandHorizontalScroll:true}}); $("#channelTabList").sortable({items:".channelTab",distance: 5}); $("#channelTabList").disableSelection(); setTimeout(function(){$("#channelTabMain").click();},1000); } function resolveChannelID(channel) { //channel = channel.replace(/\s+/g, ""); var channelID; var resolved = true; if (channel === "GLOBAL") { channelID = "Global"; } else if (channel === "CLAN") { channelID = "Clan"; } else if (channel.substr(0,4) === "AREA") { channelID = "Area"; } else if (channel === "HELP") { channelID = "Help"; } else if (channel === "STAFF") { channelID = "Staff"; } else if (channel === "TRADE") { channelID = "Trade"; } else if (channel === "Market") { channelID = "Trade"; } else if (channel === "Whispers Log") { channelID = WhispersChannel; } else if (channel === "Wires Log") { channelID = WiresChannel; } else if (channel === "Server Messages") { channelID = ServerMessagesChannel; } else if (channel.match(/^Level:\s+[0-9]+/)) { channelID = CMDResposeChannel; } else if (!channel.match(/^[a-zA-Z0-9]+$/)) { var channelSystemID = 0; $("select#chatChannel option").each(function(i,e){ var n = $(e).attr("name"); if (n==="channel"+channel) { channelSystemID = $(e).attr("value"); } }); if (channelSystemID === 0) { resolved = false; channelSystemID = "Main"; } channelID = channelSystemID; } else { if ($("#channel"+channel).length === 0) { resolved = false; channel = "Main"; } channelID = channel; } return {cID: channelID, res: resolved}; } function resolveChannelColor(channelID, channelName) { var color = $(".chatChannel[data-id='" + channelID + "']").css("background-color"); if (color === undefined) { $(".chatChannel").each(function(i,e){ if ($(e).attr("data-id") === channelName) { color = $(e).css("background-color"); } }); } if (channelID === ServerMessagesChannel) { color = "#007f23"; } else if (channelID === CMDResposeChannel) { color = "#317D80"; } else if (channelID === WhispersChannel) { color = "#DE3937"; //FF3 } else if (channelID === WiresChannel) { color = "#39DE37"; //FF3 } return color; } function updateChannelList(channel) { var tab = $("#channelTab" + channel.channelID); if (tab.length === 0) { if (channel.muted) { return; } $("