DC_notify

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

  1. // ==UserScript==
  2. // @name DC_notify
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.4
  5. // @description Utilisation des notifications navigateur pour la réception d'un message sur Dreadcast.
  6. // @author Damasio
  7. // @match https://www.dreadcast.net/Main
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. var $msg_new,$msg_imgurl,$msg_title,$msg_author, $msg_id, $msg_inner,msg_object, response_xml, $response, $check_event;
  15. var msg_ids = [];
  16. var pending = false;
  17.  
  18. if (!("Notification" in window)) {
  19. console.log('[DC_notify] Ce navigateur ne supporte pas les notifications');
  20. }
  21. else if (Notification.permission === "granted") {
  22. console.log('[DC_notify] Notifications acceptées');
  23. }
  24. else if (Notification.permission !== 'denied') {
  25. Notification.requestPermission(function (permission) {
  26. if(!('permission' in Notification)) {
  27. Notification.permission = permission;
  28. console.log('[DC_notify] Notifications refusées');
  29. }
  30.  
  31. if (permission === "granted") {
  32. console.log('[DC_notify] Notifications acceptées');
  33. }
  34. });
  35. }
  36.  
  37. $(document).ajaxComplete(function (event, xhr, settings) {
  38.  
  39. if(settings.url.endsWith("OpenFolder")){
  40. console.log(msg_ids);
  41. if(pending){
  42. $msg_new = $('.message.new');
  43. for(let i=0;i<$msg_new.length;i++){
  44. $msg_author = $($msg_new[i]).find('.message_auteur').text();
  45. $msg_imgurl = $($msg_new[i]).find('img').prop('src');
  46. $msg_title = $($msg_new[i]).find('.message_titre').text();
  47. if($msg_title.trim()===''){
  48. msg_object = '';
  49. }else{
  50. msg_object = '\nObjet : '+$msg_title;
  51. }
  52. new Notification("Nouveau message de "+$msg_author, {icon:$msg_imgurl, body:msg_object,lang: 'fr-FR',dir: 'ltr'});
  53. }
  54. pending = false;
  55. }
  56. }
  57.  
  58. if (settings.url.endsWith("Check")) {
  59. response_xml = $.parseXML( xhr.responseText );
  60. $response = $( response_xml );
  61. $check_event = $response.find( "evenement" );
  62. if($check_event.length>0){
  63. $msg_inner = $check_event[0].innerHTML;
  64. $msg_id = /id_conversation="(.*)"/g.exec($msg_inner);
  65. console.log($msg_id);
  66. if($msg_id.length>1){
  67. pending = true;
  68. }
  69. }
  70. }
  71. });
  72.  
  73.  
  74. })();