-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (54 loc) · 1.92 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
// Try edit message
const getData = async () => {
const res = await fetch('pimple.php');
return await res.json();
};
const copyToClipboard = {
click: function (e) {
const input = document.createElement('input');
const btn = e.currentTarget;
const btns = document.getElementsByClassName('js__pimple__matches_copy_link-btn');
input.value = btn.dataset.copy;
document.body.append(input);
input.select();
document.execCommand("copy");
input.remove();
for (let i = 0; i < btns.length; i++) {
const item = btns.item(i);
item.innerHTML = 'Copy';
}
btn.innerHTML = 'Copied';
}
};
const addDataToTable = (data) => {
const table = document.getElementById('js__pimple__matches-table');
const spinners = document.getElementById('js__pimple__matches_spinners-div');
table.classList.remove("d-none");
spinners.classList.add("d-none");
data.forEach(function (item, key) {
const row = table.insertRow(key);
const cellName = row.insertCell(0);
const cellLink = row.insertCell(1);
const cellBtn = row.insertCell(2);
cellName.innerHTML = item.name;
if (item.acestream) {
const btnCopy = document.createElement('button');
btnCopy.type = 'button';
btnCopy.classList.add('btn', 'btn-secondary', 'btn-sm', 'js__copy_btn', 'js__pimple__matches_copy_link-btn');
btnCopy.dataset.copy = item.acestream;
btnCopy.innerText = 'Copy';
btnCopy.addEventListener('click', copyToClipboard.click);
cellBtn.append(btnCopy);
const link = document.createElement('a');
link.href = item.acestream;
link.innerText = 'Open';
cellLink.append(link);
}
});
};
const init = () => {
getData().then(function (data) {
addDataToTable(data);
});
};
init();