-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
111 lines (91 loc) · 2.8 KB
/
script.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const selectors = document.querySelectorAll(".input_select");
const results = document.querySelectorAll(".output_result");
const button = document.getElementById("submit_form");
const body = document.querySelector("body");
async function getData() {
const response = await fetch(
"https://script.google.com/macros/s/AKfycbwXkVQEb9kxhSpPBkCXqdHMiucaxPC_5Vd-S_3lEeZwJoHf3p49Bgfzd0OY-sy3T73p/exec"
);
const data = await response.json();
return data;
}
let dataList;
let hmap = [0, 0, 0, 0, 0, 0];
function loadData() {
getData().then((data) => {
dataList = data;
hmap = [0, 0, 0, 0, 0, 0];
setSelectors(data);
body.classList.remove("loading");
button.disabled = true;
});
}
loadData();
function setSelectors(items) {
const uniqueData = [];
items.forEach((item) => {
const rowData = [];
item.forEach((value) => {
if (!rowData.includes(value)) rowData.push(value);
});
uniqueData.push(rowData);
});
selectors.forEach((selector, index) => {
if (hmap[index] === 0) {
let str = `<option >Please select</option>`;
selector.innerHTML = str + getStr(uniqueData[index]);
} else {
selector.innerHTML = getStr(uniqueData[index]);
}
});
}
function getStr(items) {
let str = "";
items.forEach((item) => {
let temp = item.split(" ").join("_");
str += `<option value=${temp}>${item}</option>`;
});
return str;
}
const selectorsArray = Array.from(selectors);
let startIndex;
let endIndex;
selectors.forEach((selector) => {
selector.addEventListener("change", (e) => {
let index = selectorsArray.indexOf(selector);
hmap[index] = 1;
startIndex = dataList[index].indexOf(selector.value.split("_").join(" "));
endIndex = dataList[index].lastIndexOf(selector.value.split("_").join(" "));
dataList.map((data, index) => {
dataList[index] = data.slice(startIndex, endIndex + 1);
});
setSelectors(dataList);
if (!hmap.includes(0)) button.disabled = false;
});
});
button.addEventListener("click", (e) => {
if (startIndex === endIndex && !hmap.includes(0)) {
results.forEach((result, index) => {
result.value = dataList[index + 6][0];
});
showInputValues();
loadData();
} else {
body.classList.add("error");
setTimeout(() => {
body.classList.remove("error");
}, 2000);
}
e.preventDefault();
});
function showInputValues() {
let arr = [];
selectors.forEach((selector) => {
arr.push(selector.value.split("_").join(" "));
});
let str = `Showing results for <b>${arr[0]}</b> (channel), <b>${arr[1]}</b>
(partner/placement),
<b>${arr[2]}</b> (platform), <b>${arr[3]}</b> (App Status),<br> <b>${arr[4]}</b> (IDFA/GAID Status (source)),
<b>${arr[5]}</b> (IDFA/GAID Status(client app))`;
document.querySelector(".current_selected_inputs").innerHTML = str;
}