parloti / Add Sequence

// ==UserScript==
// @name         Add Sequence
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        *portal.pixelfederation.com/?a=profile/userProfile*
// @grant        none
// @run-at	   document-end
// ==/UserScript==
/* jshint -W097 */
'use strict';

var interval=(localStorage.interval||60*1000)/1;
console.log($("#friendsList .friend-minibox").size());
setTimeout(function(){location.reload()},1000*interval);

function a(i){
	localStorage.i=i;
    localStorage.interval=interval;
    var c=new Date().getTime();
    var xhr=new XMLHttpRequest();
	xhr.open("POST","http://portal.pixelfederation.com/?a=friends/addFriend&lang=",true);
    xhr.responseType="json";
	xhr.onload=function(b){
		console.log(b.currentTarget.response);
        if(!b.currentTarget.response){
             let j=i;
             console.log({id:j,Intervalo:interval,duração:new Date().getTime()-d});
             setTimeout(a,interval,j);
        }
        if(b.currentTarget.response.success){
            interval--;
        }
        else if(b.currentTarget.response.msg!=="This friendship already exists (or waiting for approval)."){
            console.log(b.currentTarget.response.msg);
            interval=interval+100;
            console.log($("#friendsList .friend-minibox").size());
        }
		{
			let d=c;
			if(i<10000){
                let j=++i;
                console.log({id:j,Intervalo:interval,duração:new Date().getTime()-d});
                setTimeout(a,interval,j);
            }
            else if(i==10000){
                let j=7000000;
                console.log({id:j,Intervalo:interval,duração:new Date().getTime()-d});
                //localStorage.i=7000000;
                setTimeout(a,interval,j);
            }
            else{
                let j=--i;
                console.log({id:j,Intervalo:interval,duração:new Date().getTime()-d});
                setTimeout(a,interval,j);
            }
		}
	}
    xhr.ontimeout=function(b){
        console.log(b);
        a(localStorage.i);
    }
    xhr.onerror=function(b,c,d,e,f,g){
        console.log(b,c,d,e,f,g);
        a(localStorage.i);
    }
	xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xhr.send("user_id="+i+"&id_type=id");
}
a(localStorage.i||0);