-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
104 lines (77 loc) · 3.35 KB
/
script.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
(async function () {
///////// INSERT YOUR KEY & EVENT NAME BELOW /////////
const iftttKey = "paste_here_your_ifttt_key"
const iftttEventName = "paste_here_your_event_name"
//////////////////////////////////////////////////////
const recheckIntervalInMs = 60000 + (Math.round(Math.random() * 20 - 10) * 1000)
const captchaWasVisibleBefore = (await chrome.storage.local.get("captchaIsVisible")).captchaIsVisible;
const captchaIsVisible = !!document.querySelector('.main__captcha')
if (captchaIsVisible && !captchaWasVisibleBefore) {
await sendMessage("Solve the Captcha! ❌", null, null)
await chrome.storage.local.set({ "captchaIsVisible": true });
}
if (!captchaIsVisible) {
if (captchaWasVisibleBefore) {
await sendMessage("Captcha solved! ✅", null, null)
}
const items = [...document.querySelectorAll("li.result-list__listing")]
const previousIds = (await chrome.storage.local.get("immoIds")).immoIds
const currentIds = items.map((item) => item.attributes["data-id"].value)
const newIds = previousIds ? currentIds.filter(id => !previousIds.includes(id)) : []
if (!previousIds) {
console.log("Immo Check: Initial items were saved successfully")
await sendMessage("Immo Check setup was successful! ✅", null, null)
} else if (newIds.length == 0) {
console.log("Immo Check: No new items were found on the page. Check again in " + (recheckIntervalInMs / 1000) + "s.")
} else {
console.log("Immo Check: Found " + newIds.length + " new items on the page")
await triggerLazyLoading() // Lazy load images
for (const id of newIds) {
const element = document.querySelector(`li[data-id="${id}"]`)
const text = element.querySelector("h2").innerText.replace("NEU", "")
const link = element.querySelector("a").href
const allImages = element.querySelectorAll('img[alt="Immobilienbild"]')
const imgElem = allImages[1] || allImages[0]
let image = imgElem ? imgElem.src : null
await sendMessage(text, link, image)
}
}
await chrome.storage.local.set({
"immoIds": currentIds,
"captchaIsVisible": false
})
}
setTimeout(() => {
location.reload()
}, recheckIntervalInMs);
function sendMessage(text, link, image) {
const url = `https://maker.ifttt.com/trigger/${iftttEventName}/with/key/${iftttKey}?value1=${text}&value2=${link}&value3=${image}`
return fetch(url, { mode: "no-cors" });
}
async function wait(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}
async function triggerLazyLoading() {
scrollDown()
await wait(3000)
scrollUp()
}
function scrollUp() {
window.scrollTo({
top: 0,
behavior: 'smooth',
})
}
function scrollDown() {
var body = document.body,
html = document.documentElement;
var height = Math.max(body.scrollHeight, body.offsetHeight,
html.clientHeight, html.scrollHeight, html.offsetHeight);
window.scrollTo({
top: height,
behavior: 'smooth',
})
}
})()