COUB.COM - hide selected authors and disliked videos

hides selected authors and disliked videos on COUB.COM

当前为 2024-02-01 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         COUB.COM - hide selected authors and disliked videos
// @namespace    https://coub.com
// @version      1.2
// @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--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.coub-description__about__inner");
            let coubAuthor = coubDescription.querySelector("a.hbold.coub-description__about__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);
})();