sxn91401 / vote

// ==UserScript==
// @name         vote
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  try to take over the world!
// @author       You
// @match        http://rcshow.tv/appNew/event/faceScore/pk.php*
// @grant        none
// ==/UserScript==

var check_token;
var target = "8161070";
var checkCounter = 0;
var checkLimit = 30;

function vote(candidate)
{
	var allow = true;
	if(allow === true)
	{
		$(".pkUser")[parseInt(candidate)].children[1].click();
	}
	return;
}

function judge()
{

	var candidate1 = $(".pkUser")[0].children[1].getAttribute("data-id");
	var candidate2 = $(".pkUser")[1].children[1].getAttribute("data-id");

	if(candidate1 === target)
	{
		vote("0");
		setTimeout(function(){location.reload();}, 10000);
	}
	else if(candidate2 === target)
	{
		vote("1");
		setTimeout(function(){location.reload();}, 10000);
	}
	else
	{
		//var next = confirm("candidate1: " + candidate1 + " candidate2: " + candidate2 + " target: " + target);
		var next = true;
		if(next === true)
		{
			location.reload();
		}
	}
	
	return;
}

function loading()
{
	console.log("load");
	checkCounter = checkCounter + 1;
	
	if(checkCounter >= checkLimit)
	{
	    location.reload();
	}
	else if($(".pkUser").length === 2)
	{
		clearInterval(check_token);
		judge();
	}
	return;
}

 check_token = setInterval( loading, 1000);