-
Notifications
You must be signed in to change notification settings - Fork 0
/
refresh-and-beep.js
83 lines (67 loc) · 2.72 KB
/
refresh-and-beep.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
let audioContext
async function initializeAudioContext() {
const constraints = { audio: true }
try {
const stream = await navigator.mediaDevices.getUserMedia(constraints)
audioContext = new (window.AudioContext || window.webkitAudioContext)()
stream.getTracks().forEach(track => track.stop())
console.log("AudioContext initialized.")
} catch (error) {
console.error("Error initializing AudioContext:", error)
}
}
async function checkForNewIDs() {
console.log("Running checkForNewIDs...")
const idsOnPage = [...document.querySelectorAll(".result-list__listing")].map(e => e.getAttribute("data-id"))
const storedIDs = JSON.parse(localStorage.getItem("storedIDs")) || []
const newIDs = idsOnPage.filter(id => !storedIDs.includes(id))
if (newIDs.length > 0) {
console.log("New IDs found. Playing a beep sound...")
await playBeep(200)
storedIDs.push(...newIDs)
localStorage.setItem("storedIDs", JSON.stringify(storedIDs))
} else {
console.log("No new IDs found.")
}
}
async function playBeep(duration) {
if (!audioContext || audioContext.state !== "running") {
console.log("AudioContext is not running or not created. Cannot play beep sound.")
return
}
console.log("Playing beep sound...")
return new Promise((resolve, reject) => {
const oscillator = audioContext.createOscillator()
oscillator.connect(audioContext.destination)
oscillator.start()
setTimeout(() => {
console.log("Beep sound stopped.")
oscillator.stop()
resolve()
}, duration)
})
}
async function refreshPageRandomly(minDelaySeconds, maxDelaySeconds) {
const minDelay = minDelaySeconds * 1000
const maxDelay = maxDelaySeconds * 1000
const refreshDelay = Math.floor(Math.random() * (maxDelay - minDelay + 1)) + minDelay
const nextFireTime = new Date(Date.now() + refreshDelay).toLocaleTimeString()
console.log("Refreshing the page randomly...")
console.log(`Next refresh will occur at: ${nextFireTime}`)
await new Promise(resolve => setTimeout(resolve, refreshDelay))
console.log("Reloading the page...")
location.reload()
}
async function main() {
await new Promise(resolve => setTimeout(resolve, 5000))
await initializeAudioContext()
if (document.title.startsWith("Wohnung mieten")) {
console.log("Checking IDs after the page is loaded...")
await checkForNewIDs()
await refreshPageRandomly(60, 180)
} else if (document.title === "Ich bin kein Roboter - ImmobilienScout24") {
console.log("Captcha page displayed. Playing a long beep sound...")
await playBeep(600)
}
}
main()