-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZoopla.user.js
100 lines (95 loc) · 4.45 KB
/
Zoopla.user.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
//==UserScript==
// @name Zoopla Search Better Maker
// @namespace https://anitabyte.xyz
// @version 0.0.4
// @description Show floor plans in search
// @author anitabyte
// @run-at document-idle
// @match https://*.zoopla.co.uk/*
// @grant none
// ==/UserScript==
function get_data(response, listing) {
var domParser = new DOMParser();
var dom = domParser.parseFromString(response, "text/html");
var info_json = JSON.parse(dom.getElementById("__NEXT_DATA__").innerText);
var pageProps = info_json["props"]["pageProps"];
var listing_details = pageProps["listingDetails"];
var detailed_description = listing_details["detailedDescription"].toLowerCase();
var ad_targeting = listing_details["adTargeting"]
var has_floorplan = ad_targeting["hasFloorplan"];
var numBaths = listing_details["counts"]["numBathrooms"];
var divs = listing.querySelectorAll("div");
divs.forEach(div => {
if (numBaths >= 2) div.style.backgroundColor = "#238823";
else if (numBaths == 0) div.style.backgroundColor = "#ffbf00";
else div.style.backgroundColor = "#d2222d";
});
var infobox = document.createElement('div');
var infotable = document.createElement('table');
infotable.style.width = '100%';
var infoTableObj = {
"Tenure": ad_targeting["tenure"],
"W/C": detailed_description.includes("w/c") || detailed_description.includes("wc")
}
infotable.innerHTML = Object.entries(infoTableObj).map(i => "<tr><td><b>" + i[0] + "</b></td><td>" + i[1] + "</td></tr>").join();
infobox.append(infotable);
if (has_floorplan) {
var floorPlanImages = info_json["props"]["pageProps"]["listingDetails"]["floorPlan"]["image"]
var floorPlanImgTags = floorPlanImages.map(i => "<img src='https://lid.zoocdn.com/u/2400/1800/" + i["filename"] + "' style='width:100%'>").join("<br />");
var floorPlanBox = document.createElement('div');
floorPlanBox.innerHTML = floorPlanImgTags;
infobox.append(floorPlanBox);
}
listing.append(infobox);
}
function augment_listings_main() {
/*if (document.URL.includes("page_size=25" || !document.URL.includes("page_size"))) {
var domain = document.URL.match(/(\/\/.*\/\?)/i)[0];
console.log(domain);
var args = [...document.URL.matchAll(/[\?\&]([^\&\#]+)/g)].map(i => i[1]).filter(i => (!i.includes("page") && !i.includes("pn")));
var arg_string = args.join("&") + "&page_size=500";
var redirect_url = domain + arg_string;
console.log(args);
console.log(arg_string);
console.log(redirect_url);
window.location.replace(redirect_url);
console.log("25 page");
} */
var listings = document.querySelectorAll('[id^=listing]');
listings.forEach(listing => {
var listing_url = listing.querySelector("a").href;
listing.style.backgroundColor = "#ffff00";
fetch(listing_url, { headers: { 'Content-Type': 'text/html' } }).then(response => response.text()).then(data => get_data(data, listing));
});
}
function augment_listings_map() {
var listing = document.querySelector('[data-testid="listing-card-portrait-mini"]');
var listing_url = listing.getElementsByTagName('a')[0].href;
fetch(listing_url, { headers: { 'Content-Type': 'text/html' } }).then(response => response.text()).then(data => get_data(data, listing));
}
(function () {
var observer = new MutationObserver(function (mutations) {
var called = false;
mutations.forEach(function (mutation) {
if (mutation.addedNodes.length != 0 && !called) {
try {
if (mutation.addedNodes[0].innerHTML.includes('listing') && mutation.addedNodes[0].localName == "div") {
if (document.URL.includes("/map/")) {
augment_listings_map();
called = true;
} else {
augment_listings_main();
console.log(mutation);
called = true;
}
}
} catch (err) {
// there are some without 'innerhtml'
}
} else {
}
});
});
observer.observe(document, { subtree: true, childList: true });
'use strict';
})();