Skip to content

Commit

Permalink
V1.1 (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
vloss3 authored Sep 28, 2024
2 parents 6aa9e33 + bc3ba98 commit cc507d9
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 144 deletions.
39 changes: 0 additions & 39 deletions background.js

This file was deleted.

110 changes: 57 additions & 53 deletions content.js
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});
}
});
3 changes: 0 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
"default_popup": "popup.html",
"default_icon": "icon.png"
},
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": ["https://multipass.wizzair.com/*"],
Expand Down
6 changes: 4 additions & 2 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
<h1 class="is-size-5">Wizz AYCF Route Finder</h1>
<p class="is-size-7 mt-2">
<a href="https://github.com/vloss3/wizz-aycf-route-finder" target="_blank">GitHub</a> |
<a href="https://discord.gg/k3eRaSBez4" target="_blank">Feedback (Discord)</a>
<a href="https://discord.gg/k3eRaSBez4" target="_blank">Feedback (Discord)</a> |
<a href="https://ko-fi.com/vloss3/?hidefeed=true&widget=true&embed=true&preview=true" target="_blank">☕️ Tips</a>
</p>
</div>
<div class="field">
Expand All @@ -47,7 +48,8 @@ <h1 class="is-size-5">Wizz AYCF Route Finder</h1>
</div>
</div>
</div>
<p class="is-size-6 mt-3"><b>Note:</b> First go to the Wizzair Multipass page, enter a random route and press Search. Then you can use this extension.</p>
<p class="is-size-6 mt-3"><b>Disclaimer:</b> This extension is not affiliated with Wizz Air or its partners in any way. It is a personal project to help Multipass users like me find available routes.</p>
<p class="is-size-6 mt-3">Please use responsibly and at your own risk. Doing too many searches in a short period of time will result in temporary rate limiting.</p>
</section>
<script src="popup.js"></script>
</body>
Expand Down
Loading

0 comments on commit cc507d9

Please sign in to comment.