Greasy Fork 还支持 简体中文。

T411 - Shoutbox notifications

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

目前為 2016-07-06 提交的版本,檢視 最新版本

  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.ch/chati/*
  7. // @match https://www.t411.ch/chati/*
  8. // @grant none
  9. // @version 1.0.2
  10. // ==/UserScript==
  11. function INIT()
  12. {
  13. var url = document.location.protocol + '//www.t411.ch/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.slice(19).slice(0, title.indexOf(' '));
  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("message")[0];
  53. var user = element.getElementsByTagName("strong")[0];
  54. var user_pv = element.getElementsByTagName("strong")[1];
  55. var msg = element.getElementsByTagName("p")[0];
  56. var msg1 = "";
  57. if (user.innerText.split(' ')[0] !== me)
  58. {
  59. if (user_pv !== undefined)
  60. {
  61. msg1 = msg.innerHTML.replace(/<a.*?>(.*?)<\/a>/g, "$1").replace(/<img.*?alt="(.*?)">/g, "$1").replace(/((<.*?>)+).*?((<\/.*?>)+)/g, "");
  62. notifyMe("pv", user.innerText, msg1);
  63. }
  64. else
  65. {
  66. var test = msg.innerText.toLowerCase().indexOf(me_test);
  67. if (test !== -1)
  68. {
  69. msg1 = msg.innerHTML.replace(/<a.*?>(.*?)<\/a>/g, "$1").replace(/<img.*?alt="(.*?)">/g, "$1").replace(/((<.*?>)+).*?((<\/.*?>)+)/g, "");
  70. notifyMe(true, user.innerText, msg1);
  71. }
  72. }
  73. }
  74. }
  75. });
  76. }
  77. function notifyMe(x, user, msg)
  78. {
  79. if (x === undefined)
  80. {
  81. if (!Notification)
  82. {
  83. alert('Notifications de bureau non supportées.');
  84. return;
  85. }
  86. if (Notification.permission === "denied")
  87. {
  88. alert('Notifications de bureau sont bloquées.');
  89. return;
  90. }
  91. if (Notification.permission !== "granted")
  92. {
  93. Notification.requestPermission();
  94. }
  95. }
  96. else
  97. {
  98. var notification = "";
  99. if (x !== "pv")
  100. {
  101. notification = new Notification('Shoutbox T411',
  102. {
  103. icon: 'https://www.t411.ch/themes/blue/images/logo.png',
  104. body: user + " vous a cité :\n" + msg
  105. });
  106. } else {
  107. notification = new Notification('Shoutbox T411',
  108. {
  109. icon: 'https://www.t411.ch/themes/blue/images/logo.png',
  110. body: user + " vous a MP :\n" + msg
  111. });
  112. }
  113. var audio = new Audio("http://mobilering.net/ringtones/mp3/sound-effects/facebook_pop.mp3");
  114. audio.volume = 0.3;
  115. audio.play();
  116. }
  117. }
  118. INIT();
  119. notifyMe();