Skip to content

Instantly share code, notes, and snippets.

@StephenBrown2
Created March 14, 2025 18:53
Show Gist options
  • Save StephenBrown2/534c027cf2d58db5d7467a6fe7d42974 to your computer and use it in GitHub Desktop.
Save StephenBrown2/534c027cf2d58db5d7467a6fe7d42974 to your computer and use it in GitHub Desktop.
Real Estate Priced in BTC UserScript
// ==UserScript==
// @name Real Estate Priced in BTC
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Display all home prices in BTC.
// @author Phteven
// @match http*://www.zillow.com/*
// @match http*://www.redfin.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
async function getBTC() {
const url = "https://mempool.space/api/v1/prices";
const btc = await fetch(url).then(function (response) {
return response.json();
}).then(function (data) {
return data.USD;
}).catch(function (err) {
console.log('Fetch Error :-S', err);
})
return btc;
}
function getAllPrices() {
// Combined query selector for all possible price elements
return document.querySelectorAll(
'div.stat-block .statsValue,' + // Redfin
'.price-text,' + // Zillow
'[data-testid="primary-zestimate"],' + // Zestimate
'[data-test="property-card-price"],' + // Zillow Cards
'.bp-Homecard__Price--value' // Redfin Homepage Cards
);
}
// setBTC takes an element with a USD price, and btcPrice,
// and updates the element's innerHTML to show the BTC equivalent
// of the USD price
function setBTC(elem, btcPrice) {
if (!elem.textContent.includes('$')) {
return;
}
let usdPrice = Number(elem.textContent.replace(/[^0-9.-]+/g, ""));
let BTC = (usdPrice / btcPrice).toFixed(8) + ' ₿';
const inner = '<span title="' + elem.textContent + ' @ $' + btcPrice + '/BTC">' + BTC + '</span>';
elem.innerHTML = inner;
}
(async function() {
'use strict';
var btcPrice = await getBTC();
var runIt = function() {
var prices = getAllPrices();
for (let i = 0; i < prices.length; i++) {
const priceObj = prices[i];
setBTC(priceObj, btcPrice);
}
};
window.onload = runIt;
setInterval(runIt, 1000);
setInterval(async function() { btcPrice = await getBTC(); }, 60000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment