-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
129 lines (104 loc) · 3.73 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import puppeteer from "puppeteer";
const browserInit=async()=>{
browser=await puppeteer.launch({
executablePath: 'F:/programs/chrome-win/chrome-win/chrome.exe',
// headless: false,
timeout:0
})
page=await browser.newPage()
}
const getFollow=async (url)=>{
let followers=[]
while(true){
await page.goto(url,{timeout:0})
const pageFollowers=await page.evaluate(()=>{
let spans1=document.querySelectorAll(".Link--primary")
let users=Array.from(spans1).map(item=>{
if(item.innerHTML!='')
return item.innerHTML
else{
return item.nextElementSibling.innerHTML
}
})
return users
})
followers=[...followers,...pageFollowers]
//---------- handle to next button and return the url ---------------------
url=await page.evaluate(()=>{
let container=document.querySelector('.pagination')
if(container.children[1].classList.contains("disabled"))
return false
else
return container.children[1].getAttribute('href')
})
//---------------- finish scrap condition -----------------
if (!url)
break
}
return followers
}
async function login(){
let url='https://github.com/login'
await page.goto(url,{timeout:0})
let result=await page.evaluate(async()=>{
document.querySelector('#login_field').value='your github username'
document.querySelector('#password').value='your github password'
document.querySelector('input[name="commit"]').click()
return true
})
await page.waitForNavigation();
}
const unfollowBasters=async(differ)=>{
let url='https://github.com/nariman-z-k?tab=following'
var targets=[]
while(true){
await page.goto(url,{timeout:0})
const y=await page.evaluate((differ,targets)=>{
let name1=''
let name2=''
let rows=document.querySelectorAll('.d-table')
Array.from(rows).forEach((row)=>{
if(row.querySelector('.Link--primary'))
name1=row.querySelector('.Link--primary').innerHTML
if(row.querySelector('.Link--secondary'))
name2=row.querySelector('.Link--secondary').innerHTML
if(differ.indexOf(name1)>=0 || differ.indexOf(name2)>=0){
let temp=row.querySelector('input[value="Unfollow"]')
temp.click()
}
name1=''
name2=''
})
return true
},differ,targets)
console.log("all basters removed!");
//---------- handle to next button and return the url ---------------------
url=await page.evaluate(()=>{
let container=document.querySelector('.pagination')
if(container.children[1].classList.contains("disabled"))
return false
else
return container.children[1].getAttribute('href')
})
//---------------- finish scrap condition -----------------
if (!url)
break
}
}
const mainFunction=async()=>{
await browserInit()
await login()
let url='https://github.com/nariman-z-k?tab=followers'
let followers=await getFollow(url)
// console.log(followers)
url='https://github.com/nariman-z-k?tab=following'
let followings=await getFollow(url)
// console.log(followings)
let difference = followings.filter(x => !followers.includes(x));
console.log(difference)
await unfollowBasters(difference)
await browser.close()
}
let browser
let page
mainFunction()