User:Lady Furude/chat.js

/* $(function {   "use strict";    // This array is going to contain all the messages    var loggedMsg = [];    // All the events    var loggedMsgEvent = [];    // NEW: Log everything by event    var loggedMessagesArray = (function { // Describing actions that need to be logged var actions = ["chat:add", "join", "logout", "kick", "ban"]; // Defining their appearance var actionsLook = ["has joined the chat", "has left the chat", "has been kicked by", "has been banned by"]; actions.forEach(function(t) {           mainRoom.socket.bind(t, function(a) { // First, log the event into an array loggedMsgEvent.push(t); // Defining all the elements of a message var time = new Date, year = time.getFullYear, month = time.getMonth + 1, day = time.getDate, hour = time.getHours, minute = time.getMinutes, second = time.getSeconds; // Formatting the data month = month.toString.padStart(2, 0); day = day.toString.padStart(2, 0); hour = hour.toString.padStart(2, 0); minute = minute.toString.padStart(2, 0); second = second.toString.padStart(2, 0); var loggedTime = "[" + year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + "] "; // Getting the content data var data = JSON.parse(a.data); var nickname = data.attrs.name; // For kicks and bans var modName = data.attrs.moderatorName; var kickedName = data.attrs.kickedUserName; // Future messages var logged; var msgLogged = loggedTime + "<" + nickname + "> " + data.attrs.text, joinLogged = loggedTime + nickname + " " + actionsLook[0], partLogged = loggedTime + nickname + " " + actionsLook[1], kickLogged = loggedTime + kickedName + " " + actionsLook[2] + " " + modName, banLogged = loggedTime + kickedName + " " + actionsLook[3] + " " + modName; // Choosing the format depending on the event type if (t == "join") logged = joinLogged; else if (t == "chat:add") logged = msgLogged; else if (t == "part" || t == "logout") logged = partLogged; else if (t == "kick") logged = kickLogged; else if (t == "ban") logged = banLogged; loggedMsg.push(logged); // Debugging console.log(a); });       }, this); return loggedMsg; });   // Creating a future feature    var chatLogger = {        // This array contains the logged messages        logged: [],        // This one contains all system messages        loggedSystemMsg: [],        // Formatting the logs        formatLogs: function {            // This variable contains the number of iteration            var amount = 0;            loggedMsg.forEach(function(a) { // Recognizing the amount of events/messages // var amount = window.mainRoom.model.chats.models.length; if (loggedMsgEvent[amount]) { this.logged.push(loggedMessagesArray[amount]); amount++; }           }, this);            // Debugging            console.log(this.logged.join("\n"));        },        // Logging the main room        clickLog: function {            // Organizing the messages into one format type            var messagesObj = window.mainRoom.model.chats._byCid,                messages = Object.keys(messagesObj);            this.formatLogs(messages, messagesObj);        },        // Logging the private room        clickPrivateLog: function {            var messagesObj = window.mainRoom.chats.privates[mainRoom.activeRoom].model.chats._byCid,                messages = Object.keys(messagesObj);            this.formatLogs(messages, messagesObj);        },        // Creating paragraphs for a future modal        createText: function {            var textDiv = $(" ", { class: "ChatLoggerDiv" });           for(var c = 0; c < this.logged.length; c++) {                textDiv.append($(" ", {                    text: this.logged[c]                }));            }            return textDiv;        },        // A modal window that contains the logged stuff        modal: function {            var modalContent = [                $(" ", { text: "The logged conversation" }), this.createText,               $(" "), {                    id: "ChatLoggerCopy",                    text: "Copy"                }            ];            $.showCustomModal("The result of logging the chat", $(" ").append(modalContent).html, {               id: "ChatLoggerResult", }).css({ width: "750px", overflow: "auto", height: "550px", "margin-left": "-388px" });           $("#ChatLoggerCopy").click(function { console.log("Yes it works"); // NO IT FUCKING DOES NOT // It's also a DOM function that you can call on nodes but only to execute their click listeners, not to set them var temp = document.createElement("input"); temp.setAttribute("value", document.getElementById("ChatLoggerDiv").innerHTML); document.body.appendChild(temp); temp.select; document.execCommand("copy"); document.body.removeChild(temp); $("#ChatLoggerResult").append($(" ", { id: "ChatLoggerCopied", text: "Text is copied!" }));           });        }    };    // Creating a button    mw.hook("dev.chat").add(function(chat) { chatLogger.button = new chat.button({           name: "ChatLog",            attr: {                text: "Log",                click: function {                    chatLogger.logged = [];                    // Checking whether it's a main or private room                    if (mainRoom.activeRoom == "main" || mainRoom.activeRoom === null) chatLogger.clickLog;                    else { chatLogger.clickPrivateLog; }                    chatLogger.modal;                }            }        }); });

// thanks to Speedy-kun for this incredible library <3 importArticle({       type: "script",        article: "u:dev:Chat-js.js"    }); }); */

importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:ChatNotifications/code.js',        'u:dev:MediaWiki:MobileChat.js',        'u:dev:MediaWiki:ChatHacks.js'    ] });