// ==UserScript== // @name ClanChatSaver // @namespace http://tampermonkey.net/ // @version 0.9.1 // @description Script created for adding the ability to save clan chat to an html file // @author JustinR17 // @match https://www.warzone.com/MultiPlayer?ChatRoom=* // @grant none // @require http://cdn.jsdelivr.net/g/filesaver.js // @require // @downloadURL none // ==/UserScript== function saveFile(value, name) { var fileBlob = new Blob([value], { type: "text/plain;charset=utf-8" }); saveAs(fileBlob, name + ".html"); } function startFile(chat) { return "" + chat + ""; } function endFile() { return "
"; } function formatMessage(curMsg) { var output = ""; var playerCol = curMsg.querySelectorAll("div[id^='ujs_LeftCol']")[0].innerText; var messageCol = curMsg.querySelectorAll("div[id^='ujs_Message']")[0].innerText; if (playerCol == "Player Name") { playerCol = ""; } output += playerCol + "" output += messageCol + "" return output; } function doSave() { var chatFinal = prompt("Enter a file name: ", "chat"); if (chatFinal == null) { return; } var date = new Date(); chatFinal = date.getFullYear() + ("0" + date.getMonth().toString()).slice(-2) + ("0" + date.getDay().toString()).slice(-2) + "-" + chatFinal; var output = startFile(chatFinal); var chat = document.getElementById("ujs_ChatContainer_2"); var childNodes = chat.childNodes; for (var i = 0; i < chat.childNodes.length; i++) { var curMsg = childNodes[i]; output += formatMessage(curMsg); } output += endFile(); saveFile(output, chatFinal); } function getModalButton() { return ''; } function initiateSave() { var modalButton = document.createElement("div"); modalButton.innerHTML = getModalButton(); var navBox = document.getElementsByClassName("navbar-nav")[0]; navBox.appendChild(modalButton); var el = document.getElementById("saveChatButton"); if (el.addEventListener) { el.addEventListener("click", doSave, false); } else if (el.attachEvent) { el.attachEvent('onclick', doSave); } } (function() { 'use strict'; initiateSave(); })();