COUB.COM - hide selected authors and disliked videos

hides selected authors and disliked videos on COUB.COM

目前為 2022-10-16 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         COUB.COM - hide selected authors and disliked videos
// @namespace    https://coub.com
// @version      1.0
// @description  hides selected authors and disliked videos on COUB.COM
// @author       Rhoads
// @license      CC-BY-SA-4.0
// @icon         https://cs14.pikabu.ru/avatars/2609/m2609364-1795047659.png
// @match        https://coub.com/*
// @run-at       document-start
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand

// ==/UserScript==

(async function () {
    "use strict";

    // author href with forward '/'
    let BLACKLIST = new Set(JSON.parse(GM_getValue("CoubBannedAuthors", "[]")));

    BLACKLIST.forEach((coubAuthor) =>
    {
        GM_registerMenuCommand(`Unban ${coubAuthor}`, function() { UnbanAuthor(coubAuthor); });
    });

    let lastCleanedPageID = "-1";

    function cleanUp(targetNode) {
        const lastPage = document.querySelector(".coubs-list__inner .page:last-child");

        if (lastCleanedPageID === lastPage.dataset.pageId) {
            return;
        }

        lastCleanedPageID = lastPage.dataset.pageId;

        const coubs = lastPage.querySelectorAll("div[coub-block].coub--normal-card");

        coubs.forEach((coub) =>
        {
            //let coubTitle = coub.querySelector("h5.description__title > a")?.title;

            if (!!coub.querySelector(".coub__dislike-button.-on"))
            {
                //console.log(`[COUB.COM - BLACKLIST] Removed disliked coub: ${coubTitle}`);
                coub.remove();

                return;
            }

            let coubDescription = coub.querySelector("div.description__stamp");
            let coubAuthor = coubDescription.querySelector("a.description__stamp__user")?.getAttribute("href");

            if (BLACKLIST.has(coubAuthor))
            {
                //console.log(`[COUB.COM - BLACKLIST] Removed blacklisted coub author: ${coubAuthor}`);
                coub.remove();

                return;
            }

            // add BAN button

            var button = document.createElement('button');
            button.setAttribute('id', 'ButtonBanAuthor');
            button.innerHTML = "Ban!";
            coubDescription.appendChild(button).addEventListener("click", function() { ButtonBanAuthorClickAction(coubAuthor); }, false);
        });
    }

    function ButtonBanAuthorClickAction (coubAuthor) {
        //console.log(`[COUB.COM - BLACKLIST] Blacklist coub author: ${coubAuthor}`);
        BLACKLIST.add(coubAuthor);
        SaveBlacklist();
    }

    function UnbanAuthor(coubAuthor) {
        //console.log(`[COUB.COM - BLACKLIST] Unban: ${coubAuthor}`);
        BLACKLIST.delete(coubAuthor);
        SaveBlacklist();
    }

    function SaveBlacklist() {
        GM_setValue("CoubBannedAuthors", JSON.stringify([...BLACKLIST]));
    }

    async function waitUntilExists(selector) {
        return new Promise(function check(resolve, reject) {
            let el = document.querySelector(selector);

            if (el) {
                return resolve(el);
            }

            setTimeout(function () {
                check(resolve, reject);
            }, 100);
        });
    }

    await waitUntilExists(".coubs-list__inner > .page");

    cleanUp();

    window.addEventListener("scroll", cleanUp);
})();