-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.js
70 lines (69 loc) · 1.92 KB
/
core.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
const validate=require("./validate.js");
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const fetch=require("cross-fetch");
const isScratcher=async function(username,options) {
var falseOnError=false;
var result1=new AbortController();
if(options instanceof Object) {
if(typeof options.falseOnError=="boolean") {
falseOnError=options.falseOnError;
}
}
if(!validate(username)) {
if(falseOnError) {
return false;
}
else {
throw new TypeError("Invalid username!");
}
}
console.log("At request");
const scratchRes=await fetch(`https://scratch.mit.edu/users/${username}`); // Thanks @webdev03 for teaching me about backtick brackets!
console.log("Got response!");
const text=await scratchRes.text();
console.log("Got text");
try {
const scratchDom=new JSDOM(text);
var value=scratchDom.window.document.querySelector("#profile-data > div.box-head > div > p > span.group").textContent.toLowerCase();
value=value.replaceAll("\n","");
value=value.replaceAll("\t","");
value=value.replaceAll(String.fromCharCode(32),"")
if(value=="scratchteam" || value=="scratcher") {
result1.abort();
}
else {
// Do nothing
}
console.log("Got result!");
}
catch(e) {
if(falseOnError) {
result=false;
}
else {
console.error(e.stack);
throw e;
}
}
/* },function(e) {
if(falseOnError) {
result=false;
}
else {
console.error(e.stack);
throw e;
}
})
},function(e) {
if(falseOnError) {
result=false;
}
else {
console.error(e.stack);
throw e;
}
}) */
return result1.signal.aborted;
}
module.exports=isScratcher;