add support for motorcycles to the kbb.js script

This commit is contained in:
Robert Dyer
2025-05-03 14:24:31 -05:00
parent 4741dee84f
commit c30b429f96
2 changed files with 25 additions and 6 deletions
+12 -2
View File
@@ -18,8 +18,15 @@ async function getKBB(URL) {
const html = await response.text();
const dom = new jsdom.JSDOM(html);
const kbbText = dom.window.document.getElementById('PriceAdvisor').getElementsByTagName('text')[3].textContent;
return parseInt(kbbText.replace('$', '').replaceAll(',', '')) * 100;
const advisor = dom.window.document.getElementById('PriceAdvisor');
if (advisor) {
const kbbText = advisor.getElementsByTagName('text')[3].textContent;
return parseInt(kbbText.replace('$', '').replaceAll(',', '')) * 100;
}
const regex = /"value":\s*(\d+)/;
const match = html.match(regex);
return parseInt(match[1]) * 100;
}
(async function() {
@@ -49,6 +56,9 @@ async function getKBB(URL) {
const options = getTagValue(note, 'kbbOptions');
if (options) URL += `&optionids=${options}`;
const pricetype = getTagValue(note, 'kbbPriceType');
if (pricetype) URL += `&pricetype=${pricetype}`;
console.log('Fetching KBB for account:', account.name);
const kbb = await getKBB(URL);