Modrinth Gallery Text Background

Adds background color to text on gallery images

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

作者のサイトでサポートを受ける。または、このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name           Modrinth Gallery Text Background
// @name:tr        Modrinth Galeri Yazısı Arkaplanı
// @namespace      https://github.com/Arcdashckr/Modrinth-Gallery-Text-Background
// @version        1.0
// @description    Adds background color to text on gallery images
// @description:tr Galeri sayfasında görsellerin metinlerine arka plan rengi ekler
// @author         Arcdashckr
// @match          https://modrinth.com/*
// @run-at         document-end
// @icon           https://modrinth.com/favicon-light.ico
// @grant          none
// @license        MIT
// @supportURL     https://github.com/Arcdashckr/Modrinth-Gallery-Text-Background/issues
// ==/UserScript==

(function () {
    'use strict';

    let lastLog = "";

    function log(message, type = "INFO") {
        if (lastLog === message) return;
        lastLog = message;

        const styles = {
            INFO: "color: #3b82f6; font-weight: bold;",
            SUCCESS: "color: #22c55e; font-weight: bold;",
            WARN: "color: #f59e0b; font-weight: bold;",
            SYSTEM: "background: #3b82f6; color: white; padding: 2px 5px; border-radius: 3px;"
        };

        console.log(`%c[Modrinth-Gallery][${type}]%c ${message}`, styles.SYSTEM, styles[type]);
    }

    function isGalleryPage() {
        return window.location.pathname.endsWith("/gallery");
    }

    function applyStyle() {
        const elements = document.querySelectorAll(
            '.expanded-image-modal .content .floating .text[data-v-b80ce4e8]'
        );

        if (elements.length > 0) {
            elements.forEach(el => {
                el.style.backgroundColor = 'var(--color-scrollbar)';
            });
            log("Gallery text styled.", "SUCCESS");
        }
    }

    function handlePageState() {
        if (isGalleryPage()) {
            log("Gallery page detected.", "INFO");
            applyStyle();
        } else {
            log("Not a gallery page.", "WARN");
        }
    }

    const onMutate = function () {
        if (isGalleryPage()) {
            applyStyle();
        }
    };

    const observer = new MutationObserver(onMutate);
    observer.observe(document.body, { childList: true, subtree: true });

    log("Script initialized.", "SYSTEM");
    handlePageState();

})();