T411 - Shoutbox notifications

Affiche une notification de bureau lors de la réception d'un message

Verze ze dne 05. 07. 2016. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         T411 - Shoutbox notifications
// @namespace    https://www.t411.ch
// @description  Affiche une notification de bureau lors de la réception d'un message
// @author       M1st3rN0b0d7
// @match      http://www.t411.ch/chati/*
// @match      https://www.t411.ch/chati/*
// @grant        none
// @version 0.0.1.20160705094355
// ==/UserScript==

var me = prompt("Veuillez entrer votre nom d'utilisateur T411.");

document.addEventListener('DOMContentLoaded', function () {
  if (Notification.permission !== "granted")
    Notification.requestPermission();
});

var me_2 = "@" + me + " : ";
var me_3 = "@" + me + " | ";
var me_4 = "@" + me + " ";

var msg_backup = "";

function loop() {

  var element = document.getElementsByClassName("message")[0];
  var user    = element.getElementsByTagName("strong")[0];
  var msg     = element.getElementsByTagName("p")[0];
  var msg2    = msg.innerText.replace(me_2, "");
  var msg3    = msg2.replace(me_3, "");
  var msg4    = msg3.replace(me_4, "");
  var test    = msg.innerText.search(me);

  if(test !== -1 && msg.innerText !== msg_backup) {

      msg_backup = msg.innerText;

      notifyMe();

  }

  console.log(user.innerText + msg.innerText);

  function notifyMe() {

    if (!Notification) {

      alert('Notifications de bureau non supportées.');
     return;

    }

    if (Notification.permission !== "granted")
      Notification.requestPermission();

    else {

      var notification = new Notification('Shoutbox T411', {

        icon: 'https://www.t411.ch/themes/blue/images/logo.png',
        body: "Message de " + user.innerText + "\n" + msg4,

     });

      var audio = new Audio("http://mobilering.net/ringtones/mp3/sound-effects/facebook_pop.mp3");
      audio.volume = 0.3;
      audio.play();
    
    }

  }
  
}

var loopFunction = window.setInterval(loop, 100);