// ==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; } $("
") .attr("id", "channelTab" + channel.channelID) .attr("data-channel", channel.channelID) .addClass("border2 ui-element channelTab") .css({ color: channel.channelColor }) .appendTo("#channelTabList"); tab = $("#channelTab" + channel.channelID); } var channelTabLabel = "#"+channel.channelName; tab.text(channelTabLabel); if (channel.newMessages && !channel.muted) { if ($(".Ch"+channel.channelID+"Badge").length === 0) { var badge = $("") .addClass("ChBadge") .addClass("border2") .addClass("Ch"+channel.channelID+"Badge") .text(channel.newMessagesCount) .appendTo("#channelTab"+channel.channelID); } else { $(".Ch"+channel.channelID+"Badge").text(channel.newMessagesCount); } } if (channel.muted) { $("") .addClass("ChBadge fa fa-times border2 ui-element") .appendTo("#channelTab"+channel.channelID); } } function addSettingsTab() { $("
") .attr("id", "ToASettings") .addClass("border2 ui-element ToASettings") .prependTo("#channelTabList"); $("") .addClass("fa") .addClass("fa-cogs") .css({ color: "#ffd700", fontWeight: 500 }) .appendTo("#ToASettings") } function randomNumber() { return Math.floor(Math.random() * 1000000+1000000); } function loadDependencies() { // $("") .attr({ rel: "stylesheet", href: "//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" }) .appendTo("head"); } function prepareHTML() { $("
") .attr("id", "channelTabListWrapper") .insertBefore("#chatMessageListWrapper"); $("
") .attr("id", "channelTabList") .appendTo("#channelTabListWrapper"); /** * Preview channel */ $("
") .attr("id", "channelPreviewWrapper") .addClass("border2") .addClass("ui-element") .appendTo("body"); $("
") .css("text-align", "center") .appendTo("#channelPreviewWrapper"); $("
") .attr("id", "channelPreviewActions") .appendTo("#channelPreviewWrapper"); $("") .addClass("border2 ui-element fa fa-check sapphire cpa") .attr("id", "CPAReset") .attr("title", "Mark as read") .appendTo("#channelPreviewActions"); $("") .addClass("border2 ui-element fa fa-eraser emerald cpa") .attr("id", "CPAPurge") .attr("title", "Clear channel of all messages") .appendTo("#channelPreviewActions"); $("") .addClass("border2 ui-element fa fa-unlink ruby cpa") .attr("id", "CPARemove") .attr("title", "Clear the channel and remove it from tabs\nIf any new messages pop into it, it will come back.") .appendTo("#channelPreviewActions"); $("
") .attr("id", "channelPreviewContent") .appendTo("#channelPreviewWrapper"); $("
") .attr("id", "channelPreviewMessages") .css({ padding:"2px", }) .appendTo("#channelPreviewContent"); $("#channelPreviewContent").mCustomScrollbar(); /** * context menu */ $("
") .attr("id", "channelTabContextMenu") .addClass("ui-element navSection") .appendTo("body"); $("") .attr("id", "chTabCTMenuMute") .text("Mute channel") .addClass("cctmButton") .appendTo("#channelTabContextMenu"); $("") .addClass("ui-element fa fa-bell-slash titanium") .prependTo("#chTabCTMenuMute"); $("") .attr("id", "chTabCTMenuUnMute") .text("Un-mute channel") .addClass("cctmButton") .appendTo("#channelTabContextMenu"); $("") .addClass("ui-element fa fa-bell platinum") .prependTo("#chTabCTMenuUnMute"); $("") .attr("id", "chTabCTMenuReset") .text("Mark as read") .addClass("cctmButton") .appendTo("#channelTabContextMenu"); $("") .addClass("ui-element fa fa-check sapphire") .prependTo("#chTabCTMenuReset"); $("") .attr("id", "chTabCTMenuPurge") .text("Purge messages") .addClass("cctmButton") .appendTo("#channelTabContextMenu"); $("") .addClass("ui-element fa fa-eraser emerald") .prependTo("#chTabCTMenuPurge"); $("") .attr("id", "chTabCTMenuRemove") .text("Remove from tabs") .addClass("cctmButton") .appendTo("#channelTabContextMenu"); $("") .addClass("ui-element fa fa-unlink ruby") .prependTo("#chTabCTMenuRemove"); $("") .attr("id", "chTabCTMenuLeave") .text("Leave channel") .addClass("cctmButton") .appendTo("#channelTabContextMenu"); $("") .addClass("ui-element fa fa-arrow-right diamond") .prependTo("#chTabCTMenuLeave"); $("#channelTabContextMenu").hide(); /** * settings */ $("
") .attr("id", "ToASettingsWindow") .addClass("border2 ui-element") .appendTo("body"); $("
") .css("text-align", "center") .text("TabsOfAvabur - Settings") .appendTo("#ToASettingsWindow"); $("
") .attr("id","ToASWMenu") .appendTo("#ToASettingsWindow"); var t = $("
") .addClass("col-xs-6 text-center"); var l = t.clone().appendTo("#ToASWMenu"); var r = t.clone().appendTo("#ToASWMenu"); $("