dhaBeverage / getNumberOfConnectedKhey

// ==UserScript==
// @name         getNumberOfConnectedKhey
// @version      0.1
// @description  Rajoute une colonne avec le nombre de connectés par topic dans la page principale
// @author       DhaBeverage
// @icon         http://www.stickaz.com/1142-1788-large/hap.png
// @match        *://www.jeuxvideo.com/forums/0-5*
// @match        *://www.jeuxvideo.com/recherche/forums/*
// @match        *://www.jeuxvideo.com/forums/0-1000034-0-1-0-1-0-japon.htm
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var linksTab = [];
    var entete = document.getElementsByClassName("topic-date")[0];
    entete.innerHTML = "CONNECTÉ(S)";

    for (var i = 1; i < 26; i++) {
        var sujetLiens = document.getElementById("forum-main-col").childNodes[5].getElementsByClassName("topic-list")[0].getElementsByClassName("topic-subject")[i].getElementsByClassName("topic-title")[0].href;
        //console.log("listeLiens : " +sujetLiens);
        linksTab.push(sujetLiens);
    }


    function makeHttpObject() {
        try {
            return new XMLHttpRequest();
        } catch (error) {}
        try {
            return new ActiveXObject("Msxml2.XMLHTTP");
        } catch (error) {}
        try {
            return new ActiveXObject("Microsoft.XMLHTTP");
        } catch (error) {}

        throw new Error("Could not create HTTP request object.");
    }

    var getSourceCode = function(myUrl) {
        var request = makeHttpObject();
        var response = "";
        request.open("GET", myUrl, true);
        request.send(null);
        request.onreadystatechange = function() {
            if (request.readyState == 4) {
                response = String(request.responseText);
                var resRegEx = String(response.match(/\S+\s+connecté/));
                var resConnected = "<b>"+resRegEx.substring(24, resRegEx.indexOf(' '))+"</b>";
                var index = linksTab.indexOf(myUrl);
                //console.log("myUrl :" + myUrl);
                //console.log("index :" + index);
                //console.log("resConnected : " + resConnected);
                resConnected+=" Connecté(s)";
                document.getElementsByClassName("topic-date")[index + 1].innerHTML = resConnected;

                return response;
            }
        };
    };

    for (var i = 0; i < linksTab.length; i++) {
        getSourceCode(linksTab[i]);
    }

})();