User:Lady Furude/chat.js

/* ChatDeveloperTools.js is another unreleased script that lacks some * improvements in design and maybe functionality... * Anyways, I use it myself currently lol */ $(function {   "use strict";    var ChatDeveloperTools = {        createLink: function(link, title) {            return $("", { href: (function {                   if (link.indexOf("global") !== -1) {                        return "https://community.wikia.com/wiki/Special:MyPage/" + link;                    }                    if (link.indexOf("MediaWiki") !== -1) {                        return mw.util.getUrl(link);                    }                    switch(link) {                        case "User": return mw.util.getUrl("Special:MyPage");                        case "Talk": return mw.util.getUrl("Special:MyTalk");                        case "Contribs": return mw.util.getUrl("Special:Contributions");                        case "UserActivity": return "https://community.wikia.com/wiki/Special:UserActivity";                        case "SpecialPages": return mw.util.getUrl("Special:SpecialPages");                        case "WikiActivity": return mw.util.getUrl("Special:WikiActivity");                        case "RecentChanges": return mw.util.getUrl("Special:RecentChanges"); default: return mw.util.getUrl("Special:MyPage/") + link; }               }),                target: "_blank",                text: title            }); },       createSection: function(obj) { var collection = []; var counter = 0; for (var key in obj) { counter++; if (counter == Object.keys(obj).length) { collection.push(this.createLink(key, obj[key])); } else { collection.push(this.createLink(key, obj[key]), ", "); }           }            return collection; },       showModal: function { var sections = [ this.createSection({                   User: "My Profile",                    Sandbox: "My Sandbox",                    Talk: "My Talk Page",                    Contribs: "My Contributions",                    UserActivity: "My Activity"                }), this.createSection({                   SpecialPages: "All Special Pages",                    WikiActivity: "Recent Wiki Activity",                    RecentChanges: "Recent Changes"                }), this.createSection({                   "MediaWiki:Common.js": "MW:Common JS",                    "MediaWiki:Common.css": "MW:Common.CSS"                }), this.createSection({                   "MediaWiki:Wikia.js": "MW:Wikia JS",                    "MediaWiki:Wikia.css": "MW:Wikia.CSS"                }), this.createSection({                   "MediaWiki:Chat.js": "MW:Chat JS",                    "MediaWiki:Chat.css": "MW:Chat.CSS"                }), this.createSection({                   "common.js": "Common JS",                    "common.css": "Common CSS"                }), this.createSection({                   "global.js": "Global JS",                    "global.css": "Global CSS"                }), this.createSection({                   "Wikia.js": "Wikia JS",                    "Wikia.css": "Wikis CSS"                }), this.createSection({                   "chat.js": "Chat JS",                    "chat.css": "Chat CSS"                }) ];           $.showCustomModal(                "Chat Developer Tools",                $(" ").append([ $(" ").append(                       $("", {text: "User Files"}), ": ", sections[0]                    ), $(" "), $(" ").append(                       $("", {text: "Special Pages"}), ": ", sections[1]                    ), $(" "), $(" ").append(                       $("", {text: "MediaWiki Common Files"}), ": ", sections[2]                    ), $(" "), $(" ").append(                       $("", {text: "MediaWiki Oasis Skin Files"}), ": ", sections[3]                    ), $(" "), $(" ").append(                       $("", {text: "MediaWiki Chat Files"}), ": ", sections[4]                    ), $(" "), $(" ").append(                       $("", {text: "User Common Files"}), ": ", sections[5]                    ), $(" "), $(" ").append(                       $("", {text: "User Global Files"}), ": ", sections[6]                    ), $(" "), $(" ").append(                       $("", {text: "User Oasis Skin Files"}), ": ", sections[7]                    ), $(" "), $(" ").append(                       $("", {text: "User Chat Files"}), ": ", sections[8]                    ), $(" ") ]).html, {                   id: "WikiaDeveloperTools"                }            ).css({                width: "550px",                overflow: "auto",                height: "285px",                "margin-left": "-283px"            }); }   };    mw.hook("dev.chat").add(function(chat) {        new chat.Button({ name: "DevTools", attr: { text: "Tools", click: function { ChatDeveloperTools.showModal; }           }        });    });    importArticle({        type: "script",        article: "u:dev:Chat-js.js"    }); });

/* FucodeLogger.js is an advanced script for logging the chat and private messages. * Contains several features, such as copying the logs or downloading them with a * special chosen filename. In other words, whatever you could wish for. * Authors: Lady Furude, KockaAdmiralac * * Thanks to KockaAdmiralac for help with finding appropriate methods, giving the * object that solved the difficulty of logging the messages, for testing the code with * me in his personal wiki, allowing to keep it there and suggesting Download feature. * Thanks to Speedit for help with making a button and creating an object~ * * If you've got a suggestion or found a bug, contact Lady Furude! */

