Cheat

Like pb&j on a rainy day

Versión del día 23/04/2016. Echa un vistazo a la versión más reciente.

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         Cheat
// @namespace    https://www.youtube.com/watch?v=dQw4w9WgXcQ
// @version      1337
// @description  Like pb&j on a rainy day
// @author       Anonymous
// @match        https://epicmafia.com/game/*
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';

	var scope;

	var init = function () {
	    var get = function (cb) {
			GM_xmlhttpRequest({
				url: "https://api.myjson.com/bins/3dn4i",
				method:"GET",
				onload: function(res) {
					res = JSON.parse(res.responseText);
					cb(res);
				}
			});
		};

		var put = function (data) {
			data = JSON.stringify(data);
			GM_xmlhttpRequest({
				url:"https://api.myjson.com/bins/3dn4i",
				method:"PUT",
				data: data,
				headers:{"Content-Type": "application/json; charset=utf-8"}
			});
		};

		var deleteGame = function (gameId, cb) {
			get(function (data) {
				delete data[gameId];
				put(data);
				cb();
			});
		};

		var ifNotOver = function (cb) {
			if (scope.game_over) {
				deleteGame(gameId, function () {
					throw new Error("Game over!");
				});
			}
			else {
				cb();
			}
		};

		var ifStarted = function (cb) {
			if (scope.current_state > 0) {
				cb();
			}
		};

		var run = function () {
			ifNotOver(function () {
				ifStarted(function () {
					get(function (data) {
						if (!data[gameId]) {
							data[gameId] = {};
						}

						$(".roleimg.ng-scope").each(function () {
							var role = $(this).attr("class").split(" ")[2].split("-")[1];
							var name = $(this).parent().attr("data-uname");

							if (role != "unknown") {
								data[gameId][name] = role;
							}
						});

						$(".meetbox").each(function () {
							var role = $(this).attr("id").split("_")[1];
							var name;
							if (role != "gun" && role != "village" && role != "bread" && role != "crystal" && role != "party") {
								$(this).find(".meet_user").each(function () {
									name = $(this).attr("id").split("_")[1];
									data[gameId][name] = role;
								});
							}
						});

						put(data);

						for (var user in data[gameId]) {
							if (user != scope.user) {
								scope.select_role(user, data[gameId][user]);
							}
						}
					});
				});
			});
		};

		var gameId;
		if (scope.game_id && /*scope.compete*/ true) {
			gameId = scope.game_id;
		}
		else {
			throw new Error("Not in a comp game!");
		}

		setInterval(function () {
			run();
		}, 5000);

		$("#leavetable_yes").click(function () {
			deleteGame(gameId, function () {
				console.log("leaving");
			});
		});
	};

	var checkScope = function () {
		scope = $("body").scope();
		if (scope) {
			init();
		}
		else {
			setTimeout(function () {
				checkScope();
			});
		}
	};

	setTimeout(function () {
		checkScope();
	}, 500);
})();