// ==UserScript== // @name GameFAQs Colored Text Renderer // @description This script translates , , , , , , and tags into GameFAQs friendly HTML tags, and accordingly renders messages into the aforementioned colors. // @namespace http://thelolilulelo.wordpress.com/ // @grant GM_addStyle // @include https://www.gamefaqs.com/boards/* // @exclude https://www.gamefaqs.com/boards/user.php* // @exclude https://www.gamefaqs.com/boards/sigquote.php* // @version 1.2 // @downloadURL https://update.greasyfork.cloud/scripts/5157/GameFAQs%20Colored%20Text%20Renderer.user.js // @updateURL https://update.greasyfork.cloud/scripts/5157/GameFAQs%20Colored%20Text%20Renderer.meta.js // ==/UserScript== GM_addStyle ( " \ @font-face {font-family: MadokaRunes; src: url('https://dl.dropboxusercontent.com/u/42167128/MadokaRunes.ttf');} \ " ); GM_addStyle ( " \ @font-face {font-family: ComicSans; src: url('https://dl.dropboxusercontent.com/u/42167128/comic.ttf');} \ " ); GM_addStyle ( " \ @font-face {font-family: Papyrus; src: url('https://dl.dropboxusercontent.com/u/42167128/papyrus.ttf');} \ " ); var CONST = {NEW:'Post Message', PREV:'Preview Message', PREVS:'Preview and Spellcheck Message', EDIT:'Save Changes'}; var BTN_ID = {RED:'btnRed', BLUE:'btnBlue', GOLD:'btnGold', GREEN:'btnGreen', MAUVE:'btnMauve', PINK:'btnPink', ORANGE:'btnOrange', UNDERLINE:'btnUnderline', STRIKEOUT:'btnStrikeout', SMALL:'btnSmall', BIG:'btnBig'}; if (document.getElementsByTagName('textarea').length != 0) { document.addEventListener('click', eventListener, true); btnRed = document.createElement("input"); btnRed.setAttribute("tabindex", "-1") btnRed.setAttribute("id", BTN_ID.RED); btnRed.setAttribute("value", "Red"); btnRed.setAttribute("type", "button"); btnBlue = document.createElement("input"); btnBlue.setAttribute("tabindex", "-1") btnBlue.setAttribute("id", BTN_ID.BLUE); btnBlue.setAttribute("value", "Blue"); btnBlue.setAttribute("type", "button"); btnGreen = document.createElement("input"); btnGreen.setAttribute("tabindex", "-1") btnGreen.setAttribute("id", BTN_ID.GREEN); btnGreen.setAttribute("value", "Green"); btnGreen.setAttribute("type", "button"); btnGold = document.createElement("input"); btnGold.setAttribute("tabindex", "-1") btnGold.setAttribute("id", BTN_ID.GOLD); btnGold.setAttribute("value", "Gold"); btnGold.setAttribute("type", "button"); btnMauve = document.createElement("input"); btnMauve.setAttribute("tabindex", "-1") btnMauve.setAttribute("id", BTN_ID.MAUVE); btnMauve.setAttribute("value", "Mauve"); btnMauve.setAttribute("type", "button"); btnPink = document.createElement("input"); btnPink.setAttribute("tabindex", "-1") btnPink.setAttribute("id", BTN_ID.PINK); btnPink.setAttribute("value", "Pink"); btnPink.setAttribute("type", "button"); btnOrange = document.createElement("input"); btnOrange.setAttribute("tabindex", "-1") btnOrange.setAttribute("id", BTN_ID.ORANGE); btnOrange.setAttribute("value", "Orange"); btnOrange.setAttribute("type", "button"); btnUnderline = document.createElement("input"); btnUnderline.setAttribute("tabindex", "-1") btnUnderline.setAttribute("id", BTN_ID.UNDERLINE); btnUnderline.setAttribute("value", "Underline"); btnUnderline.setAttribute("type", "button"); btnStrikeout = document.createElement("input"); btnStrikeout.setAttribute("tabindex", "-1") btnStrikeout.setAttribute("id", BTN_ID.STRIKEOUT); btnStrikeout.setAttribute("value", "Strike"); btnStrikeout.setAttribute("type", "button"); btnSmall = document.createElement("input"); btnSmall.setAttribute("tabindex", "-1") btnSmall.setAttribute("id", BTN_ID.SMALL); btnSmall.setAttribute("value", "Small"); btnSmall.setAttribute("type", "button"); btnBig = document.createElement("input"); btnBig.setAttribute("tabindex", "-1") btnBig.setAttribute("id", BTN_ID.BIG); btnBig.setAttribute("value", "Big"); btnBig.setAttribute("type", "button"); if (document.getElementsByName('gamefox-quickpost-normal').length != 0) { var elemParent = document.getElementsByName('gamefox-quickpost-normal')[0]; elemParent.insertBefore(btnRed, elemParent.childNodes[0]); //elemParent.childNodes[0].appendChild(btnRed); } else { var elemParent = document.getElementsByTagName('textarea')[0]; elemParent.parentNode.parentNode.insertBefore(btnRed, elemParent.parentNode); } btnRed.parentNode.insertBefore(btnBlue, btnRed.nextSibling); btnBlue.parentNode.insertBefore(btnGreen, btnBlue.nextSibling); btnGreen.parentNode.insertBefore(btnMauve, btnGreen.nextSibling); btnMauve.parentNode.insertBefore(btnPink, btnMauve.nextSibling); btnPink.parentNode.insertBefore(btnGold, btnPink.nextSibling); btnGold.parentNode.insertBefore(btnOrange, btnGold.nextSibling); btnOrange.parentNode.insertBefore(btnUnderline, btnOrange.nextSibling); btnUnderline.parentNode.insertBefore(btnStrikeout, btnUnderline.nextSibling); btnStrikeout.parentNode.insertBefore(btnSmall, btnStrikeout.nextSibling); btnSmall.parentNode.insertBefore(btnBig, btnSmall.nextSibling); btnGold.parentNode.insertBefore(btnOrange, btnGold.nextSibling); btnBig.appendChild(document.createElement("br")); } renderColors(); function eventListener(event) { var elemVal = event.target.value; if (elemVal == CONST.NEW || elemVal == CONST.PREV || elemVal == CONST.PREVS || elemVal == CONST.EDIT) { var text = document.getElementsByTagName('textarea')[0].value; //red text = text.replace(//gi, '').replace(/<\/font>/gi, ''); //blue text = text.replace(//gi, ''); //gold text = text.replace(//gi, ''); //green text = text.replace(//gi, ''); //mauve text = text.replace(//gi, ''); //salmonpink text = text.replace(//gi, ''); //orange text = text.replace(//gi, ''); //contract text = text.replace(//gi, ''); //AOEKnight text = text.replace(//gi, ''); //rennyf1 text = text.replace(//gi, '<\/i><\/b>'); //yaranaika text = text.replace(//gi, '<\/b><\/i>'); //conwayshrug text = text.replace(//gi, '<\/b><\/code>'); //conwayfacepalm text = text.replace(//gi, '<\/b><\/code><\/b>'); //papyrus font text = text.replace(//gi, '<\/i><\/code><\/b>'); //papyrus emote text = text.replace(//gi, '<\/b><\/code><\/i>'); //sans emote text = text.replace(//gi, '<\/i><\/code><\/i>'); //tobdog text = text.replace(//gi, '<\/b><\/b><\/code>'); //happycrank text = text.replace(//gi, '<\/b><\/i><\/code>'); //Comic Sans MS text = text.replace(//gi, ' '); //Marquee text = text.replace(//gi, '').replace(/<\/marquee>/gi, ''); //Underline text = text.replace(//gi, '').replace(/<\/u>/gi, ''); //Strikeout text = text.replace(//gi, '').replace(/<\/strike>/gi, ''); //Small Font text = text.replace(//gi, ''); //Big Font text = text.replace(//gi, ''); //DINOSAUR text = text.replace(//gi, ''); //EDIT Comic Sans MS text = text.replace(/<\/i><\/b><\/code><\/b>/gi, ''); //EDIT Red text = text.replace(/<\/b><\/b><\/i>/gi, ''); //EDIT Blue text = text.replace(/<\/b><\/b><\/b>/gi, ''); //EDIT Gold text = text.replace(/<\/i><\/b><\/b>/gi, ''); //EDIT Green text = text.replace(/<\/i><\/i><\/b>/gi, ''); //EDIT Mauve text = text.replace(/<\/b><\/i><\/i>/gi, ''); //EDIT Salmon Pink text = text.replace(/<\/i><\/i><\/i>/gi, ''); //EDIT Orange text = text.replace(/<\/i><\/i><\/code><\/b>/gi, ''); //EDIT Madoka Font text = text.replace(/<\/i><\/i><\/code><\/i>/gi, '').replace(/<\/i><\/code>/gi, ''); //EDIT AOEKnight text = text.replace(/<\/i><\/b><\/code>/gi, ''); //EDIT rennyf1 text = text.replace(/<\/i><\/b>/gi, ''); //EDIT yaranaika text = text.replace(/<\/b><\/i>/gi, ''); //EDIT conwayshrug text = text.replace(/<\/b><\/code>/gi, ''); //EDIT conwayfacepalm text = text.replace(/<\/b><\/code><\/b>/gi, ''); //EDIT mute text = text.replace(/<\/i><\/code><\/b>/gi, ''); //EDIT surprise text = text.replace(/<\/b><\/code><\/i>/gi, ''); //EDIT questionmark text = text.replace(/<\/i><\/code><\/i>/gi, ''); //EDIT gokigen text = text.replace(/<\/b><\/b><\/code>/gi, ''); //EDIT happycrank text = text.replace(/<\/b><\/i><\/code>/gi, ''); //EDIT Marquee text = text.replace(/<\/b><\/code><\/code>/gi, '').replace(/<\/i><\/b><\/code><\/code><\/code>/gi, ''); //EDIT Underline text = text.replace(/<\/i><\/code><\/code>/gi, '').replace(/<\/b><\/code><\/code><\/code>/gi, ''); //EDIT Strikeout text = text.replace(/<\/b><\/i><\/code><\/i>/gi, '').replace(/<\/i><\/code><\/code><\/code>/gi, ''); //EDIT Small Font text = text.replace(/<\/b><\/b><\/code><\/i>/gi, ''); //EDIT Big Font text = text.replace(/<\/b><\/b><\/code><\/b>/gi, ''); //EDIT DINOSAUR text = text.replace(/<\/b><\/i><\/code><\/b>/gi, ''); document.getElementsByTagName('textarea')[0].value = text; } else { var elemId = event.target.id; var obj = document.getElementsByTagName('textarea')[0]; if (elemId == BTN_ID.RED) { insertAtCaret(obj, '', ''); } else if (elemId == BTN_ID.BLUE) { insertAtCaret(obj, '', ''); } else if (elemId == BTN_ID.GOLD) { insertAtCaret(obj, '', ''); } else if (elemId == BTN_ID.MAUVE) { insertAtCaret(obj, '', ''); } else if (elemId == BTN_ID.PINK) { insertAtCaret(obj, '', ''); } else if (elemId == BTN_ID.ORANGE) { insertAtCaret(obj, '', ''); } else if (elemId == BTN_ID.GREEN) { insertAtCaret(obj, '', ''); } else if (elemId == BTN_ID.UNDERLINE) { insertAtCaret(obj, '', ''); } else if (elemId == BTN_ID.STRIKEOUT) { insertAtCaret(obj, '', ''); } else if (elemId == BTN_ID.SMALL) { insertAtCaret(obj, '', ''); } else if (elemId == BTN_ID.BIG) { insertAtCaret(obj, '', ''); } } } function insertAtCaret(obj, tagOpen, tagClose) { if (obj.selectionStart) { obj.focus(); var start = obj.selectionStart; var end = obj.selectionEnd; obj.value = obj.value.substr(0, start).concat(tagOpen).concat(obj.value.substr(start, end - start)).concat(tagClose).concat(obj.value.substr(end)); } if (start != null) { setCaretTo(obj, start + tagOpen.length); } else { //obj.value += text; } } function setCaretTo(obj, pos) { if(obj.createTextRange) { var range = obj.createTextRange(); range.move('character', pos); range.select(); } else if(obj.selectionStart) { obj.focus(); obj.setSelectionRange(pos, pos); } } function renderColors() { var msg = document.getElementsByClassName('msg_body'); if (msg.length != 0) { var i = 0; for (i = 0; i < msg.length; i++) { //Comic Sans msg[i].innerHTML = msg[i].innerHTML.replace(/<\/i><\/b><\/code><\/b>/gi, ""); //Dinosaur msg[i].innerHTML = msg[i].innerHTML.replace(/<\/b><\/i><\/code><\/b>/gi, ""); //Big Font msg[i].innerHTML = msg[i].innerHTML.replace(/<\/b><\/b><\/code><\/b>/gi, ""); //Small Font msg[i].innerHTML = msg[i].innerHTML.replace(/<\/b><\/b><\/code><\/i>/gi, ""); //Strikeout msg[i].innerHTML = msg[i].innerHTML.replace(/<\/b><\/i><\/code><\/i>/gi, "").replace(/<\/i><\/code><\/code><\/code>/gi, ''); //Underline msg[i].innerHTML = msg[i].innerHTML.replace(/<\/i><\/code><\/code>/gi, "").replace(/<\/b><\/code><\/code><\/code>/gi, ''); //Marquee msg[i].innerHTML = msg[i].innerHTML.replace(/<\/b><\/code><\/code>/gi, "").replace(/<\/i><\/b><\/code><\/code><\/code>/gi, ''); //Madoka Font msg[i].innerHTML = msg[i].innerHTML.replace(/<\/i><\/i><\/code><\/i>/gi, ""); //Orange msg[i].innerHTML = msg[i].innerHTML.replace(/<\/i><\/i><\/code><\/b>/gi, ""); //Salmon Pink msg[i].innerHTML = msg[i].innerHTML.replace(/<\/i><\/i><\/i>/gi, ""); //Mauve msg[i].innerHTML = msg[i].innerHTML.replace(/<\/b><\/i><\/i>/gi, ""); //Red msg[i].innerHTML = msg[i].innerHTML.replace(/<\/b><\/b><\/i>/gi, ""); //Blue msg[i].innerHTML = msg[i].innerHTML.replace(/<\/b><\/b><\/b>/gi, ""); //Gold msg[i].innerHTML = msg[i].innerHTML.replace(/<\/i><\/b><\/b>/gi, ""); //happycrank msg[i].innerHTML = msg[i].innerHTML.replace(/<\/b><\/i><\/code>/gi, ""); //AOEKnight msg[i].innerHTML = msg[i].innerHTML.replace(/<\/i><\/b><\/code>/gi, ""); //tobdog msg[i].innerHTML = msg[i].innerHTML.replace(/<\/b><\/b><\/code>/gi, ""); //sans emote msg[i].innerHTML = msg[i].innerHTML.replace(/<\/i><\/code><\/i>/gi, ""); //papyrus emote msg[i].innerHTML = msg[i].innerHTML.replace(/<\/b><\/code><\/i>/gi, ""); //papyrus font msg[i].innerHTML = msg[i].innerHTML.replace(/<\/i><\/code><\/b>/gi, ""); //conwayfacepalm msg[i].innerHTML = msg[i].innerHTML.replace(/<\/b><\/code><\/b>/gi, ""); //conwayshrug msg[i].innerHTML = msg[i].innerHTML.replace(/<\/b><\/code>/gi, ""); //yaranaika msg[i].innerHTML = msg[i].innerHTML.replace(/<\/b><\/i>/gi, ""); //rennyf1 msg[i].innerHTML = msg[i].innerHTML.replace(/<\/i><\/b>/gi, ""); //Green msg[i].innerHTML = msg[i].innerHTML.replace(/<\/i><\/i><\/b>/gi, "").replace(/<\/i><\/code>/gi, ''); } } }