Saucsse / Respawn Nickname seeker

// ==UserScript==
// @name         Respawn Nickname seeker
// @license MIT
// @namespace    http://www.jeuxvideo.com/
// @version      3.2
// @description  Mise à jour avec HTTPS
// @author       Craftbukkit
// @match        https://www.jeuxvideo.com/*
// @require      https://code.jquery.com/jquery-1.11.3.min.js
// @grant      GM_setValue
// @grant      GM_getValue
// @grant      GM_notification
// ==/UserScript==

(function () {
  'use strict';
  var pseudoJVC;
  var dateT = new Date();
  var rTime = dateT.getTime();
  var iAmTheMaster = false;
  var idMaster = Math.random();

  var parseSubject = function (data) {
    if (iAmTheMaster) {
      var nbLength = data.split('<span class="topic-subject">').length;

      if (nbLength >= 3) {

        for (var i = 2; i < nbLength; i++) {
          var urlData = data.split('<span class="topic-subject">')[i].split('href="')[1].split('"')[0];
          var tkDate = data.split('<span class="topic-date">')[i].split('</span>')[0].trim();
          if (tkDate.indexOf("JvCare") != "-1" && tkDate.indexOf(":") != "-1") {
            var pseudo = data.split('<span class="topic-subject">')[i].split('" target="_blank">')[1].split('</span>')[0].trim();
            var stDate = tkDate.split('>')[1].trim();
            var rlDate = new Date(new Date().getFullYear() + "-" + ((new Date().getMonth() + 1 <= 9) ? "0" : "") + (new Date().getMonth() + 1) + "-" + ((new Date().getDate() <= 9) ? "0" : "") + (new Date().getDate()) + ":" + stDate).getTime();
            if (rTime <= rlDate) {
              rTime = Number(rlDate) + 1;
              GM_setValue("masterrtimee", rTime);
              var url = urlData;
              // Notif pour HTTPS
              var notif = new Notification(pseudo + " vous a mentionné dans un topic", {
                body: 'Cliquez-ici pour accéder au topic',
                icon: 'https://www.jeuxvideo.com/img/forums/topic-dossier1.png'
              });
              notif.url = urlData;
              notif.onclick = function () {
                window.open("https://www.jeuxvideo.com/" + this.url);
              };
              // GM_notification("Cliquez-ici pour accéder au topic", pseudo+" vous a mentionné dans un topic", "http://www.jeuxvideo.com/img/forums/topic-dossier1.png", function() { window.open("http://www.jeuxvideo.com/"+url);});

            }
          }
        }
      }
    }
  };

  (function checkIfMaster() {
    var date = new Date();
    var timestamp = date.getTime();
    if (GM_getValue("masterr") == undefined) {
      GM_setValue("masterrtimee", rTime);
      GM_setValue("masterr", idMaster);
      GM_setValue("masterrtime", timestamp);
      iAmTheMaster = true;
    }
    else if (GM_getValue("masterr") == idMaster) {
      GM_setValue("masterrtimee", rTime);
      iAmTheMaster = true;
      GM_setValue("masterrtime", timestamp);
    }
    else {
      if (Math.floor((timestamp - GM_getValue("masterrtime")) / 1000) >= 7) {
        iAmTheMaster = true;
        GM_setValue("masterr", idMaster);
        GM_setValue("masterrtime", timestamp);
      }
      else {
        iAmTheMaster = false;
        rTime = GM_getValue("masterrtimee");
      }
    }
    setTimeout(checkIfMaster, 5000);
  })();

  // Cimer Mozilla pour la doc sur les notif
  (function askPourLaNotif() {
    if (Notification.permission !== 'denied') {
      Notification.requestPermission(function (permission) {
        if (!('permission' in Notification)) {
          Notification.permission = permission;
        }
      });
    }
  })();

  (function getPseudo() {
    pseudoJVC = document.getElementsByClassName("account-pseudo")[0].innerHTML;
  })();

  (function checkIfNotif() {
    if (pseudoJVC != undefined && iAmTheMaster) {
      $.get("https://www.jeuxvideo.com/recherche/forums/0-51-0-1-0-1-0-blabla-18-25-ans.htm?type_search_in_forum=texte_message&search_in_forum=" + pseudoJVC, function (data) {
        parseSubject(data);
        setTimeout(checkIfNotif, 40000);
      });
    }
    else {
      setTimeout(checkIfNotif, 5000);
    }
  })();

})();