NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Faction Chat Discord logger // @namespace torn.com // @version 1.0 // @description Faction chat to discord // @author SMH [1208589] // @include *www.torn.com/rules.php* // @grant GM.xmlHttpRequest // @license MIT // ==/UserScript== var secret = document.querySelector("body > script:nth-child(6)").getAttribute("secret"); var uid = document.querySelector("body > script:nth-child(6)").getAttribute("uid"); var socket = new WebSocket("wss://ws-chat.torn.com/chat/ws?uid="+uid+"&secret="+secret); var audioPlayer = document.createElement('audio'); audioPlayer.src = 'https://www.torn.com/casino/russianRoulette/audio/bang.ogg'; audioPlayer.preload = 'auto'; socket.onmessage = function(event) { if(typeof event.data === 'string'){ var jsonObject = JSON.parse(event.data); if(jsonObject['data'][0]['roomId'] === 'Faction:27370' && jsonObject['data'][0].hasOwnProperty("messageText")){ var date = new Date(jsonObject['data'][0]['time']*1000); GM.xmlHttpRequest({ method: "POST", url: "https://discordapp.com/api/webhooks/", data: JSON.stringify({"embeds": [{"title": jsonObject['data'][0]['senderName']+" ["+jsonObject['data'][0]['senderId']+"]", "url": "https://www.torn.com/profiles.php?XID="+jsonObject['data'][0]['senderId'], "description": jsonObject['data'][0]['messageText'], "color": "16711680", "footer": {"text": "Torn City Time (tct) - "+date.getUTCHours().toString().padStart(2, "0")+":"+date.getMinutes().toString().padStart(2, "0")+":"+date.getSeconds().toString().padStart(2, "0")} }]}), headers: { "Content-Type": "application/json" }, }); } } }; socket.onclose = function(event) { if (event.wasClean) { audioPlayer.play(); alert(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`); } else { audioPlayer.play(); alert('[close] Connection died'); } }; socket.onerror = function(error) { audioPlayer.play(); alert(`[error] ${error.message}`); };