-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathig_giveaway_randomizer.js
64 lines (50 loc) · 1.65 KB
/
ig_giveaway_randomizer.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
/*
This script runs in the the browser dev tools to load all commenters on an
Instagram post and select one randomly for giveways, contests, etc..
It programatically retrieves and excludes the owner of the post.
Navigate to post
Load entire script in browser and press enter
*/
const me = document.getElementsByClassName('_2g7d5')[0].title
function loadAllComments(){
let load_more = document.querySelector('._m3m1c._1s3cd')
return new Promise(resolve => {
setInterval(() => {
if (document.querySelector('._m3m1c._1s3cd') == null) {
resolve();
}
load_more.click()
}, 300)
})
}
async function randomizeWinner(){
await loadAllComments()
let participants = []
let commenters = document.querySelectorAll('._2g7d5.notranslate._95hvo')
for(let i = 0; i < commenters.length; i++) {
let commenter = commenters[i]
if (commenter.title != me){
let title = commenter.title
participants.push(title)
}
}
console.log('Number of Entries: ' + participants.length)
let display = document.createElement('div')
display.style.position = 'absolute'
display.style.left = '50%';
display.style.top = '50%';
display.style.transform = 'translateX(-50%) translateY(-50%)';
display.style.zIndex = 1000000;
display.style.fontSize = '100px'
document.body.innerHTML = ''
document.body.appendChild(display)
let spinWheelInterval = setInterval(() => {
let random = Math.floor(participants.length * Math.random())
display.innerHTML = participants[random]
}, 100)
setTimeout(() => {
clearInterval(spinWheelInterval)
console.log(display.innerHTML)
}, 8000)
}
randomizeWinner()