DC_notify

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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

(function() {
    'use strict';

    var $msg_new,$msg_imgurl,$msg_title,$msg_author, $msg_id, $msg_inner,msg_object, 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")){
            console.log(msg_ids);
            if(pending){
                $msg_new = $('.message.new');
                for(let i=0;i<$msg_new.length;i++){
                    $msg_author = $($msg_new[i]).find('.message_auteur').text();
                    $msg_imgurl = $($msg_new[i]).find('img').prop('src');
                    $msg_title = $($msg_new[i]).find('.message_titre').text();
                    if($msg_title.trim()===''){
                        msg_object = '';
                    }else{
                        msg_object = '\nObjet : '+$msg_title;
                    }
                    new Notification("Nouveau message de "+$msg_author, {icon:$msg_imgurl, body:msg_object,lang: 'fr-FR',dir: 'ltr'});
                }
                pending = false;
            }
        }

        if (settings.url.endsWith("Check")) {
            response_xml = $.parseXML( xhr.responseText );
            $response = $( response_xml );
            $check_event = $response.find( "evenement" );
            if($check_event.length>0){
                $msg_inner = $check_event[0].innerHTML;
                $msg_id = /id_conversation="(.*)"/g.exec($msg_inner);
                console.log($msg_id);
                if($msg_id.length>1){
                    pending = true;
                }
            }
        }
    });


})();