Battlefy seeding csv input script

When run creates an input for csv and a button that when clicked seeds the participants

Від 26.06.2021. Дивіться остання версія.

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 or Violentmonkey 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.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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!)

// ==UserScript==
// @name         Battlefy seeding csv input script
// @namespace    tampermonkey.net
// @version      0.1
// @description  When run creates an input for csv and a button that when clicked seeds the participants
// @author       newclarityex
// @match        https://battlefy.com/*
// @grant        none
// ==/UserScript==
 
(function() {
    'use strict';
 var loop = setInterval(() => {
    if(document.getElementsByClassName('seeding-buttons').length == 1){
        var table = document.getElementsByTagName("table")[0]
 
        var inputs = table.getElementsByTagName("input");
 
        var reference = document.getElementById("seed-by-number-list")
 
        var textarea = document.createElement("textarea")
 
        textarea.placeholder = "Insert csv player data"
 
        reference.parentElement.insertBefore(textarea,reference)
 
        var button = document.createElement("button")
 
        button.textContent = "seed"
        // button.style = getComputedStyle(document.getElementsByClassName('btn-shuffle')[0])
        button.classList.add('btn')
        button.classList.add('btn-primary')
 
        function parsecsv(inputcsv) {
            var names = [...table.getElementsByClassName("seed-name")]
            names = names.map(elem => elem.textContent.trim())
 
            console.log("called function");
            var rows = inputcsv.split('\n')
            var data = rows.map(elem => elem.split(',')
                            .map(elem => elem.trim()))
            data = data.map(elem => [elem[0],elem[1]])
 
            var unseeded = []
 
            for(var i = 0 ; i < names.length ; i++){
                inputs[i].focus()
                var seed = data.find(elem => elem[1] === names[i])
                if(seed){
                    inputs[i].value = seed[0].replace('.','')
                } else {
                    unseeded.push(names[i]);
                    inputs[i].value = ''
                }
            }
 
            console.log(`${names.length - unseeded.length}/${names.length} people seeded`);
            if(unseeded.length !== 0){
                console.log("unseeded people:")
                console.log(unseeded);
            }
        }
 
 
        button.onclick = () => { parsecsv(textarea.value) }
 
        reference.parentElement.insertBefore(button,reference)
 
        clearInterval(loop)
    }
}, 1000)
 
 
})();