Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name EMjack
- // @version 2.0
- // @description Some crap you may find useful.
- // @match http://www.epicmafia.com/game/*
- // ==/UserScript==
- //Welcome back
- EMjack=String(function() {
- //Variables
- users={}
- meet=null
- master=null
- afk=false
- autokick=true
- autobomb=false
- development=false
- kicktimer=0
- roulette=6
- rouletteTurn=false
- //Locate the socket
- socket=io.sockets["http://www.epicmafia.com:80"].namespaces[""]
- //Breaking into that $scope
- socket.log=function(message,classes) {
- this.$events.message[0](JSON.stringify([["msg",{
- msg:message,
- type:classes
- }]]))
- }
- //Extend the socket
- socket.cmd=function(cmd,data) {
- this.send(JSON.stringify([cmd,data]))
- }
- //Extend it some more
- socket.chat=function(message) {
- this.cmd("<",{
- meet:meet,
- msg:message
- })
- }
- //Extend it until it bursts
- socket.vote=function(vote,meeting) {
- this.cmd("point",{
- meet:meeting||meet,
- target:vote
- })
- }
- //Going too far
- socket.dcfunc=function(callback) {
- this.socket.onDisconnect=callback
- this.cmd("leave")
- }
- //Plug in
- socket.on("message",function(packet) {
- var i,
- cmd,
- data
- packet=JSON.parse(packet)
- for(i=0;i<packet.length;i++) {
- cmd=packet[i][0],
- data=packet[i][1]
- switch(cmd) {
- case "auth":
- break
- case "round":
- for(var x in users) {
- users[x].voted=false
- }
- break
- case "users":
- for(var x in data.users) {
- new User(data.users[x])
- }
- me=users[user]
- break
- case "join":
- new User(data.data)
- socket.log(data.user+" has joined")
- break
- case "leave":
- delete users[data.user]
- socket.log(data.user+" has left")
- break
- case "kick":
- users[data.user].dead=true
- break
- case "kill":
- users[data.target].dead=true
- break
- case "<":
- if(i!==packet.length-1) break
- var target=data.msg.match(/^@(\w+)/)
- if(target!==null&&target[1]===user) {
- bot.eval(data.msg.substring(target[1].length+2),data)
- }
- break
- case "speech":
- if(data.type==="contact") {
- socket.log("The roles are... "+data.data.join(", "))
- }
- break
- case "meet":
- if(data.say) {
- meet=data.meet
- data.members.forEach(function(who) {
- if(users[who]) {
- users[who].meet=data.meet
- }
- })
- }
- if(data.meet==="mafia"||data.meet==="thief") {
- me.mafia=true
- users.list.forEach(function(who) {
- if(!data.choosedata[who]) {
- users[who].mafia=true
- socket.log(who+" is your partner!")
- }
- })
- }
- if(afk) {
- socket.vote(data.basket[0],data.meet)
- }
- break
- case "end_meet":
- if(data.say) {
- users.find({meet:data.meet}).forEach(function(who) {
- if(users[who]) {
- users[who].meet=null
- }
- })
- }
- break
- case "point":
- if(users[data.user]===undefined) break
- users[data.user].voted=!data.unpoint
- break
- case "countdown":
- if(!afk&&!autokick) break
- clearTimeout(kicktimer)
- kicktimer=setTimeout(function() {
- socket.cmd("kick")
- },data.totaltime)
- break
- case "start_input":
- if(autobomb) {
- socket.cmd("input",{
- id:data.id,
- input:{
- player:autobomb.constructor===String?autobomb:users.list.random()
- }
- })
- }
- else if(afk) {
- setTimeout(function() {
- socket.cmd("input",{
- id:data.id,
- input:{
- player:users.list.random()
- }
- })
- },5000)
- }
- break
- }
- }
- })
- //Hottie keys
- typebox=$("#typebox")
- $(window).on("keydown",function(event) {
- if(event.ctrlKey) {
- switch(event.which) {
- case 66:
- socket.cmd("option",{
- field:"fastgame"
- })
- socket.cmd("option",{
- field:"nospectate"
- })
- break
- case 81:
- socket.cmd("<",{
- meet:meet,
- msg:typebox.val(),
- quote:true,
- target:user
- })
- typebox.val("")
- break
- }
- }
- else if(!event.target.type) {
- typebox.focus()
- }
- })
- //Important information
- $(window).on("error",function(event) {
- socket.log("You've got error!")
- socket.log(event.originalEvent.message)
- })
- //Townie input
- typebox.on("keydown",function(event) {
- if(event.which!==13||this.value.charAt(0)!=="/") return
- commands.eval(this.value.substring(1))
- this.value=""
- })
- //Userperson
- function User(data) {
- this.id=data.id
- this.name=data.username
- this.me=this.name===user
- this.meet=meet
- this.mafia=false
- this.dead=false
- this.voted=false
- users[this.name]=this
- }
- //Userpeople
- Object.defineProperties(users,{
- list:{
- get:function() {
- return this.find({
- me:false,
- dead:false
- },true)
- }
- },
- find:{
- value:function(criteria,names) {
- var who,
- valid,
- criterion,
- output=[]
- for(who in this) {
- valid=true
- for(criterion in criteria) {
- if(this[who][criterion]!==criteria[criterion]) {
- valid=false
- break
- }
- }
- if(valid===true) {
- output.push(names===true?this[who].name:this[who])
- }
- }
- return output
- }
- }
- })
- //Command list
- function Cmdlist(cmds) {
- this.cmds=[]
- for(var x in cmds) {
- this.cmds.push({
- regex:RegExp(x),
- callback:cmds[x]
- })
- }
- }
- Cmdlist.prototype.eval=function(input,scope) {
- var match
- if(scope===undefined) scope=this
- this.cmds.some(function(command) {
- match=command.regex.exec(input)
- if(match!==null&&input===match[0]) {
- match.shift()
- command.callback.apply(scope,match)
- return true
- }
- })
- }
- //This is a sin
- bot=new Cmdlist({
- "scriptcheck":function() {
- socket.chat("I have it")
- },
- "roulette":function() {
- if(rouletteTurn) return
- var prefix="@"+this.user+" "
- socket.chat(prefix+roulette+" bullets left. You put the gun to your head...")
- var message=prefix+["Wet your pants","Gulp","Get ready","Say your prayers"].random()
- message+=", "+["pull it","pull the trigger","let it rip"].random()
- rouletteTurn=true
- setTimeout(function() {
- rouletteTurn=false
- if(Math.random()*roulette>1) {
- roulette--
- socket.chat(message+", and nothing happens.")
- }
- else {
- roulette=0
- socket.chat(message+", and die instantly.")
- }
- if(roulette===0) {
- roulette=6
- socket.chat("Reloaded the revolver. Who's next?")
- }
- },3000)
- },
- "be my bitch":function() {
- if(master===null) {
- master=this.user
- socket.chat("Yes master "+master+"...")
- }
- else {
- socket.chat("I belong to "+master)
- }
- },
- "roll over":function() {
- if(this.user===master) {
- socket.chat("/me rolls over for senpai...")
- }
- else {
- socket.chat("You're not the boss of me")
- }
- },
- "beg(?: for (.+))?":function(what) {
- if(this.user!==master) return
- var output=[
- "gets on her knees",
- "gets on all fours"
- ].random()
- output="/me "+output+" and begs"
- if(what) {
- output+=" for "+what
- }
- socket.chat(output)
- },
- "vote (\\w+)":function(who) {
- if(this.user!==master) return
- socket.vote(who,this.meet)
- }
- })
- //Get acquainted
- commands=new Cmdlist({
- "dev":function() {
- development=!development
- socket.log(development?"Logging I/O.":"Logging disabled.")
- },
- "afk":function() {
- afk=!afk
- socket.log(afk?"Jeeves will handle your affairs":"Jeeves has been dismissed")
- },
- "random":function() {
- socket.log(users.list.random())
- },
- "eval (.+)":function(input) {
- socket.log(JSON.stringify(eval(input)))
- },
- "kick (\\w+)":function(who) {
- if(users[who]!==undefined) {
- socket.cmd("ban",{
- uid:users[who].id
- })
- }
- },
- "vote(?: (no one)|(\\w+))?":function(none,who) {
- socket.vote(none!==undefined?"*":who!==undefined?who:users.list.random())
- },
- "will (.+)":function(will) {
- socket.log("You revised your will.","lastwill")
- socket.cmd("will",{
- msg:will
- })
- },
- "(?:fq|quote|fakequote) (\\w+) (.+)":function(who,message) {
- socket.cmd("<",{
- meet:meet,
- msg:message,
- quote:true,
- target:who
- })
- },
- "(?:ab|autobomb)(?: (\\w+))?":function(who) {
- if(users[who]!==undefined) {
- autobomb=who
- socket.log("Passing the bomb to "+who)
- }
- else {
- autobomb=!autobomb
- socket.log(autobomb?"You're now an anarchist!":"You're now a tree.")
- }
- },
- "ping( all)?":function(all) {
- socket.chat((all===undefined?users.find({
- dead:false,
- voted:false,
- meet:meet
- },true):users.list).join(" "))
- },
- "host(?: (.+))?":function(title) {
- socket.dcfunc(function() {
- $.getJSON("/game/add/mafia",{
- setupid:setup_id,
- ranked:false,
- add_title:title===undefined?0:1,
- game_title:title
- },function(json) {
- location.href="/game/"+json.table
- })
- })
- },
- "join":function() {
- lobbyGames({
- status_id:0,
- target:12,
- password:false
- },function(table) {
- socket.dcfunc(function() {
- location.href="/game/"+table.id
- })
- return true
- })
- },
- "games":function() {
- var a,
- div,
- chat=document.getElementById("window")
- lobbyGames({
- status_id:0,
- password:false
- },function(table) {
- a=document.createElement("a")
- a.textContent="Table "+table.id
- a.addEventListener("click",function(event) {
- socket.dcfunc(function() {
- location.href="/game/"+table.id
- })
- })
- div=document.createElement("div")
- div.appendChild(a)
- div.appendChild(document.createTextNode(" - "+table.numplayers+" / "+table.target+" players"))
- chat.appendChild(div)
- chat.scrollTop=chat.scrollHeight
- })
- }
- })
- //Misc.
- function lobbyGames(criteria,callback) {
- $.ajax({url:"/game/find?page=1",method:"get"}).success(function(json) {
- var criterion,
- openGames=[]
- json.data.forEach(function(table) {
- for(criterion in criteria) {
- if(criteria[criterion]!==table[criterion]) {
- return
- }
- }
- openGames.push(table)
- })
- if(openGames.length===0) {
- socket.log("No open games available!")
- }
- else {
- openGames.some(function(table) {
- return callback(table)
- })
- }
- })
- }
- //MiniLib
- Array.prototype.random=function() {
- return this[Math.floor(Math.random()*this.length)]
- }
- })
- //Jack-in
- setTimeout(function() {
- var script=document.createElement("script")
- script.type="text/javascript"
- script.textContent="("+EMjack+")()"
- document.body.appendChild(script)
- document.body.oncontextmenu=null
- })
Add Comment
Please, Sign In to add comment