$(function {   "use strict";    // This array is going to contain the messages of the main chat    var loggedMsg = [];    function getTime(c) {        var year = c.getFullYear;        var month = String(c.getMonth + 1).padStart(2, 0);        var day = c.getDate.toString.padStart(2, 0);        var hour = c.getHours.toString.padStart(2, 0);        var minute = c.getMinutes.toString.padStart(2, 0);        var second = c.getSeconds.toString.padStart(2, 0);        return "[" + year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + "] ";    }    // Logging the main chat    // Warning: Doesn't include messages sent before user's arrival.    ["chat:add", "join", "part", "logout", "kick", "ban"].forEach(function(e) { mainRoom.socket.bind(e, function(a) {           var loggedTime = getTime(new Date);            var data = JSON.parse(a.data);            var joinLogged = loggedTime + data.attrs.name + " " + "has joined the chat";            var partLogged = loggedTime + data.attrs.name + " " + "has left the chat";            var logoutLogged = loggedTime + data.attrs.name + " " + "has closed the chat window";            var kickLogged = loggedTime + data.attrs.kickedUserName + " " + "has been kicked by" + " " + data.attrs.moderatorName;            var banLogged = loggedTime + data.attrs.kickedUserName + " " + "has been banned by" + " " + data.attrs.moderatorName;            if (e == "chat:add") {                data.attrs.text.split("\n").forEach(function(line) { loggedMsg.push(loggedTime + "<" + data.attrs.name + "> " + line); });           }            var logged = (function { switch(e) { case "join": return joinLogged; case "part": return partLogged; case "logout": return logoutLogged; case "kick": return kickLogged; case "ban": return banLogged; }           });            if (e !== "chat:add") loggedMsg.push(logged);        }); });   var FucodeLogger = {        logged: [],        logActiveRoom: function {            if (mainRoom.activeRoom == "main" || mainRoom.activeRoom === null) {                // Pushing all that was logged by IIFE above                for (var e = 0; e < loggedMsg.length; e++) {                    this.logged.push(loggedMsg[e]);                }            } else {                // Otherwise, logging messages of a private room and format them                var msgObj = window.mainRoom.chats.privates[mainRoom.activeRoom].model.chats._byCid;                for (var i in msgObj) {                    // A little mistake here because it's a function inside a loop... rip                    msgObj[i].attributes.text.split("\n").forEach(function(line) { this.logged.push(getTime(new Date(msgObj[i].attributes.timeStamp)) + "<" + msgObj[i].attributes.name + "> " + line); }, this);               }            }        },        createText: function {            // Creating text for a future modal            var preContent = "";            for (var c = 0; c < this.logged.length; c++) {                // Placing the last message of logs                if (c + 1 == this.logged.length) preContent += this.logged[c];                else { preContent += this.logged[c] + "\n"; }            }            return $(" ", { id: "FucodeLoggerContent", text: preContent, });       },        copyLogs: function {            document.querySelector("#FucodeLoggerCopy").addEventListener("click", function { // Double-click: the copy feature works at the second click, for some reason. $("#FucodeLoggerCopy").click; var range = document.createRange; range.selectNode(document.querySelector("#FucodeLoggerContent")); window.getSelection.addRange(range); try { document.execCommand("copy"); if (!document.getElementById("FucodeLoggerCopied")) { $(".modalContent").append($(" ", { id: "FucodeLoggerCopied", text: "Text is copied!" }));                   }                } catch(err) { // If it's not copied, look into console console.log("Whoops, unable to copy.\nMaybe switch to a normal browser?.."); }               window.getSelection.removeAllRanges; });       },        clickToDownloadLogs: function {            $("#FucodeLoggerExecuteDl").click(function { if (!document.getElementById("FucodeLoggerLinkDl")) { $("#FucodeLoggerExecuteDl").text(""); $("#FucodeLoggerExecuteDl").append($("", { id: "FucodeLoggerLinkDl", download: (function {                           var filename = $("#FucodeLoggerSetFilename").val + ".txt";                            return filename;                        }), href: URL.createObjectURL(new Blob([$("#FucodeLoggerContent").text], {type: 'octet/stream'})), text: "Download logs" }).css({ color: "#FFF", "text-decoration": "none" }));               }            });        },        downloadLogs: function {            $("#FucodeLoggerDl").click(function { if (!document.getElementById("FucodeLoggerSetDownload")) { $(".modalContent").append($(" ", { id: "FucodeLoggerSetDownload" }));                   $("#FucodeLoggerSetDownload").append([$(" ", { id: "FucodeLoggerFilenameNotif", text: "Type the filename:" }), $(" ", {                       id: "FucodeLoggerSetFilename", type: "text" }), $(" ", {                       id: "FucodeLoggerExecuteDl", name: "setFilename", text: "Set the filename" })]);                   // Allowing an user to press Enter instead of clicking the button $("#FucodeLoggerSetFilename").keyup(function(event) {                       if (event.keyCode === 13) $("#FucodeLoggerExecuteDl").click;                    }); this.clickToDownloadLogs; }           }.bind(this));        },        createModal: function {            $.showCustomModal("The result of logging the chat", $(" ").append([this.createText,                $(" ", { id: "FucodeLoggerCopy", text: "Copy" }),               $(" ", {                    id: "FucodeLoggerDl", text: "Download" })           ]).html, { id: "FucodeLoggerResult", }).css({ width: "750px", overflow: "auto", height: "550px", "margin-left": "-388px" });           this.copyLogs;            this.downloadLogs;        },    };

// Creating a button mw.hook("dev.chat").add(function(chat) {       FucodeLogger.button = new chat.Button({ name: "ChatLog", attr: { text: "Log", click: function { FucodeLogger.logged = []; FucodeLogger.logActiveRoom; FucodeLogger.createModal; }           }        });    });

// An incredible library made by Speedit, thanks! importArticle({       type: "script",        article: "u:dev:Chat-js.js"    }); });

// lags because it prevents removing .selected $("h1.public.wordmark").css({   color: "#EE537D",    "font-size": "12px",    "font-weight": "bold",    "padding-left": "15px" }).text("Community Central");

importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:ChatAwayButton/code.js',        'u:dev:MediaWiki:ChatBlockButton/code.2.js',        'u:dev:MediaWiki:ChatNotifications/code.js',        //I guess it has no bugs: 'u:dev:MediaWiki:ChatUserPageButton.js',        'u:dev:MediaWiki:EmoticonsWindow/code.js',        // Testing still: 'u:dev:MediaWiki:FucodeLogger.js',        'u:dev:MediaWiki:MobileChat.js'    ] });