🏠 Home 

Greasy Fork is available in English.

cometeo桌面通知

try to take over the world!


安装此脚本?
  1. // ==UserScript==
  2. // @name cometeo桌面通知
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description try to take over the world!
  6. // @author colodes
  7. // @match http://www.cometeo.com/room/*
  8. // @grant none
  9. // ==/UserScript==
  10. window.addEventListener('load', function () {
  11. Notification.requestPermission(function (status) {
  12. if (Notification.permission !== status) {
  13. Notification.permission = status;
  14. }
  15. });
  16. });
  17. let elementToObserve = document.querySelector('#comments');
  18. let observer = new MutationObserver(function (mutations) {
  19. mutations.forEach(function (e) {
  20. let addedChats = e.addedNodes;
  21. var options = {
  22. silent: true
  23. }
  24. var n = new Notification(addedChats[0].innerText,options);
  25. n.onclick = function () {
  26. try {
  27. window.focus();
  28. }
  29. catch (ex) { };
  30. };
  31. });
  32. });
  33. const config = {
  34. // attributes: true,
  35. childList: true,
  36. // characterData: true,
  37. // subtree: true
  38. }
  39. function background() {
  40. observer.observe(elementToObserve, config);
  41. }
  42. function handleVisibilityChange() {
  43. if (document.hidden) {
  44. background();
  45. } else {
  46. observer.disconnect();
  47. }
  48. }
  49. document.addEventListener("visibilitychange", handleVisibilityChange, false);