Lemmy Subscription Helper

In the list of communities, darken communities that you're already subscribed to

目前為 2023-06-21 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Lemmy Subscription Helper
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  In the list of communities, darken communities that you're already subscribed to
// @author       MikeFez
// @match        https://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=lemmy.world
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    var isLemmy;
    try {
        isLemmy = document.head.querySelector("[name~=Description][content]").content === "Lemmy";
    } catch (_er) {
        isLemmy = false;
    }
    function isCommunityPage() {
        return window.location.pathname.includes("/communities");
    }

    function GM_addStyle(css) {
        const style = document.getElementById("GM_addStyleBy8626") || (function() {
            const style = document.createElement('style');
            style.type = 'text/css';
            style.id = "GM_addStyleBy8626";
            document.head.appendChild(style);
            return style;
        })();
        const sheet = style.sheet;
        sheet.insertRule(css, (sheet.rules || sheet.cssRules || []).length);
    }

    function markSubscribedCommunities() {
        const communityRows = document.querySelectorAll('table#community_table > tbody > tr');
        communityRows.forEach(function(communityRow) {
            console.log(communityRow.firstChild.innerText, communityRow.lastChild.innerText, ("Unsubscribe", "Subscribe Pending").includes(communityRow.lastChild.innerText))
            if (communityRow.lastChild.innerText !== "Subscribe") {
                communityRow.setAttribute('data-is-subscribed-to', true);
            }
        });
    }

    if (isLemmy && isCommunityPage()) {
        GM_addStyle('[data-is-subscribed-to="true"] { background-color: rgba(0,0,0,0.5); opacity: 0.3; }');
        markSubscribedCommunities();
    }
})();