-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
211 additions
and
144 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,68 @@ | ||
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { | ||
if (request.action === "getDestinations") { | ||
const origin = request.origin; | ||
|
||
// Find the input fields. | ||
const firstInputField = document.querySelector('input[aria-owns="autocomplete-result-list-1"]'); | ||
const secondInputField = document.querySelector('input[aria-owns="autocomplete-result-list-2"]'); | ||
setTimeout(() => { | ||
const routePattern = /"routes":\[(.*?)\].*?"isOneWayFlightsOnly"/gms; | ||
const pageContent = document.head.innerHTML; | ||
const match = pageContent.match(routePattern); | ||
if (match && match[0]) { | ||
try { | ||
const routesJson = `{"routes":${match[0].split('"routes":')[1].split(',"isOneWayFlightsOnly"')[0]}}`; | ||
const routesData = JSON.parse(routesJson); | ||
|
||
const firstList = document.querySelector('ul#autocomplete-result-list-1'); | ||
const secondList = document.querySelector('ul#autocomplete-result-list-2'); | ||
const originAirport = request.origin; | ||
const routesFromOrigin = routesData.routes.find(route => route.departureStation.id === originAirport); | ||
|
||
// Clear both input fields. | ||
[firstInputField, secondInputField].forEach((inputField, index) => { | ||
if (inputField) { | ||
const clearButton = inputField.parentElement.querySelector('button.CvoClose'); | ||
if (clearButton) { | ||
clearButton.click(); | ||
} else { | ||
console.error(`Clear button not found for input field ${index + 1}`); | ||
if (routesFromOrigin && routesFromOrigin.arrivalStations) { | ||
const destinationIds = routesFromOrigin.arrivalStations.map(station => station.id); | ||
console.log(`Routes from ${originAirport}:`, destinationIds); | ||
sendResponse({ success: true, destinations: destinationIds }); | ||
} else { | ||
console.log(`No routes found from ${originAirport}`); | ||
sendResponse({ success: false, error: `No routes found from ${originAirport}` }); | ||
} | ||
} catch (error) { | ||
console.error("Error parsing routes data:", error); | ||
sendResponse({ success: false, error: "Failed to parse routes data" }); | ||
} | ||
} else { | ||
console.error(`Input field ${index + 1} not found`); | ||
sendResponse({ success: false, error: "No routes data found" }); | ||
} | ||
}); | ||
|
||
if (firstInputField && secondInputField) { | ||
firstInputField.focus(); | ||
firstInputField.value = origin; | ||
firstInputField.dispatchEvent(new Event('input', { bubbles: true })); | ||
|
||
setTimeout(() => { | ||
firstInputField.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true })); | ||
setTimeout(() => { | ||
firstInputField.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true })); | ||
|
||
|
||
setTimeout(() => { | ||
secondInputField.focus(); | ||
secondInputField.click(); | ||
secondInputField.dispatchEvent(new Event('input', { bubbles: true })); | ||
|
||
setTimeout(() => { | ||
if (secondList) { | ||
const destinations = Array.from(secondList.querySelectorAll('li')) | ||
.map(li => { | ||
const text = li.textContent.trim(); | ||
const match = text.match(/\(([A-Z]{3})\)/); | ||
return match ? match[1] : text; | ||
}); | ||
sendResponse({ destinations: destinations }); | ||
} else { | ||
sendResponse({ error: 'Destination list not found' }); | ||
} | ||
}, 500); | ||
}, 500); | ||
}, 100); | ||
}, 500); | ||
} else { | ||
sendResponse({ error: 'Input fields not found' }); | ||
} | ||
}, 1000); | ||
return true; | ||
} | ||
}); | ||
|
||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { | ||
if (request.action === "getDynamicUrl") { | ||
setTimeout(() => { | ||
const pageContent = document.head.innerHTML; | ||
const match = pageContent.match(/"searchFlight":"https:\/\/multipass\.wizzair\.com[^"]+\/([^"]+)"/); | ||
if (match && match[1]) { | ||
const uuid = match[1]; | ||
const dynamicUrl = `https://multipass.wizzair.com/w6/subscriptions/json/availability/${uuid}`; | ||
sendResponse({dynamicUrl: dynamicUrl}); | ||
} else { | ||
console.log('Dynamic ID not found in page content'); | ||
sendResponse({error: "Dynamic ID not found"}); | ||
} | ||
}, 1000); | ||
return true; | ||
} | ||
}); | ||
|
||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { | ||
if (request.action === "getHeaders") { | ||
const headers = {}; | ||
performance.getEntriesByType("resource").forEach(entry => { | ||
if (entry.name.includes("multipass.wizzair.com")) { | ||
entry.serverTiming.forEach(timing => { | ||
if (timing.name.startsWith("request_header_")) { | ||
const headerName = timing.name.replace("request_header_", ""); | ||
headers[headerName] = timing.description; | ||
} | ||
}); | ||
} | ||
}); | ||
sendResponse({headers: headers}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.