Created
December 24, 2021 17:22
-
-
Save l-portet/5a5fcb5dfa701aaa91fe2b63f0b7f705 to your computer and use it in GitHub Desktop.
Show the total price per person of an Airbnb listing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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