-
Notifications
You must be signed in to change notification settings - Fork 0
/
catDownloader.plugin.js
94 lines (83 loc) · 2.49 KB
/
catDownloader.plugin.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
/**
* @name CatDownloader
* @author Bazyli
* @description Pobiera koty niezawodnie 🤓 `BdApi.Plugins.reload('catDownloader.plugin.js')`
* @version 0.0.1
*/
const config = {
info: {
name: "CatDownloader",
id: "CatDownloader",
description: "Szybko pobiera koty",
version: "0.0.1",
author: "Bazyli",
},
settings: {
filePrefix: "cats ",
directory: "cats",
},
};
module.exports = class catDownloader {
constructor() {}
getName() {
return config.info.name;
}
getAuthor() {
return config.info.author;
}
load() {}
start() {
const fs = require("fs");
function saveToFile(cats) {
if (fs.existsSync(__dirname + "/cats/cats.json")) {
let rawcats = fs.readFileSync(__dirname + "/cats/cats.json");
let catsJson = JSON.parse(rawcats);
fs.writeFileSync(
__dirname + "/cats/cats.json",
JSON.stringify(
{ data: [...catsJson.data, ...cats] },
null,
4
),
"utf8"
);
} else {
fs.writeFileSync(
__dirname + "/cats/cats.json",
JSON.stringify({ data: [...cats] }, null, 4),
"utf8"
);
}
}
console.log("start");
let cats = [];
// pobieranie zdjec, filmow z kanalu
document
.querySelector('[data-list-id="chat-messages"]')
.querySelectorAll("*")
.forEach((el) => {
if (el.id.includes("chat-messages")) {
if (el.querySelector("video")) {
return cats.push(el.querySelector("video").src);
} else {
el.querySelectorAll("*").forEach((el) => {
if (el.classList.value.includes("originalLink")) {
return cats.push(el.getAttribute("href"));
}
});
}
}
});
console.log(cats);
console.log(cats.length);
if (fs.existsSync(__dirname + "/cats")) {
saveToFile(cats);
} else {
fs.mkdirSync(__dirname + "/cats");
saveToFile(cats);
}
}
stop() {
console.log("stop");
}
};