T411 - Shoutbox notifications

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

当前为 2016-11-02 提交的版本,查看 最新版本

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