-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
69 lines (58 loc) · 2.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function getSeperator() {
var radioButtons = document.querySelector('input[name="separate-by"]:checked').value;
switch(radioButtons) {
case "separate-new-lines":
return /\n/g;
case "separate-commas":
return ","
case "separate-custom":
return document.getElementById("separate-custom-input").value;
}
}
function getTag() {
var radioButtons = document.querySelector('input[name="display-as"]:checked').value;
switch(radioButtons) {
case "html-list":
return "li";
case "html-select":
return "option"
case "html-custom":
return document.getElementById("custom-tag").value;
}
}
function getValue() {
var radioButtons = document.querySelector('input[name="value-format"]:checked').value;
switch(radioButtons) {
case "no-value":
return "none";
case "first-word":
return "first"
case "join-using":
return document.getElementById("custom-join").value;
}
}
function convertList() {
var textInput = document.getElementById("text-input").value.trim();
var convertInput = document.getElementById("convert-input");
var seperator = getSeperator();
var textArray = textInput.split(seperator);
textArray = document.getElementById("remove-duplicates").checked ? [...new Set(textArray)] : textArray
var tag = getTag();
var value = getValue();
var convertArray;
if (value == "none") {
convertArray = textArray.map(item => `<${tag}>${item.trim()}</${tag}>`);
} else if (value=="first") {
convertArray = textArray.map(item => `<${tag} value="${item.trim().toLowerCase().split(" ")[0]}">${item.trim()}</${tag}>`)
} else {
convertArray = textArray.map(item => `<${tag} value="${item.trim().toLowerCase().split(" ").join(value)}">${item.trim()}</${tag}>`)
}
convertInput.value = tag == "option" ? `<select>\n ${convertArray.join("\n ")}\n</select>` : convertArray.join("\n")
}
function copyConvertedList() {
var convertInput = document.getElementById("convert-input");
convertInput.select();
if(document.execCommand("copy")){
alert("Copied to clipboard.");
};
}