T411 - Shoutbox notifications

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

Από την 06/07/2016. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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, Micdu70
// @match        http://www.t411.ch/chati/*
// @match        https://www.t411.ch/chati/*
// @grant        none
// @version      1.0.1
// ==/UserScript==
function INIT()
{
    var url = document.location.protocol + '//www.t411.ch/users/profile/';
    var http = new XMLHttpRequest();
    http.open("GET", url, true);
    http.timeout = 15000;
    http.ontimeout = function(e)
    {
        alert('Script Shoutbox notifications : Impossible d\'obtenir votre pseudo, site instable ? Actualisez la page...');
    };
    http.onreadystatechange = function()
    {
        if (http.readyState == 4 && http.status == 200)
        {
            getYourUsername(http.response);
        }
    };
    http.send(null);
}
function getYourUsername(x)
{
    var tempDiv = document.createElement('div');
    tempDiv.innerHTML = x.replace(/<script(.|\s)*?\/script>/g, '');
    var title = tempDiv.getElementsByTagName('title')[0].innerHTML;
    if (title.indexOf('Membre') != -1)
    {
        var yourusername = title.slice(19).slice(0, title.indexOf(' '));
        Check(yourusername);
    }
    else
    {
        alert('Script Shoutbox notifications : Impossible d\'obtenir votre pseudo, site instable ? Actualisez la page...');
    }
}
function Check(me)
{
    var me_test = me.toLowerCase();
    document.getElementById('messages').addEventListener('DOMNodeInserted', function (event)
                                                         {
        if (event.target.parentNode.id == 'messages')
        {
            var element = document.getElementsByClassName("message")[0];
            var user = element.getElementsByTagName("strong")[0];
            var user_pv = element.getElementsByTagName("strong")[1];
            var msg = element.getElementsByTagName("p")[0];
            var msg1 = "";
            if (user.innerText !== me)
            {
                if (user_pv !== undefined)
                {
                    msg1 = msg.innerHTML.replace(/<a.*?>(.*?)<\/a>/g, "$1").replace(/<img.*?alt="\\(.*?)">/g, "$1").replace(/((<.*?>)+).*?((<\/.*?>)+)/g, "");
                    notifyMe("pv", user.innerText, msg1);
                }
                else
                {
                    var test = msg.innerText.toLowerCase().indexOf(me_test);
                    if (test !== -1)
                    {
                        msg1 = msg.innerHTML.replace(/<a.*?>(.*?)<\/a>/g, "$1").replace(/<img.*?alt="(.*?)">/g, "$1").replace(/((<.*?>)+).*?((<\/.*?>)+)/g, "");
                        notifyMe(true, user.innerText, msg1);
                    }
                }
            }
        }
    });
}
function notifyMe(x, user, msg)
{
    if (x === undefined)
    {
        if (!Notification)
        {
            alert('Notifications de bureau non supportées.');
            return;
        }
        if (Notification.permission === "denied")
        {
            alert('Notifications de bureau sont bloquées.');
            return;
        }
        if (Notification.permission !== "granted")
        {
            Notification.requestPermission();
        }
    }
    else
    {
        var notification = "";
        if (x !== "pv")
        {
            notification = new Notification('Shoutbox T411',
                                            {
                icon: 'https://www.t411.ch/themes/blue/images/logo.png',
                body: user + " vous a cité :\n" + msg
            });
        } else {
            notification = new Notification('Shoutbox T411',
                                            {
                icon: 'https://www.t411.ch/themes/blue/images/logo.png',
                body: user + " vous a MP :\n" + msg
            });
        }
        var audio = new Audio("http://mobilering.net/ringtones/mp3/sound-effects/facebook_pop.mp3");
        audio.volume = 0.3;
        audio.play();
    }
}
INIT();
notifyMe();