Skip to content

Instantly share code, notes, and snippets.

@smirea
Last active July 6, 2022 15:53
Show Gist options
  • Save smirea/d980e6a82ec7d99604fa9bea50a2eeb1 to your computer and use it in GitHub Desktop.
Save smirea/d980e6a82ec7d99604fa9bea50a2eeb1 to your computer and use it in GitHub Desktop.
window.airbnbPostToSheet = (WEBHOOK) => {
if (!WEBHOOK) return alert('ERROR: WEBHOOK not set');
const $$ = sel => Array.from(document.querySelectorAll(sel) || []);
const $ = document.querySelector.bind(document);
$('.v7aged4')?.click(); // open amenities popup
setTimeout(() => {
const amenities = $$('._gw4xx4').map(x => x.textContent.trim().toLowerCase()).join(' ');
const city = $('._9xiloll')?.textContent?.split(', ') || ['—', '—'];
const country = city.pop();
const info = $('[data-section-id=OVERVIEW_DEFAULT] ol')?.textContent.trim().replace(/[^0-9\s.·]/ig, '').split(' · ').slice(1).map(x => x.trim());
const row = {
URL: location.href,
Name: $(`[data-section-id='TITLE_DEFAULT'] div`)?.textContent.split('󰀄')[0],
Rating: $('[data-section-id=REVIEWS_DEFAULT] h2 [dir=ltr]')?.textContent.trim(),
City: city[0],
Country: country,
Address: $('[data-section-id=LOCATION_DEFAULT] ._152qbzi')?.textContent.trim(),
'Total $': $$('._1k4xcdh')?.pop()?.textContent?.slice(1).replace(',', ''),
'$ / Day': $$('._tyxjp1').pop().textContent.slice(1).replace(',', ''),
'Bedrooms': info[0],
'Beds': info[1],
'Bathrooms': info[2],
'AC': !!amenities.includes('air conditioning') ? 'yes' : 'no',
'Pool': !!amenities.match(/\bpool\b/) ? 'yes' : 'no',
};
console.log(JSON.stringify(row, null, 4));
$('[aria-label=Close]')?.click();
const params = Object.entries(row)
.map(v => encodeURIComponent(v[0]) + '=' + encodeURIComponent(v[1]?.trim() || '—'))
.join('&');
fetch(WEBHOOK + '&' + params)
.then(() => alert('logged into sheet'))
.catch(() => alert('welp shite, did not work'));
}, 100);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment