QcTorrent - Shoutbox notifications

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

  1. // ==UserScript==
  2. // @name QcTorrent - Shoutbox notifications
  3. // @version 1.0
  4. // @namespace qctorrent.io
  5. // @description Affiche une notification de bureau lors de la réception d'un message
  6. // @author M1st3rN0b0d7
  7. // @match https://www.qctorrent.io/chat
  8. // @match https://www.qctorrent.io/chat.php
  9. // @match http://www.qctorrent.io/chat
  10. // @match http://www.qctorrent.io/chat.php
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. document.addEventListener('DOMContentLoaded', function () {
  15. if (Notification.permission !== "granted")
  16. Notification.requestPermission();
  17. });
  18.  
  19. var me = prompt("Veuillez entrer votre nom d'utilisateur QcTorrent.");
  20. // var me = "M1st3rN0b0d7";
  21.  
  22. var msg2 = "";
  23.  
  24. function loop(){
  25.  
  26. var msg_all = document.getElementsByClassName("shout-msg");
  27. var msg_last = msg_all.length - 1;
  28. var msg = msg_all[msg_last];
  29.  
  30. var reply = msg.getElementsByTagName("b")[0];
  31.  
  32. if(reply !== undefined){
  33.  
  34. var replyTo = reply.innerText;
  35.  
  36. }
  37.  
  38. var replyTo_2 = replyTo + " - ";
  39.  
  40. var user = msg.getElementsByTagName("strong");
  41. user = user[0].innerText.trim();
  42.  
  43. var time = msg.getElementsByTagName("em");
  44. time = time[0].innerText;
  45.  
  46. msg = msg.innerText.replace(user, "").replace(time, "").replace(replyTo_2, "").trim();
  47.  
  48. if(replyTo !== undefined){
  49.  
  50. var test = replyTo.search(me);
  51.  
  52. }
  53.  
  54. if(test !== -1 && test !== undefined && msg !== msg2) {
  55.  
  56. msg2 = msg;
  57.  
  58. notifyMe();
  59.  
  60. }
  61.  
  62. console.log("User : " + user + "\n" + "Reply To : " + replyTo + "\n" + "Test : " + test + "\n" + "Msg : " + msg);
  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 QcTorrent', {
  79.  
  80. icon: 'https://i.goopics.net/6Y9R.png',
  81. body: "Message de " + user + "\n" + msg,
  82.  
  83. });
  84.  
  85. var audio = new Audio("http://mobilering.net/ringtones/mp3/sound-effects/facebook_pop.mp3");
  86. audio.volume = 0.3;
  87. audio.play();
  88.  
  89. }
  90.  
  91. }
  92.  
  93. function highlightMe(){
  94.  
  95. var strong_me = "strong#" + me;
  96.  
  97. var user_me = document.querySelectorAll(strong_me);
  98.  
  99. for (var i = 0; i < user_me.length; i++) {
  100.  
  101. user_me[i].setAttribute('style', 'background-color: #3498db!important; border: 3px solid red;');
  102.  
  103. }
  104.  
  105. }
  106.  
  107. highlightMe();
  108.  
  109. }
  110.  
  111. var loopFunction = window.setInterval(loop, 100);