T411 - Shoutbox notifications

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

当前为 2016-07-05 提交的版本,查看 最新版本

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