tsvetant / MyELO Scrapper

// ==UserScript==
// @name         MyELO Scrapper
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  League scrapper
// @author       You
// @include        *://matchhistory.*.leagueoflegends.com/*
// @grant        none
// @noframes
// ==/UserScript==

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') 
            c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) === 0) 
            return c.substring(nameEQ.length, c.length);
    }
    return null;
}

(function() {
    'use strict';

    //--- Loop through cookies and delete them.
    var cookieList  = document.cookie.split (/;\s*/),
        regex_TOKEN = /(PVPNET_TOKEN_)(\w{1,4})/,
        match = '', cookie = '', Region = '', Authorization = '', ID = '';

    for (var J = cookieList.length - 1;   J >= 0;  --J) {
        var cookieName = cookieList[J].replace (/\s*(\w+)=.+$/, "$1");
        if(regex_TOKEN.test(cookieName)) {
            match = cookieName.match(regex_TOKEN);
            cookie = readCookie(cookieName);
            Region = match[2];
            Authorization = "Vapor " + cookie;
            ID = readCookie('PVPNET_ID_' + Region);
        }
    }

    var begIndex = 0;
    var endIndex = 20; // Max 20
    var opts = {
        method: 'GET',
        headers: {
            'Region': Region,
            'Authorization': Authorization,
        }
    };
    fetch('https://acs.leagueoflegends.com/v1/stats/player_history/' + Region + '1/' + ID + '?begIndex=' + begIndex + '&endIndex=' + endIndex, opts).then(function (response) {
        return response.json();
    }).then(function (body) {
        var div = document.createElement("div");
        div.style.padding = "5px 20px";
        div.style.background = "#e9eaec";
        div.style.position = "absolute";
        div.style.margin = "45px 0 0 25px";
        div.innerHTML = "<strong>Games</strong>: " + body.games.gameCount;
        div.style.boxShadow = "rgba(0, 0, 0, 0.498039) 0px -10px 15px 0px";
        div.style.zIndex  = 999;
        document.getElementById("breadcrumbs").appendChild(div);
    });
})();