-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
129 lines (114 loc) · 3.25 KB
/
content.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
129
'use strict'
let checkerInterval = null
let lastCount = 0
let goodChecks = 0
// let activeIntervals = []
const DATA = {
follow: {
toggle: false,
loops: 1,
},
party: {
toggle: false,
loops: 10,
},
}
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
// console.log(sender.tab ? 'from a content script:' + sender.tab.url : 'from the extension')
if (request.type === 'follow') {
DATA.follow.toggle = !DATA.follow.toggle
DATA.party.toggle = false
}
if (request.type === 'party') {
DATA.follow.toggle = false
DATA.party.toggle = !DATA.party.toggle
}
sendResponse({ follow: DATA.follow.toggle, party: DATA.party.toggle })
if (request.type) {
if (DATA.follow.toggle || DATA.party.toggle) startInterval()
else clearInterval(checkerInterval)
}
})
const shuffle = (array) => {
var currentIndex = array.length
var temporaryValue, randomIndex
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex--)
temporaryValue = array[currentIndex]
array[currentIndex] = array[randomIndex]
array[randomIndex] = temporaryValue
}
return array
}
// const createCounter = (elem) => {
// const countElem = elem.closest('span.count')
// if (countElem.length > 0) {
// countElem.text(`${i + 1}`)
// } else {
// const countElem = $('<span class="count">0</span>')
// countElem.insertAfter(element)
// }
// }
const getLoops = () => {
if (DATA.follow.toggle) return DATA.follow.loops
if (DATA.party.toggle) return DATA.party.loops
return 0
}
const searchClass = () => {
if (DATA.follow.toggle) {
const share = $('.modal a').get(0)
return $(share).find('div').first()
}
if (DATA.party.toggle) {
const share = $('.modal a').get(1)
return $(share).find('div').first()
}
return null
}
const startSharing = (_elems) => {
let total = 0
let counter = 0
const elems = DATA.follow.toggle ? shuffle(_elems) : _elems
elems.each((index, _element) => {
const element = $(_element).closest('div[class*="col"]').find('i').last()
for (let i = 0; i < getLoops(); ++i) {
// activeIntervals.push(
setTimeout(() => {
if (DATA.follow.toggle || DATA.party.toggle) {
element.css('backgroundColor', 'yellow')
element.get(0).click()
// activeIntervals.push(
setTimeout(() => {
const share = searchClass()
// console.info('STATUS', total, counter, counter + 1 === total - 1 && DATA.party.toggle)
if (share.length > 0) {
share.get(0).click()
if (counter + 1 === total && DATA.party.toggle) {
startSharing(_elems)
}
}
++counter
}, 1500)
// )
}
}, 3000 * ++total)
// )
}
})
}
const startInterval = () => {
lastCount = 0
goodChecks = 0
const radioToggle = $('input[value*="available"]')
radioToggle.get(0).click()
checkerInterval = setInterval(() => {
const elems = $('a[href*="/listing/"] img')
if (lastCount === elems.length) ++goodChecks
else elems.last().get(0).scrollIntoView()
if (goodChecks === 2) {
clearInterval(checkerInterval)
startSharing(elems)
}
lastCount = elems.length
}, 2500)
}