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 main(html) { 0008 var reservations = new Array(); 0009 0010 const bookingRef = html.root.recursiveContent.match(/Booking Reference: ([A-Z0-9]{6})/)[1]; 0011 0012 var row = html.eval("//table//table//table//table[2]/tr")[0].nextSibling; 0013 var passengers = row.recursiveContent.split('\n'); 0014 0015 while (row && !row.isNull) { 0016 if (row.firstChild.recursiveContent != "Flight") { 0017 row = row.nextSibling; 0018 continue; 0019 } 0020 0021 var res = JsonLd.newFlightReservation(); 0022 res.reservationNumber = bookingRef; 0023 0024 var flight = row.firstChild.nextSibling.recursiveContent.match(/(\S{2})(\d{4}) - \S{3} (.+)/); 0025 res.reservationFor.flightNumber = flight[2]; 0026 res.reservationFor.airline.iataCode = flight[1]; 0027 0028 row = row.nextSibling; 0029 var dep = row.firstChild.nextSibling.recursiveContent.match(/([^\)]+) \((\S{3})\) (\d{2}:\d{2})/); 0030 res.reservationFor.departureAirport.name = dep[1]; 0031 res.reservationFor.departureAirport.iataCode = dep[2]; 0032 res.reservationFor.departureTime = JsonLd.toDateTime(flight[3] + dep[3], "dd MMM yyyyhh:mm", "en"); 0033 0034 row = row.nextSibling; 0035 var arr = row.firstChild.nextSibling.recursiveContent.match(/([^\)]+) \((\S{3})\) (\d{2}:\d{2})/); 0036 res.reservationFor.arrivalAirport.name = arr[1]; 0037 res.reservationFor.arrivalAirport.iataCode = arr[2]; 0038 res.reservationFor.arrivalTime = JsonLd.toDateTime(flight[3] + arr[3], "dd MMM yyyyhh:mm", "en"); 0039 0040 row = row.nextSibling.nextSibling; 0041 res.reservationFor.airline.name = row.firstChild.nextSibling.recursiveContent; 0042 0043 for (i in passengers) { 0044 var r = JsonLd.clone(res); 0045 r.underName.name = passengers[i]; 0046 reservations.push(r); 0047 } 0048 0049 row = row.nextSibling; 0050 } 0051 0052 return reservations; 0053 } 0054 0055 function extractPdfBoardingPass(pdf, node, barcode) { 0056 let res = barcode.result[0]; 0057 const text = pdf.pages[barcode.location].text; 0058 const times = text.match(/(\d\d:\d\d) +\d+[A-Z] +(\d\d:\d\d)/); 0059 res.reservationFor.departureTime = JsonLd.toDateTime(times[1], 'hh:mm', 'en'); 0060 res.reservationFor.boardingTime = JsonLd.toDateTime(times[2], 'hh:mm', 'en'); 0061 return res; 0062 0063 }