User:Lady Furude/chat.js

$(function {   "use strict";    // This array is going to contain all the messages    var loggedMsg = [];    // All the events    var loggedMsgEvent = [];    // Function for outputting time parameters    function getTime(c) {        var time = c,            year = c.getFullYear,            month = c.getMonth + 1,            day = c.getDate,            hour = c.getHours,            minute = c.getMinutes,            second = c.getSeconds;        // Formatting the time's 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);        // Returning the part with timestamp of a message        return "[" + year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + "] ";    }    // Log everything by event var loggedMsgArray = (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);                var loggedTime = getTime(new Date);                // Getting the content data                var data = JSON.parse(a.data);                var nickname = data.attrs.name;                var text = data.attrs.text;                // For kicks and bans                var modName = data.attrs.moderatorName;                var kickedName = data.attrs.kickedUserName;                // Future messages                var logged;                var msgLogged = loggedTime + "<" + nickname + "> " + 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: [],        // Formatting the private logs        formatLogs: function(messages, messagesObj) {            messages.forEach(function(a) { var nickname = messagesObj[a]._previousAttributes.name, content = messagesObj[a]._previousAttributes.text; // Declaring the format of logs var loggedTime = getTime(new Date(messagesObj[a]._previousAttributes.timeStamp)); var privateMsg = loggedTime + "<" + nickname + "> " + content; this.logged.push(privateMsg); }, this);       },        // Logging the currently opened room        clickLog: function {            // This variable contains the number of iteration when the main chat gets logged            var amount = 0;            if (mainRoom.activeRoom == "main" || mainRoom.activeRoom === null) {                loggedMsg.forEach(function(a) { this.logged.push(loggedMsgArray[amount]); amount++; }, this);           } else {                var messagesObj = window.mainRoom.chats.privates[mainRoom.activeRoom].model.chats._byCid,                    messages = Object.keys(messagesObj);                this.formatLogs(messages, messagesObj);            }            // Debugging            console.log(this.logged.join("\n"));        },        // 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 = [];                    chatLogger.clickLog;                    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'    ] });