-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
55 lines (45 loc) · 1.71 KB
/
main.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
$(document).ready(function() {
const npe = document.getElementById("newpipe-export");
const yte = document.getElementById("youtube-export");
const npi = document.getElementById("newpipe-import");
const btnCsv = document.getElementById("from-csv");
const btnRow = document.getElementById("from-name-url");
function fromCSV(e) {
e.preventDefault();
const offset = yte.value.startsWith("Channel Id") ? 1 : 0;
const subs = yte.value
.split("\n")
.slice(offset)
.map((line) => line.trim())
.filter((line) => line.length > 0)
.map((line) => line.split(","))
.map(([, url, name]) => ({
service_id: 0,
url: url.replace("http:", "https:"),
name,
}));
const tmpl = JSON.parse(npe.value);
tmpl.subscriptions = subs;
npi.value = JSON.stringify(tmpl, null, 2);
}
function fromNameUrl(e) {
e.preventDefault();
const subs = yte.value
.split("\n")
.map((line) => line.trim())
.filter((line) => line.length > 0)
.map((line) => line.split(/(http)/))
.map(([name, prefix, url]) => ({
service_id: 0,
url: (prefix + url).replace("http:", "https:"),
name: url.split('/').reverse()[0],
//name: name.trim(),
}));
const tmpl = JSON.parse(npe.value);
tmpl.subscriptions = subs;
npi.value = JSON.stringify(tmpl, null, 2);
}
btnCsv.addEventListener("click", fromCSV);
btnRow.addEventListener("click", fromNameUrl);
console.log("Event listeners are ready!");
});