DartCounter OnlyCam

Filter games in online lobby by Cam Only matches.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         DartCounter OnlyCam
// @author       mrdarts180
// @namespace    http://dartcounter.net/
// @version      1.2
// @license      MIT
// @description  Filter games in online lobby by Cam Only matches.
// @match        http*://dartcounter.net/*
// @icon         https://dartcounter.net/favicon-32x32.png
// @require      https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/js/all.min.js
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

(function() {
    'use strict';

    const config = {
        get showCamOnly() {
            return GM_getValue("ShowCamOnly", 1);
        },

        set showCamOnly(value) {
            GM_setValue("ShowCamOnly", value);
        }
    };

    function setNodeVisible(node, visible) {
        if (visible) {
            node.style.display = 'block';
        } else {
            node.style.display = 'none';
        }
    }

    var observer = new MutationObserver(function(mutations) {

        function isCamNode(node) {
            let icon = node.getElementsByTagName("mat-icon")[0];
            if (icon) {
                let iconName = icon.getAttribute("data-mat-icon-name");
                if (iconName && iconName.toLowerCase() == "videocam-outline") {
                    return true;
                }
            }
            return false;
        }

        for (const mutation of mutations) {
            for (const node of mutation.addedNodes) {
                if (node.nodeName.toLowerCase() == "app-global-lobby-online-game") {
                    let mainHeader = node.getElementsByClassName("main-header")[0];
                    if (mainHeader) {
                        const svg = document.createElement('svg');
                        Object.assign(svg, {
                            className: "fa-2xs fa-regular fa-eye",
                        });

                        const icon = document.createElement('mat-icon');
                        Object.assign(icon, {
                            className: "mat-icon notranslate header-button-icon mat-icon-no-color",
                            role: "img",
                        });
                        if (!config.showCamOnly) {
                            icon.setAttribute("disabled", "disabled");
                        }
                        icon.append(svg);

                        var button = document.createElement("button");

                        button.addEventListener('click', function onClick(event) {
                            if (!config.showCamOnly) {
                                icon.removeAttribute("disabled");
                                config.showCamOnly = 1;
                            } else {
                                icon.setAttribute("disabled", "disabled");
                                config.showCamOnly = 0;
                            }

                            let nodes = document.getElementsByTagName("app-joinable-online-game");
                            for (const node of nodes) {
                                setNodeVisible(node, !config.showCamOnly || isCamNode(node));
                            }
                        });

                        button.append(icon);
                        mainHeader.lastElementChild.prepend(button);
                    }
                }

                if (node.nodeName.toLowerCase() == "app-joinable-online-game") {
                    setNodeVisible(node, !config.showCamOnly || isCamNode(node));
                }
            }
        }
    });
    observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true});

})();