-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetQuestionsFromGFG.js
88 lines (75 loc) · 1.91 KB
/
getQuestionsFromGFG.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
async function getGFGQuestions(pageGFG, numQues, difficulty, check) {
let p;
if(difficulty==0)
{
await Promise.all([
pageGFG.waitForNavigation(),
pageGFG.click("[value='0']", { delay: 1000 })
])
p= new Promise(function(resolve,reject){
pageGFG.waitForSelector(".panel.problem-block div>span",{setTimeout:500})
.then(function(){
resolve();
})
.catch(function(){
resolve();
return {"No Easy Questions Available":'\0'}
})
})
}
else if(difficulty==1)
{
if(check==true)
await pageGFG.click("[value='0']", { delay: 1000 })
await Promise.all([
pageGFG.waitForNavigation(),
pageGFG.click("[value='1']", { delay: 1000 })
])
p= new Promise(function(resolve,reject){
pageGFG.waitForSelector(".panel.problem-block div>span",{setTimeout:500})
.then(function(){
resolve();
})
.catch(function(){
resolve();
return {"No Medium Questions Available":'\0'}
})
})
}
else if(difficulty==2)
{
if(check==true)
await pageGFG.click("[value='1']", { delay: 1000 })
await Promise.all([
pageGFG.waitForNavigation(),
pageGFG.click("[value='2']", { delay: 1000 })
])
p= new Promise(function(resolve,reject){
pageGFG.waitForSelector(".panel.problem-block div>span",{setTimeout:500})
.then(function(){
resolve();
})
.catch(function(){
resolve();
return {"No Hard Questions Available":'\0'}
})
})
}
await p;
return await pageGFG.evaluate(function (numQues) {
let ques = {};
let problemName = document.querySelectorAll(".panel.problem-block div>span");
let problemLink = document.querySelectorAll('[style="position: absolute;top: 0;left: 0;height: 100%;width: 100%;z-index:1;pointer:cursor;"]');
if (problemName.length > numQues) {
for (let i = 0; i < numQues; i++)
ques[problemName[i].innerText] = problemLink[i].getAttribute("href");
}
else {
for (let i = 0; i < problemName.length; i++) {
ques[problemName[i].innerText] = problemLink[i].getAttribute("href");
}
}
return ques;
}, numQues)
}
module.exports={"getQues":getGFGQuestions};