-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlike.js
49 lines (45 loc) · 1.19 KB
/
like.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
let util = require("./../util")
/**
* /outcome
* Tweet status id and returns like status id
* @param {*} userID
* @param {*} pwd
* @param {*} likestatusId
*
*/
async function likeButton (userID, pwd,likestatusId) {
let data = {}
let browser =await util.getBrowser()
let page = await browser.newPage()
try {
await page.setViewport({ width: 1920, height: 1080 })
let loggedin = await util.cookie_login(page)
if(!loggedin) {
await util.auth_login(userID, pwd, page)
await util.save_login_cookie(page)
}
//To click favourite or like button
await page.goto(likestatusId)
const like_button = 'div[data-testid="like"]'
const unlikeButton = 'div[data-testid="unlike"]'
await page.waitFor(3000);
if(await page.$(unlikeButton)){
await browser.close()
return data
}else if(await page.$(like_button)){
await page.waitForSelector(like_button);
await page.click(like_button);
}
await browser.close()
data['success'] = true
return data
} catch (e) {
data['success'] = false
await browser.close()
console.log(e)
throw new Error('Failed to like..')
}
}
module.exports = {
likeButton,
}