-
-
Save pasghetti/875223987490d5658579908acc3de36c to your computer and use it in GitHub Desktop.
Generals.io extension to automate superficial chat.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Generals.io Superficiality Mod | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0.3 | |
// @description Takes care of formalities for you in generals.io chat. | |
// @author pasghetti | |
// @match https://generals.io | |
// @match https://*.generals.io | |
// @match https://generals.io/games/* | |
// @match https://*.generals.io/games/* | |
// @grant none | |
// @require https://cdn.rawgit.com/pasghetti/wshook/master/wsHook.js | |
// @run-at document-start | |
// ==/UserScript== | |
var greeting = "glhf"; | |
var msg = ""; | |
var turn = 0; | |
var lossEnding = "ggwp"; | |
var winEnding = "gg"; | |
var chatRoom = ""; | |
wsHook.after = function(messageEvent, url, wsObject) { | |
if(messageEvent.data.indexOf("42[\"game_start\",") == 0) { | |
var check = messageEvent.data.indexOf(",{\"playerIndex\":") + ",{\"playerIndex\":".length; | |
if(messageEvent.data.substr(check, 1) === "-") { | |
return messageEvent; | |
} | |
var start = messageEvent.data.indexOf(",\"chat_room") + ",\"chat_room".length + 3; | |
var end = messageEvent.data.indexOf(",\"team_chat_room") - 1; | |
if(end < 0) { | |
end = messageEvent.data.indexOf(",\"usernames") - 1; | |
} | |
chatRoom = messageEvent.data.substr(start, end - start); | |
if(greeting !== "") { | |
wsObject.send("42[\"chat_message\",\"" + chatRoom + "\",\"" + greeting + "\",\"\"]"); | |
} | |
} | |
if(chatRoom !== "" && messageEvent.data.indexOf("42[\"game_update\",") == 0) { | |
var start = messageEvent.data.indexOf(",\"turn") + ",\"turn".length + 2; | |
var end = messageEvent.data.indexOf(",\"attackIndex"); | |
var curTurn = +messageEvent.data.substr(start, end - start); | |
if(curTurn === turn && msg !== "") { | |
wsObject.send("42[\"chat_message\",\"" + chatRoom + "\",\"" + msg + "\",\"\"]"); | |
} | |
} | |
if(chatRoom !== "" && messageEvent.data.indexOf("game_lost") != -1) { | |
if(lossEnding !== "") { | |
wsObject.send("42[\"chat_message\",\"" + chatRoom + "\",\"" + lossEnding + "\",\"\"]"); | |
} | |
chatRoom = ""; | |
} | |
if(chatRoom !== "" && messageEvent.data.indexOf("game_won") != -1) { | |
if(winEnding !== "") { | |
wsObject.send("42[\"chat_message\",\"" + chatRoom + "\",\"" + winEnding + "\",\"\"]"); | |
} | |
chatRoom = ""; | |
} | |
return messageEvent; | |
} | |
var minimized = false; | |
function checkChat() { | |
var log = document.getElementsByClassName("chat-messages-container"); | |
var leaderboard = document.getElementById("game-leaderboard"); | |
if(leaderboard) { | |
if(!minimized && log.length > 0 && !log[0].classList.contains("minimized") && chatRoom !== "") { | |
minimized = true; | |
log[0].click(); | |
} | |
} else { | |
minimized = false; | |
} | |
} | |
setInterval(checkChat, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment