Hide ratings on backloggd.com

10/2/2025, 22:34:48

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Hide ratings on backloggd.com
// @namespace   Violentmonkey Scripts
// @icon        https://www.backloggd.com/favicon.ico
// @match       https://backloggd.com/*
// @match       https://www.backloggd.com/*
// @run-at      document-start
// @grant       none
// @version     1.0.3
// @author      epicBlast
// @description 10/2/2025, 22:34:48
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';

    // Selector for the target element
    const selectorParent = "#game-stats > div.row.mt-4.mt-md-3 > div.col-4.col-xl-3.d-none.d-md-block.order-1 > div.container.backloggd-container.center-container.h-100"
    const selectorScore = "#game-rating > h1";
    const selectorGraph = "#ratings-bars-height"

    function hideElements() {
        console.log("hideElements entry")
        let style = document.getElementById("hide-elements-style")
        if (!style) {
            style = document.createElement("style");
            style.id = "hide-elements-style";
            style.innerHTML = `${selectorScore}, ${selectorGraph} { display: none !important; }`;
            document.head.appendChild(style);
            console.log("style created")
        }
        else {
            style.innerHTML = `${selectorScore}, ${selectorGraph} { display: none !important; }`;
        }
    }

    function showElements() {
        console.log("showElements entry")
        const style = document.getElementById("hide-elements-style")
        if (!style) return;
        style.innerHTML = `
            ${selectorScore} { display: block; }
            ${selectorGraph} { display: flex; }
        `;
    }

    function toggleElements() {
        const style = document.getElementById("hide-elements-style");
        if (!style) return;

        if (style.innerHTML.includes("display: none !important")) {
            showElements();
        } else {
            hideElements();
        }
    }

    function removeStyle() {
        const existingStyle = document.getElementById("hide-elements-style");
        if (existingStyle) {
            existingStyle.remove();
        }
    }

    function addEye() {
        const parent = document.querySelector(selectorParent);
        if (!parent || parent.querySelector(".eye-toggle")) return;

        // Create an eye icon button
        const eyeIcon = document.createElement("button");
        eyeIcon.innerHTML = "👁";
        eyeIcon.className = "eye-toggle";
        eyeIcon.style.cursor = "pointer";
        eyeIcon.style.background = "none";
        eyeIcon.style.border = "none";
        eyeIcon.style.fontSize = "20px";
        eyeIcon.style.padding = "5px";

        // Insert the eye icon as the first child of the parent element
        parent.insertBefore(eyeIcon, parent.firstChild);

        // Toggle visibility on click
        eyeIcon.addEventListener("click", function() {
            toggleElements();
        });
    }

    function mainExecutor() {
        console.log("mainExecutor entry")
        if (document.querySelector('#user-info, #profile-sidebar')) {
            removeStyle();
        } else {
            const style = document.getElementById("hide-elements-style");
            if (!style) {
                hideElements();
            }
            addEye();
        }
    }

    function observePageChanges() {
        new MutationObserver(mutations => {
            if (!document.body.matches('#game-body, #user-info, #profile-sidebar') && !mutations.some(m => m.addedNodes.length)) return;
            mainExecutor();
        }).observe(document.documentElement, { childList: true, subtree: true });
    }

    observePageChanges();
    window.addEventListener("load", mainExecutor);
})();