T411 - Shoutbox notifications

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

  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, Micdu70
  6. // @match http://www.t411.al/chati/*
  7. // @match https://www.t411.al/chati/*
  8. // @grant none
  9. // @version 1.3.1
  10. // ==/UserScript==
  11. function INIT()
  12. {
  13. var url = document.location.protocol + '//www.t411.al/users/profile/';
  14. var http = new XMLHttpRequest();
  15. http.open("GET", url, true);
  16. http.timeout = 15000;
  17. http.ontimeout = function(e)
  18. {
  19. alert('Script Shoutbox notifications : Impossible d\'obtenir votre pseudo, site instable ? Actualisez la page...');
  20. };
  21. http.onreadystatechange = function()
  22. {
  23. if (http.readyState == 4 && http.status == 200)
  24. {
  25. getYourUsername(http.response);
  26. }
  27. };
  28. http.send(null);
  29. }
  30. function getYourUsername(x)
  31. {
  32. var tempDiv = document.createElement('div');
  33. tempDiv.innerHTML = x.replace(/<script(.|\s)*?\/script>/g, '');
  34. var title = tempDiv.getElementsByTagName('title')[0].innerHTML;
  35. if (title.indexOf('Membre') != -1)
  36. {
  37. var yourusername = title.split(' ')[3];
  38. Check(yourusername);
  39. }
  40. else
  41. {
  42. alert('Script Shoutbox notifications : Impossible d\'obtenir votre pseudo, site instable ? Actualisez la page...');
  43. }
  44. }
  45. function Check(me)
  46. {
  47. var me_test = me.toLowerCase();
  48. document.getElementById('messages').addEventListener('DOMNodeInserted', function (event)
  49. {
  50. if (event.target.parentNode.id == 'messages')
  51. {
  52. var element = document.getElementsByClassName(event.target.className)[0];
  53. var user = element.getElementsByTagName("strong")[0];
  54. var user1 = user.innerText.split(' ')[0];
  55. if (user1 !== me)
  56. {
  57. var msg = element.getElementsByTagName("p")[0];
  58. var msg1 = msg.innerHTML.replace(/<a.*?>(.*?)<\/a>/g, "$1").replace(/<img.*?alt="(.*?)">/g, "$1").replace(/((<.*?>)+)(.*?)((<\/.*?>)+)/g, "$3").replace(/&lt;/g, '<').replace(/&gt;/g, '>');
  59. var pv = element.className.split(' ')[1];
  60. if (pv !== "private")
  61. {
  62. var test = msg.innerText.toLowerCase().indexOf(me_test);
  63. if (test != -1)
  64. {
  65. notifyMe(true, user1, msg1);
  66. }
  67. }
  68. else
  69. {
  70. notifyMe("pv", user1, msg1);
  71. }
  72. }
  73. }
  74. });
  75. }
  76. function notifyMe(x, user, msg)
  77. {
  78. if (x === undefined)
  79. {
  80. if (!Notification)
  81. {
  82. alert('Notifications de bureau non supportées.');
  83. }
  84. else if (Notification.permission === "denied")
  85. {
  86. alert('Notifications de bureau sont bloquées. ( Bruit sonore uniquement )');
  87. }
  88. else if (Notification.permission !== "granted")
  89. {
  90. Notification.requestPermission();
  91. }
  92. }
  93. else
  94. {
  95. var notification = "";
  96. if (x !== "pv")
  97. {
  98. notification = new Notification('Shoutbox T411',
  99. {
  100. icon: 'https://www.t411.al/themes/blue/images/logo.png',
  101. body: user + " vous a cité :\n" + msg
  102. });
  103. }
  104. else
  105. {
  106. notification = new Notification('Shoutbox T411',
  107. {
  108. icon: 'https://www.t411.al/themes/blue/images/logo.png',
  109. body: user + " vous a MP :\n" + msg
  110. });
  111. }
  112. var audio = new Audio("https://cdn.rawgit.com/M1st3rN0b0d7/t411-ShoutboxNotifications/master/facebook_pop.mp3");
  113. audio.volume = 0.3;
  114. audio.play();
  115. }
  116. }
  117. INIT();
  118. notifyMe();