Kone sidebar remover

remove sidevar from kone

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

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

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

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

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

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

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

Advertisement:

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

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

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

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

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

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

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

Advertisement:

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name            Kone sidebar remover
// @name:ko         코네 사이드바 제거기
// @namespace       KN_SB_REM
// @description     remove sidevar from kone
// @description:ko  코네 사이드바를 제거합니다
// @icon            https://i.ibb.co/9mnHpbGN/Laria-square.jpg
// @match           https://kone.gg/*
// @version         1.0.3
// @author          Laria
// @license         MIT
// @encoding        utf-8
// @grant           GM_getValue
// @grant           GM_setValue
// @grant           GM_registerMenuCommand
// @grant           GM_unregisterMenuCommand
// @run-at          document-start
// ==/UserScript==

(async function () {
    'use strict';

    const utilSWAL2 = "https://cdn.jsdelivr.net/npm/sweetalert2@11";

    const KEY_ENABLED = 'sidebar_removal';

    let observer = null;
    let menuId = null;

    function getLocalizedScriptName(localized = true) {
        const defaultName =
            GM?.info?.script?.name ??
            GM_info?.script?.name ??
            'LARIA_UNTITLED_SCRIPT';

        if (!localized) {
            return defaultName;
        }

        const langs =
            navigator.languages ??
            [navigator.language];

        for (const lang of langs) {

            const fullKey = `name:${lang}`;
            const shortKey =
                `name:${lang.split('-')[0]}`;

            if (GM?.info?.script?.[fullKey]) {
                return GM.info.script[fullKey];
            }

            if (GM?.info?.script?.[shortKey]) {
                return GM.info.script[shortKey];
            }
        }

        return defaultName;
    }

    const SCRIPT_NAME = getLocalizedScriptName();
    const SCRIPT_DEFAULT_NAME = getLocalizedScriptName(false);
    const SCRIPT_VERSION = GM?.info?.script?.version ??
            GM_info?.script?.version ??
            '0.1Pre';

    class Logger {

        static log(...args) {
            console.log(`[${SCRIPT_NAME}]`, ...args);
        }

        static warn(...args) {
            console.warn(`[${SCRIPT_NAME}]`, ...args);
        }

        static error(...args) {
            console.error(`[${SCRIPT_NAME}]`, ...args);
        }

        static debug(...args) {
            console.debug(`[${SCRIPT_NAME}]`, ...args);
        }
    }
    Logger.log(`(${SCRIPT_DEFAULT_NAME}) V${SCRIPT_VERSION} loaded`);

    async function loadScriptOnce(src, globalName) {
        if (globalName && window[globalName]) return;

        await new Promise((resolve, reject) => {
            const s = document.createElement("script");
            s.src = src;
            s.onload = resolve;
            s.onerror = reject;
            document.documentElement.appendChild(s);
        });
    }

    function getCurrentSub() {
        return window.location.pathname.replace(
            /^\/([^/]+\/[^/]+).*$/,
            '$1'
        );
    }

    function hideSidebar() {

        if (!GM_getValue(KEY_ENABLED, true)) {
            return;
        }

        const currSub = getCurrentSub();

        const target = Array
            .from(document.querySelectorAll('h1'))
            .find(el => el.innerText?.match(currSub));

        if (
            target &&
            target.parentElement &&
            target.parentElement.innerText.match('구독중')
        ) {

            const sidebar =
                target.parentElement
                    ?.parentElement
                    ?.parentElement
                    ?.parentElement
                    ?.parentElement
                    ?.parentElement;

            if (
                sidebar &&
                sidebar.style.display !== 'none'
            ) {

                sidebar.style.display = 'none';

                Logger.log(
                    'Sidebar removed'
                );
            }
        }
    }

    function startObserver() {

        if (observer) {
            return;
        }

        observer = new MutationObserver(() => {
            hideSidebar();
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true,
            characterData: true
        });

        Logger.log(
            'Observer started'
        );

        hideSidebar();
    }

    function stopObserver() {

        if (!observer) {
            return;
        }

        observer.disconnect();
        observer = null;

        Logger.log(
            'Observer stopped'
        );
    }

    function refreshMenu() {

        if (menuId !== null) {
            GM_unregisterMenuCommand(menuId);
        }

        const enabled =
            GM_getValue(KEY_ENABLED, true);

        menuId = GM_registerMenuCommand(
            `사이드바 ${enabled ? '보이기' : '숨기기'}`,
            toggleSidebar
        );
    }

    function toggleSidebar() {

        const enabled =
            GM_getValue(KEY_ENABLED, true);

        const targetState = !enabled;

        GM_setValue(
            KEY_ENABLED,
            targetState
        );

        if (targetState) {
            startObserver();
        } else {
            stopObserver();
        }

        Logger.log(
            'side bar removal', targetState ? 'enabled' : 'disabled'
        );

        Swal.fire({
            icon: 'success',
            title: GM.info.script.name,
            html: `
                <b style="font-size: 87.5%">
                    앞으로 사이드바를
                    ${targetState ? '숨깁' : '표시합'}니다.
                </b>
                ${targetState ? "" : `
                    <br><br><i>이 설정은 사이트를 새로고침 시 자동 적용됩니다.<i>
                `}
            `,
            toast: true,
            position: "top-end",
            timer: 2000,
            timerProgressBar: true,
            confirmButtonText: '확인',
        });

        refreshMenu();
    }

    await loadScriptOnce(utilSWAL2, "Swal");

    refreshMenu();

    if (
        GM_getValue(KEY_ENABLED, true)
    ) {
        startObserver();
    }

})();