T411 - Shoutbox notifications

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

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

  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.20160703235317
  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.  
  22. var msg_backup = "";
  23.  
  24. function loop() {
  25.  
  26. var element = document.getElementsByClassName("message")[0];
  27. var user = element.getElementsByTagName("strong")[0];
  28. var msg = element.getElementsByTagName("p")[0];
  29. var msg2 = msg.innerText.replace(me_2, "");
  30. var msg3 = msg2.replace(me_3, "");
  31. var test = msg.innerText.search(me);
  32.  
  33. if(test !== -1 && msg.innerText !== msg_backup) {
  34.  
  35. msg_backup = msg.innerText;
  36.  
  37. notifyMe();
  38.  
  39. }
  40.  
  41. console.log(user.innerText + msg.innerText);
  42.  
  43. function notifyMe() {
  44.  
  45. if (!Notification) {
  46.  
  47. alert('Notifications de bureau non supportées.');
  48. return;
  49.  
  50. }
  51.  
  52. if (Notification.permission !== "granted")
  53. Notification.requestPermission();
  54.  
  55. else {
  56.  
  57. var notification = new Notification('Shoutbox T411', {
  58.  
  59. icon: 'https://www.t411.ch/themes/blue/images/logo.png',
  60. body: "Message de " + user.innerText + "\n" + msg3,
  61.  
  62. });
  63. }
  64.  
  65. }
  66. }
  67.  
  68. var loopFunction = window.setInterval(loop, 100);