Kone sidebar remover

remove sidevar from kone

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

Advertisement:

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

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();
    }

})();