parloti / plus500

// ==UserScript==
// @name         plus500
// @version      0.1
// @match        https://app.plus500.com/*
// @grant        none
// @run-at	     document-start
// ==/UserScript==

window.stop();
var stopped=false;
var starting=setInterval(Start,100);

function Start(){
    var xhr=new XMLHttpRequest();
    xhr.open("GET","https://trade/CORS.php?action=start",true);
    xhr.onerror=function(a){
        clearInterval(starting);
        if(!stopped){
            if(a.currentTarget.status===0&&a.currentTarget.readyState===4){
                window.open("https://trade/","_blank");  
                stopped=true;
                alert("Autorize na aba aberta, depois atualize a página.");
            }
            else{
                console.log(a.currentTarget.status,a.currentTarget.readyState);
            }
        }
    };
    xhr.onload=function(a){
        clearInterval(starting);
        if(!stopped){
            eval(a.currentTarget.response);
        }
        stopped=true;
    };
    xhr.send();
}