Skip to content

Instantly share code, notes, and snippets.

@bobbzorzen
Created May 14, 2025 11:44
Show Gist options
  • Save bobbzorzen/ea39d1a29164becd44b2a22483ca9f22 to your computer and use it in GitHub Desktop.
Save bobbzorzen/ea39d1a29164becd44b2a22483ca9f22 to your computer and use it in GitHub Desktop.
Script set used to automatically refresh list of available practical test times available at trafikverket. This lets you find test times faster and easier
// How to use: Login to trafikverket's boka prov site
// Fill in the towns you want to do the test in and the rest of the settings so you get an initial search
// Update the referenceDate option in the bottom to the latest date you want to search for (set this to your current booked time)
// Copy paste all the code in this file (ctrl + a + c) into the console of the trafikverket page
// Now it will change between no gear option and manual gear option every thirty seconds, which will cause a refresh of the search every 60 seconds
// If it finds a newer time than specified it will log a bunch of green checkboxes
// If it does NOT find a newer time than specified it will log a red checkbox
// If you manage to snag a newer time, just update the referenceDate variable to the new date and the script should automatically check against the new time
// If you want to check against automatic car times, just change '#vehicle-select option:nth-child(2)' to '#vehicle-select option:nth-child(3)' and it should work just as well
// Remember that chrome generally pauses tabs if they aren't visible, so minimizing it may pause it after a few minutes, i usually just keep the console and page on a separate screen so i always see it
function parseCustomDateTime(input) {
const normalized = input.replace(/\u00A0/g, ' ').trim();
return new Date(normalized);
}
function logDateComparison() {
const container = document.getElementById('results-desktop');
if (!container) {
return; // No results container found, returning
}
const firstPanel = container.querySelector('.panel');
if (!firstPanel) {
return; // No panel found, returning
}
const panelBody = firstPanel.querySelector('.panel-body');
const strong = panelBody?.querySelector('strong');
if (strong) {
const dateText = strong.textContent;
const parsedDate = parseCustomDateTime(dateText);
if (parsedDate < referenceDate) {
console.log(`✅ Date is newer: ${dateText}`);
console.log(`✅ Date is newer: ${dateText}`);
console.log(`✅ Date is newer: ${dateText}`);
console.log(`✅ Date is newer: ${dateText}`);
console.log(`✅ Date is newer: ${dateText}`);
console.log(`✅ Date is newer: ${dateText}`);
console.log(`✅ Date is newer: ${dateText}`);
} else {
console.log(`❌ Date is not newer: ${parsedDate.toISOString()}`);
}
} else {
console.warn('strong element not found inside panel-body');
}
}
function clickTimeoutOkButton() {
const button = document.getElementById('ok_button_timeOut');
if (button) {
button.click();
}
}
function updateGearSelection() {
const selectElement = document.getElementById('vehicle-select');
const noGearOption = document.querySelector('#vehicle-select option:nth-child(1)');
const manualOption = document.querySelector('#vehicle-select option:nth-child(2)');
if (!selectElement || !manualOption || !noGearOption) return;
// Check if "manual-gear-option" is currently selected
if (selectElement.value === manualOption.value) {
selectElement.value = noGearOption.value;
} else {
selectElement.value = manualOption.value;
}
// Trigger change event if needed
selectElement.dispatchEvent(new Event('change'));
}
let referenceDate = new Date("2025-05-19 00:01:01"); // Date of time you want to compare to, change this every time you've managed to snag a newer time
const refreshIntervalId = setInterval(updateGearSelection, 30000); // Changes gear selection every 30 seconds, causing reload of list every 60 seconds
const confirmCacheIntervalId = setInterval(clickTimeoutOkButton, 10000); // Tries to close the timout window every 10 seconds, refreshing the current session
const logIntervalId = setInterval(logDateComparison, 30000); // Checks if the current newest time is closer than "referenceDate" and triggers a couple of console logs if so
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment