Skip to content

Instantly share code, notes, and snippets.

@Toxicable
Last active January 10, 2023 05:49
Show Gist options
  • Save Toxicable/604e7551db86b5caac85b067d42fafed to your computer and use it in GitHub Desktop.
Save Toxicable/604e7551db86b5caac85b067d42fafed to your computer and use it in GitHub Desktop.
realestate.com.au:filter-listing+add-google-maps
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.realestate.com.au/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=realestate.com.au
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
const ogFetch = window.fetch;
window.fetch = (...args) => (async(args) => {
var result = await ogFetch(...args);
const text = await result.clone().text();
let json
try {
json = JSON.parse(text);
} catch (e) {
// not json
result.text = () => Promise.resolve().then(() => text);
return result;
}
if(json?.data?.rentMapSearch?.__typename === 'RentMapResolvedSearch' && Array.isArray(json?.data?.rentMapSearch?.results?.items)) {
const modified = json.data.rentMapSearch.results.items.filter( item => {
// an item is either an array or a single
if(Array.isArray(item.results)) {
item.results = item.results.filter(r => r.price.display.includes('$'));
return true;
} else {
return item.listing.price.display.includes('$');
}
});
console.log(`remove "${json.data.rentMapSearch.results.items.length - modified.length}" BS listings`)
json.data.rentMapSearch.results.items = modified;
result.json = () => Promise.resolve().then(() => json);
result.text = () => Promise.resolve().then(() => text);
} else {
result.json = () => Promise.resolve().then(() => json);
result.text = () => Promise.resolve().then(() => text);
}
return result;
})(args);
window.addEventListener('load', (event) => {
console.log('loaded script')
new MutationObserver(() => {
console.log('mutation')
Array.from(document.querySelectorAll('.TravelTimeRow__Input-sc-1ryp3u0-3>p:nth-child(2)')).forEach(r => {
const from = document.querySelector('.property-info-address').innerText
const dest = r.innerText
const link = document.createElement('a');
link.href = `https://www.google.com/maps/dir/?api=1&origin=${encodeURIComponent(from)}&destination=${dest}&travelmode=transit`;
link.innerText=dest.replaceAll('\n', '');
r.parentElement.appendChild(link);
r.parentElement.removeChild(r);
})
}).observe(document.querySelector('.styles__Content-sc-n4ryw0-3'), {childList: true})
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment