T411 - Shoutbox notifications

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

  1. // ==UserScript==
  2. // @name T411 - Shoutbox notifications
  3. // @version 1.0
  4. // @namespace https://www.t411.li
  5. // @description Affiche une notification de bureau lors de la réception d'un message
  6. // @author M1st3rN0b0d7
  7. // @match http://www.t411.ch/chati/*
  8. // @match https://www.t411.ch/chati/*
  9. // @match http://www.t411.li/chati/*
  10. // @match https://www.t411.li/chati/*
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. var me = prompt("Veuillez entrer votre nom d'utilisateur T411.");
  15. // var me = "M1st3rN0b0d7";
  16.  
  17. document.addEventListener('DOMContentLoaded', function () {
  18. if (Notification.permission !== "granted")
  19. Notification.requestPermission();
  20. });
  21.  
  22. var me_2 = "@" + me + " : ";
  23. var me_3 = "@" + me + " | ";
  24. var me_4 = "@" + me + " ";
  25. var me_mp = "» " + me;
  26.  
  27. var msg_backup = "";
  28.  
  29. function loop() {
  30.  
  31. var element = document.getElementsByClassName("message")[0];
  32. var user = element.getElementsByTagName("strong")[0];
  33. var user_mp = element.getElementsByTagName("strong")[1];
  34. var msg = element.getElementsByTagName("p")[0];
  35. var msg2 = msg.innerText.replace(me_2, "");
  36. var msg3 = msg2.replace(me_3, "");
  37. var msg4 = msg3.replace(me_4, "");
  38. var test = msg.innerText.search(me);
  39.  
  40. if(user_mp !== undefined){
  41.  
  42. var test2 = user_mp.innerText.search(me_mp);
  43.  
  44. }
  45.  
  46. if(test !== -1 && msg.innerText !== msg_backup) {
  47.  
  48. msg_backup = msg.innerText;
  49.  
  50. notifyMe();
  51.  
  52. }
  53.  
  54. if(test2 !== -1 && test2 !== undefined && msg.innerText !== msg_backup) {
  55.  
  56. var user_mp2 = user.innerText.replace(me_mp, "");
  57.  
  58. msg_backup = msg.innerText;
  59.  
  60. notifyMe_mp();
  61.  
  62. }
  63.  
  64. function notifyMe() {
  65.  
  66. if (!Notification) {
  67.  
  68. alert('Notifications de bureau non supportées.');
  69. return;
  70.  
  71. }
  72.  
  73. if (Notification.permission !== "granted")
  74. Notification.requestPermission();
  75.  
  76. else {
  77.  
  78. var notification = new Notification('Shoutbox T411', {
  79.  
  80. icon: 'https://www.t411.ch/themes/blue/images/logo.png',
  81. body: "Message de " + user.innerText + "\n" + msg4,
  82.  
  83. });
  84.  
  85. var audio = new Audio("https://cdn.rawgit.com/M1st3rN0b0d7/t411-ShoutboxNotifications/master/facebook_pop.mp3");
  86. audio.volume = 0.3;
  87. audio.play();
  88.  
  89. }
  90.  
  91. }
  92.  
  93. function notifyMe_mp() {
  94.  
  95. if (!Notification) {
  96.  
  97. alert('Notifications de bureau non supportées.');
  98. return;
  99.  
  100. }
  101.  
  102. if (Notification.permission !== "granted")
  103. Notification.requestPermission();
  104.  
  105. else {
  106.  
  107. var notification = new Notification('Shoutbox T411', {
  108.  
  109. icon: 'https://www.t411.ch/themes/blue/images/logo.png',
  110. body: "Message privé de " + user_mp2 + "\n" + msg4,
  111.  
  112. });
  113.  
  114. var audio = new Audio("https://cdn.rawgit.com/M1st3rN0b0d7/t411-ShoutboxNotifications/master/facebook_pop.mp3");
  115. audio.volume = 0.3;
  116. audio.play();
  117.  
  118. }
  119.  
  120. }
  121.  
  122. }
  123.  
  124. var loopFunction = window.setInterval(loop, 100);