Greasy Fork is available in English.

DC_notify

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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;
                }
            }
        }
    });


})();