Skip to content

Instantly share code, notes, and snippets.

@l-portet
Created December 24, 2021 17:22
Show Gist options
  • Save l-portet/5a5fcb5dfa701aaa91fe2b63f0b7f705 to your computer and use it in GitHub Desktop.
Save l-portet/5a5fcb5dfa701aaa91fe2b63f0b7f705 to your computer and use it in GitHub Desktop.
Show the total price per person of an Airbnb listing
// Script that shows the total price of an Airbnb listing divided by the number of persons
// Inject it in any Airbnb search page (https://airbnb.com/s/*)
!function() {
function runner() {
const persons = +new URL(window.location.href).searchParams.get('adults');
if (!persons) {
return;
}
const $prices = [...document.querySelectorAll('button > div > div > span[aria-hidden=true]')];
const sep = `—`
for (const $price of $prices) {
const [initialStr] = $price.textContent.split(sep);
const price = +initialStr.replace(/\D/g,'');
const pricePerPerson = Math.round(price / persons * 100) / 100;
$price.textContent = `${initialStr} ${sep} ${pricePerPerson}/pers`
}
}
setInterval(runner, 1000);
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment