Reddit Live Highlight New

Highlights new posts on a Reddit Live thread

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Reddit Live Highlight New
// @namespace    http://kmcgurty.com
// @version      1
// @description  Highlights new posts on a Reddit Live thread
// @author       Kmc - [email protected]
// @match        *://*.reddit.com/live/*
// @grant        GM_addStyle
// ==/UserScript==

var windowIsActive = false;

window.onfocus = function () {
    windowIsActive = true;
    
    var divs = document.querySelectorAll(".gm_solid");

    if(divs.length !== 0){
        for(var i = 0; i < divs.length; i++){
            divs[i].className = "body gm_fade";
        }
    }
}; 

window.onblur = function () {
    windowIsActive = false;
};


function highlightPost(div){
    if(windowIsActive){
        div.className = "body gm_fade";
    } else {
        div.className = "body gm_solid";
    }
}

// create an observer instance
var observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
        highlightPost(target.querySelector(".body"));
    });    
});
 
var target = document.querySelector('.liveupdate-listing');
// configuration of the observer:
var config = { attributes: true, childList: true, characterData: true };
 
// pass in the target node, as well as the observer options
observer.observe(target, config);


var css = `
@keyframes fade_out {
    0%   { background-color: rgba(255, 153, 0, .7); }
    100% { background-color: rgba(0, 0, 0, 0); }
}

.gm_solid{
    background-color: rgba(255, 153, 0, .7);
}

.gm_fade{
    animation: fade_out 5s ease-in-out;
}`;
GM_addStyle(css);