Facebook YOUR Notifications Highlighter

Highlights more interesting notifications for YOU.

当前为 2017-02-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Facebook YOUR Notifications Highlighter
  3. // @namespace http://www.JamesKoss.com/
  4. // @version 1.0
  5. // @description Highlights more interesting notifications for YOU.
  6. // @author James Koss
  7. // @match https://www.facebook.com/*
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12. var first = true;
  13. var timed = false;
  14. var opened = false;
  15. var scrolled = false;
  16. function onScrollNots() {
  17. if (scrolled === false) {
  18. scrolled = true;
  19. setTimeout(function() { updateNotifications(); }, 1000);
  20. setTimeout(function() { scrolled = false; }, 3000);
  21. }
  22. }
  23. function updateNotifications() {
  24. if (timed === false) {
  25. setTimeout(function(){ timed = true; updateNotifications(); }, 1000);
  26. return;
  27. }
  28. if (opened === true && scrolled === false) {
  29. opened = false;
  30. return;
  31. }
  32. opened = true;
  33. if (first === true) {
  34. var scrolledArea = document.querySelector('div[class="uiScrollableAreaWrap scrollable"]');
  35. scrolledArea.addEventListener("scroll", onScrollNots);
  36. }
  37. var notificationsHolder = document.querySelector('div[class="_33p"]');
  38. var notificationsNew = notificationsHolder.querySelectorAll('li[class="_33c jewelItemNew"]');
  39.  
  40. for (var i = 0; i < notificationsNew.length; i++) {
  41. var current = notificationsNew[i];
  42.  
  43. var notificationParent = current.querySelector('div[class="_4l_v"]');
  44. var notificationYour = notificationParent.querySelectorAll('span');
  45. var match = false;
  46. for (var j=0; j < notificationYour.length; j++) {
  47. var cur = notificationYour[j];
  48. var t = cur.textContent;
  49. if (t.indexOf("replied to your") !== -1 ||
  50. t.indexOf("commented on your") !== -1 ||
  51. t.indexOf("shared your") !== -1) {
  52. match = true;
  53. break;
  54. }
  55. }
  56. if (match === false) {
  57. continue;
  58. }
  59. var a = current.querySelector('a[class="_33e _1_0e"]');
  60. a.style.backgroundColor = "#d0dff6";
  61. current.style.backgroundColor = "#d0dff6";
  62. }
  63. timed = false;
  64. first = false;
  65. }
  66. function onclickJewel(e) {
  67. if (e.which === 1) {
  68. updateNotifications();
  69. }
  70. }
  71. var fbNotificationsJewel = document.getElementById("fbNotificationsJewel");
  72. fbNotificationsJewel.addEventListener("click", onclickJewel);
  73. })();