Crunchyroll Watchlist

Hide watched animes so it is easier to spot new episodes

目前為 2022-01-02 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Crunchyroll Watchlist
// @version      1
// @description  Hide watched animes so it is easier to spot new episodes
// @match        https://beta.crunchyroll.com/*
// @icon         https://www.google.com/s2/favicons?domain=crunchyroll.com
// @grant        none
// @namespace   https://greasyfork.org/users/206408
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    function l(...args){
        console.log('[Watchlist]', ...args)
    }

    function filter(){
        let container = document.querySelector("#content > div > div.app-body-wrapper > div > div > div.erc-watchlist > div.watchlist-body > div:nth-child(1) > div > div")
        for(let row of container.children){
            row = row.children[0]
            for(let item of row.children){
                let card = item.querySelector('.c-watchlist-card')
                if(card){ //not a loading placeholder
                    let subtitle = card.querySelector('.c-watchlist-card__subtitle').textContent
                    if(subtitle.includes('Watch Again')){
                        //Do something with animes watched
                        card.style.filter = 'brightness(0.1)'
                    }
                }
            }
        }
    }

    //Observe changes to the DOM since there are no events that can be used
    const observer = new MutationObserver((mutationsList, observer) => {
        if(window.location.href === 'https://beta.crunchyroll.com/watchlist'){
            for(const mutation of mutationsList){
                //Items added to the watchlist grid
                if(['ReactVirtualized__Grid__innerScrollContainer', 'ReactVirtualized__Grid ReactVirtualized__List'].includes(mutation.target.className)){
                    filter()
                }
            }
        }
    })

    observer.observe(document, {subtree:true, childList:true, attributes:true})
})();