File indexing completed on 2024-12-29 04:51:03
0001 /* 0002 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 var localeMap = new Array(); 0008 localeMap['en_US'] = new Array(); 0009 localeMap['en_US']['localeMatch'] = /(?:thank you|details for booking)/; 0010 localeMap['en_US']['airportRegExp'] = /(.*) to (.*)/; 0011 localeMap['de_DE'] = new Array(); 0012 localeMap['de_DE']['localeMatch'] = /danke/; 0013 localeMap['de_DE']['airportRegExp'] = /(.*) nach (.*)/; 0014 0015 function parseHtmlBooking(doc) { 0016 var reservations = new Array(); 0017 0018 var bookingRef = doc.eval("//title")[0].content.match(/\((\w+)\)/); 0019 if (!bookingRef) 0020 return null; 0021 0022 // determine locale 0023 var introElem = doc.eval("//table[@class=\"email-wrapper\"]/tr[2]/td"); 0024 var locale = ""; 0025 for (var l in localeMap) { 0026 var m = introElem[0].content.match(localeMap[l]['localeMatch']); 0027 if (m) { 0028 locale = l; 0029 break; 0030 } 0031 } 0032 0033 var elems = doc.eval("//table[@class=\"ej-flight\"]"); 0034 for (var i = 0; i < elems.length; ++i) { 0035 var elem = elems[i]; 0036 var row = elem.firstChild; 0037 var res = JsonLd.newFlightReservation(); 0038 res.reservationNumber = bookingRef[1]; 0039 0040 var airports = row.recursiveContent.match(localeMap[locale]['airportRegExp']); 0041 res.reservationFor.departureAirport.name = airports[1]; 0042 0043 res.reservationFor.arrivalAirport.name = airports[2]; 0044 row = row.nextSibling; 0045 0046 var flightNum = row.recursiveContent.match(/([A-Z0-9]{2,3}) ?(\d{1,4})/); 0047 res.reservationFor.flightNumber = flightNum[2]; 0048 res.reservationFor.airline.iataCode = flightNum[1]; 0049 row = row.nextSibling; 0050 0051 var timeCell = row.eval(".//table/tr/td"); 0052 res.reservationFor.departureTime = JsonLd.toDateTime(timeCell[1].content.match(/\W* (.*)/)[1], "dd MMM HH:mm", locale); 0053 res.reservationFor.arrivalTime = JsonLd.toDateTime(timeCell[3].content.match(/\W* (.*)/)[1], "dd MMM HH:mm", locale); 0054 0055 elem = elem.nextSibling; 0056 if (elem.attribute("class") == "ej-pax") { 0057 var cell = elem.firstChild.firstChild; 0058 res.underName.name = cell.content; 0059 0060 cell = cell.nextSibling.firstChild.nextSibling; 0061 res.reservationFor.airplaneSeat = cell.content.match(/auto/) ? null : cell.content; 0062 } 0063 reservations.push(res); 0064 } 0065 0066 return reservations; 0067 } 0068 0069 function parsePdfBoardingPass(pdf, node, triggerNode) 0070 { 0071 var res = triggerNode.result[0]; 0072 0073 var page = pdf.pages[triggerNode.location]; 0074 var rightCol = page.textInRect(0.65, 0, 1, 0.25); 0075 var depName = rightCol.match(/(?:from|Flying)\n\([A-Z]{3}\) ([^]*?)\n(?:to|Going)/); 0076 if (depName) 0077 res.reservationFor.departureAirport.name = depName[1]; 0078 var arrName = rightCol.match(/(?:to|Going)\n\([A-Z]{3}\) ([^]*?)\ndeparts/); 0079 if (arrName) 0080 res.reservationFor.arrivalAirport.name = arrName[1]; 0081 var depTime = rightCol.match(/(?:departs|Flight)\n(\d\d:\d\d)/); 0082 if (depTime) 0083 res.reservationFor.departureTime = JsonLd.toDateTime(depTime[1], "hh:mm", "en"); 0084 0085 var leftCol = page.textInRect(0, 0, 0.3, 0.25); 0086 var boarding = leftCol.match(/(?:closes|Gate)\n(\d\d:\d\d)/); 0087 if (boarding) 0088 res.reservationFor.boardingTime = JsonLd.toDateTime(boarding[1], "hh:mm", "en"); 0089 0090 return res; 0091 }