DC_notify

Utilisation des notifications navigateur pour la réception d'un message sur Dreadcast.

目前为 2017-09-27 提交的版本。查看 最新版本

// ==UserScript==
// @name         DC_notify
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  Utilisation des notifications navigateur pour la réception d'un message sur Dreadcast.
// @author       John Doe
// @match        https://www.dreadcast.net/Main
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var $msg_new,$msg_imgurl,$msg_title,$msg_author, response_xml, $response, $check_event;
    var msg_ids = [];
    var pending = false;

    if (!("Notification" in window)) {
        console.log('[DC_notify] Ce navigateur ne supporte pas les notifications');
    }
    else if (Notification.permission === "granted") {
        console.log('[DC_notify] Notifications acceptées');
    }
    else if (Notification.permission !== 'denied') {
        Notification.requestPermission(function (permission) {
            if(!('permission' in Notification)) {
                Notification.permission = permission;
                console.log('[DC_notify] Notifications refusées');
            }

            if (permission === "granted") {
                console.log('[DC_notify] Notifications acceptées');
            }
        });
    }

    $(document).ajaxComplete(function (event, xhr, settings) {

        if(settings.url.endsWith("OpenFolder")){
            if(pending){
                $msg_new = $('.message.new');
                for(let i=0;i<$msg_new.length;i++){
                    $msg_imgurl = $($msg_new[i]).find('img').prop('src');
                    $msg_title = $($msg_new[i]).find('.message_titre').text();
                    $msg_author = $($msg_new[i]).find('.message_auteur').text();
                    new Notification("Nouveau message de "+$msg_author, {icon:$msg_imgurl, body:'\nObjet : '+$msg_title,lang: 'fr-FR',dir: 'ltr'});
                }
                pending = false;
            }else{
                msg_ids = [];
            }
        }

        if (settings.url.endsWith("Check")) {
            response_xml = $.parseXML( xhr.responseText );
            $response = $( response_xml );
            $check_event = $response.find( "evenement" );
            if($check_event.length>0){
                if($check_event[0].innerHTML.indexOf('id_conversation')!==-1){
                    pending = true;
                }
            }
        }
    });


})();