From 590763c613477ce75c899beb0f3adbb41d13cf49 Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Wed, 2 Jun 2021 22:32:57 +0200 Subject: [PATCH] implement multiline input copy --- static/balance.js | 53 ++++++++++++++++++++++++++++++++++++- templates/json_builder.html | 9 +++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/static/balance.js b/static/balance.js index cf6c669..e3a3762 100644 --- a/static/balance.js +++ b/static/balance.js @@ -1,4 +1,5 @@ positions = [ "Top", "Jungle", "Mid", "Support" , "Bottom" ] +acceptedParser = [ "top", "jungle", "mid", "sup" , "bot", "adc", "support", "bottom" ] function checkPlayer() { if(this.value == ""){ @@ -77,7 +78,6 @@ function fastPosChanged() { /* allow some basic shit */ if(clean == "*" || clean == ""){ - console.log("lol") retVal = true } @@ -180,6 +180,57 @@ function balance(){ } +function parseMultiline(){ + + var names = [] + var prioStrings = [] + + field = document.getElementById("multi-line-copy") + lines = field.value.split("\n") + lines.forEach(l => { + + lowestIndex = 100 + + acceptedParser.forEach( p => { + i = l.indexOf(" " + p) + if(i > 3 && i < lowestIndex){ + lowestIndex = i + } + }) + + if(lowestIndex != 100){ + name = l.substring(0, lowestIndex) + prioStr = l.substring(lowestIndex) + names.push(name) + prioStrings.push(prioStr) + } + }) + + sides = [ "left", "right"] + count = 0 + sides.forEach(s => { + for(i = 0; i<5; i++){ + + pObjField = document.getElementById("playername-" + s + "-" + i) + prObjField = document.getElementById("check-" + s + "-fastpos-" + i) + + if(count >= names.length){ + pObjField.value = "" + prObjField.value = "" + }else{ + pObjField.value = names[count] + prObjField.value = prioStrings[count] + } + + count++; + } + }) + + const focusEvent = new Event("focus") + fastPosFields.forEach(el => el.dispatchEvent(focusEvent)) + balance() +} + fastPosFields = document.getElementsByClassName("fastpos") playerNameFields = document.getElementsByClassName("pname") diff --git a/templates/json_builder.html b/templates/json_builder.html index 2cb997f..49548fb 100644 --- a/templates/json_builder.html +++ b/templates/json_builder.html @@ -23,6 +23,15 @@
+ + + +
+
{% for side in sides %}