Skip to content

Instantly share code, notes, and snippets.

@ekzhang
Last active March 18, 2016 00:13
Show Gist options
  • Save ekzhang/3e487883cc973e8136dc to your computer and use it in GitHub Desktop.
Save ekzhang/3e487883cc973e8136dc to your computer and use it in GitHub Desktop.
Run this code at ALL TIMES while playing mafia, and DO NOT REFRESH. You may run this code via the address bar, a bookmark, or the browser console.
function hashCode(e){var s,a,t,o=0;if(0===e.length)return o;for(s=0,t=e.length;t>s;s++)a=e.charCodeAt(s),o=(o<<5)-o+a,o|=0;return o}var players="",playing=!1,night=!1,dead=!1,my_name=$("div.message-wrapper.is-me")[0].children[0].innerHTML.trim().slice(0,-1),god="eygmath",voted=!1,_send=Classroom.send,new_send=function(e){e.message.toLowerCase().startsWith("-&gt;join")&&(e.message="-&gt;join|"+hashCode(my_name+"_join")),_send(e)},_onPluginMessage=Classroom.socket.onPluginMessage,newmsg=function(e){var s=e.message;if(my_name=my_name.toLowerCase(),"undefined"!=typeof e.message&&0===e.message.indexOf("-&gt;")){if(e.message=e.message.substring(5),e.speaker===god)if(e.message.toLowerCase().startsWith("players"))-1!==e.message.toLowerCase().indexOf(my_name)&&(playing=!0,players=e.message.substring(8));else if(e.message.toLowerCase().startsWith("end"))playing=!1,dead=!1;else if(e.message.toLowerCase().startsWith("toggle")){if(night=!night,voted=!1,night&&!dead){for(var a=prompt("Who would you like to target?");-1===players.indexOf(a);)a=prompt("Sorry, please check case and spelling. Who would you like to target?");Classroom.send({action:"public-message","room-id":"971",message:"-&gt;role "+a})}}else e.message.toLowerCase().startsWith("all")?(e.message=e.message.substring(4),_onPluginMessage(e)):e.message.toLowerCase().startsWith(my_name)?(e.message=e.message.substring(my_name.length+1),_onPluginMessage(e)):e.message.toLowerCase().startsWith("kill")?-1!==e.message.indexOf(my_name)&&(dead=!0):e.message.toLowerCase().startsWith("transfer")&&(e.message=e.message.substring(9),god=e.message.trim());else if(e.speaker===my_name&&!dead){if(e.message.toLowerCase().startsWith("vote")){if(""==e.message.substring(5).trim()||!voted){for(var t=prompt("Who would you like to lynch?");-1===players.indexOf(t);)t=prompt("Sorry, please check case and spelling. Who would you like to lynch?");voted=!0,Classroom.send({action:"public-message","room-id":"971",message:"-&gt;vote "+t})}}else e.message.toLowerCase().startsWith("kill")?alert("Oops! There is no kill command. You will be prompted during the night, and type ->vote during the day."):e.message.toLowerCase().startsWith("list")?alert("Players: "+playerlist):e.message.toLowerCase().startsWith("help")&&alert("->help, ->join, ->list, ->role, and ->vote are valid actions.");_onPluginMessage(e)}}else!playing||night||dead?playing||dead||_onPluginMessage(e):-1!==players.indexOf(e.speaker)&&(e.message=s,_onPluginMessage(e))};Classroom.send=new_send,Classroom.socket.onPluginMessage=newmsg;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment