Facebook YOUR Notifications Highlighter

Highlights more interesting notifications for YOU.

目前為 2017-02-08 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Facebook YOUR Notifications Highlighter
// @namespace    http://www.JamesKoss.com/
// @version      1.0
// @description  Highlights more interesting notifications for YOU.
// @author       James Koss
// @match        https://www.facebook.com/*
// ==/UserScript==

(function() {
    'use strict';
    
    var first = true;
    var timed = false;
    var opened = false;
    var scrolled = false;
    
    function onScrollNots() {
        if (scrolled === false) {
            scrolled = true;
            
            setTimeout(function() { updateNotifications(); }, 1000);
            setTimeout(function() { scrolled = false; }, 3000);
        }
    }
    
    function updateNotifications() {
        if (timed === false) {
            setTimeout(function(){ timed = true; updateNotifications(); }, 1000);
            return;
        }
        
        if (opened === true && scrolled === false) {
            opened = false;
            return;
        }
        opened = true;
        
        if (first === true) {
            var scrolledArea = document.querySelector('div[class="uiScrollableAreaWrap scrollable"]');
            scrolledArea.addEventListener("scroll", onScrollNots);
        }
        
        var notificationsHolder = document.querySelector('div[class="_33p"]');
        var notificationsNew = notificationsHolder.querySelectorAll('li[class="_33c jewelItemNew"]');

        for (var i = 0; i < notificationsNew.length; i++) {
            var current = notificationsNew[i];

            var notificationParent = current.querySelector('div[class="_4l_v"]');
            var notificationYour = notificationParent.querySelectorAll('span');
            
            var match = false;
            for (var j=0; j < notificationYour.length; j++) {
                var cur = notificationYour[j];
                var t = cur.textContent;
                
                if (t.indexOf("replied to your") !== -1 ||
                    t.indexOf("commented on your") !== -1 ||
                    t.indexOf("shared your") !== -1) {
                    match = true;
                    break;
                }
            }
            
            if (match === false) {
                continue;
            }
            
            var a = current.querySelector('a[class="_33e _1_0e"]');
            a.style.backgroundColor = "#d0dff6";
            current.style.backgroundColor = "#d0dff6";
        }
        
        timed = false;
        first = false;
    }
    
    function onclickJewel(e) {
        if (event.which === 1) {
            updateNotifications();
        }
    }
    
    var fbNotificationsJewel = document.getElementById("fbNotificationsJewel");
    fbNotificationsJewel.addEventListener("click", onclickJewel);
})();