File indexing completed on 2024-12-29 04:51:02
0001 /* 0002 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 function parseHtml(doc) { 0008 var elems = doc.eval("/html/body/table/tr/td/table/tr/td/table"); 0009 0010 var bookingRef = (doc.eval('//*[@id="t-w--courtesy-message"]')[0] ?? elems[1]).recursiveContent.match(/Reference\s*(\S+)/); 0011 if (!bookingRef) 0012 return null; 0013 0014 var res = JsonLd.newLodgingReservation(); 0015 res.reservationNumber = bookingRef[1]; 0016 0017 var hotelInfo = (doc.eval('//*[@id="t-w--hotel-info"]')[0] ?? elems[3]).eval(".//table//table"); 0018 var row = hotelInfo[0].firstChild; 0019 var addr = row.recursiveContent.match(/([^\n]+)[\n\s]+([^\n]+)\n\s*([^\n]+)/); 0020 res.reservationFor.name = addr[1]; 0021 res.reservationFor.address.streetAddress = addr[2]; 0022 res.reservationFor.address.addressLocality = addr[3]; 0023 row = row.nextSibling; 0024 res.reservationFor.geo = JsonLd.toGeoCoordinates(doc.eval('//a[starts-with(@href,"http://maps.google.")]')[0].attribute("href")); 0025 0026 var links = hotelInfo[1].eval(".//a"); 0027 for (var i = 0; i < links.length; ++i) { 0028 var url = links[i].attribute("href"); 0029 if (url.startsWith("tel:")) 0030 res.reservationFor.telephone = url.substr(4); 0031 else if (url.startsWith("mailto:")) 0032 res.reservationFor.email = url.substr(7); 0033 else 0034 res.reservationFor.url = url; 0035 } 0036 0037 var booking = elems[5].firstChild.firstChild.firstChild; 0038 row = booking.firstChild; 0039 res.underName.name = (doc.eval('//*[@id="t-summary--guest-name"]/tr')[0] ??row).firstChild.nextSibling.content; 0040 row = row.nextSibling.nextSibling.nextSibling; 0041 0042 const checkin = (doc.eval('//*[@id="t-summary--check-in"]/tr')[0] ?? row).recursiveContent.match(/from (\d{1,2}:\d{2}(?: AM| PM)?)\)\s*(.*)/); 0043 res.checkinTime = JsonLd.toDateTime(checkin[2] + checkin[1], ["dddd, MMMM dd, yyyyhh:mm", "dddd, MMMM dd, yyyyhh:mm AP"], "en"); 0044 row = row.nextSibling; 0045 const checkout = (doc.eval('//*[@id="t-summary--check-out"]/tr')[0] ??row).recursiveContent.match(/until (\d{1,2}:\d{2}(?: AM| PM)?)\)\s*(.*)/); 0046 res.checkoutTime = JsonLd.toDateTime(checkout[2] + checkout[1], ["dddd, MMMM dd, yyyyhh:mm", "dddd, MMMM dd, yyyyhh:mm AP"], "en"); 0047 0048 res.modifyReservationUrl = doc.eval('//a[@target="_blank"]')[0].attribute('href'); 0049 0050 const price = doc.eval('//*[@id="t-h--total-price"]')[0]; 0051 if (price) 0052 ExtractorEngine.extractPrice(price.recursiveContent, res); 0053 return res; 0054 }