Autodarts shared board script

Auto remove board user and auto 'use my board' on every user that joins

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Autodarts shared board script
// @license      MIT
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Auto remove board user and auto 'use my board' on every user that joins
// @author       Senne
// @match        *//:autodarts.io/lobbies/*
// @match        *autodarts.io/lobbies/*
// @match        *autodarts.io/*
// @match        *play.autodarts.io/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant        none
// @run-at       document-end
// ==/UserScript==

const username = "TEAL";

var MutationObserver = window.MutationObserver;
var myObserver = new MutationObserver(mutationHandler);
var obsConfig = {
    childList: true, attributes: true,
    subtree: true, attributeFilter: ['class']
};

myObserver.observe(document, obsConfig);

function mutationHandler(mutationRecords) {

    mutationRecords.forEach(function (mutation) {

        if (mutation.type == "childList" &&
            typeof mutation.addedNodes == "object" &&
            mutation.addedNodes.length
        ) {
            for (var J = 0, L = mutation.addedNodes.length; J < L; ++J) {
                checkForCSS_Class(mutation.addedNodes[J]);
            }
        }
        else if (mutation.type == "attributes") {
            checkForCSS_Class(mutation.target);
        }
    });
}
function checkForCSS_Class(node) {
    //-- Only process element nodes

    if (node.classList !== undefined) {
        if (node.classList.value === "chakra-card css-9w33n0") {
            console.log(node.classList.value);
            var elements = node.getElementsByClassName("chakra-table css-5605sr");
            if (elements.length === 1) {
                var rows = elements[0].getElementsByClassName("css-0");
                Array.from(rows).forEach(row => deleteUser(row));
            }
        }
        else if (node.classList.value === "css-0") {
            deleteUser(node);
        }
    }
}

function deleteUser(node) {
    if (node.childNodes.length === 0) {
        return;
    }
    var name = node.getElementsByClassName("ad-ext-player-name")
    if (name.length === 0 || name == undefined) {
        return;
    }
    var nameNode = name[0].childNodes[0].childNodes[0].data;
    if (nameNode === username) {
        var deleteButtons = node.getElementsByClassName("chakra-button css-8zte6d");
        if (deleteButtons.length === 1) {
            deleteButtons[0].click();
        }
        else {
            deleteButtons = node.getElementsByClassName("chakra-button css-22xpxh");
            if (deleteButtons.length === 1) {
                deleteButtons[0].click();
            }
        }
    }
    else {
        var useBoard = node.getElementsByClassName("chakra-button css-1e89954");
        if (useBoard.length === 1) {
            useBoard[0].click();
        }
        else {
            useBoard = node.getElementsByClassName("chakra-button css-1wtemij");
            if (useBoard.length === 1) {
                useBoard[0].click();
            }
        }
    }
}