Skip to content

Instantly share code, notes, and snippets.

@koelling
Last active January 6, 2020 13:19
Show Gist options
  • Save koelling/2889cd5047f7d86dd35803aa6d12aaa9 to your computer and use it in GitHub Desktop.
Save koelling/2889cd5047f7d86dd35803aa6d12aaa9 to your computer and use it in GitHub Desktop.
Paste travel data from a spreadsheet into the gov.uk citizenship application pages. Make a four column spreadsheet with departure date (DD/MM/YYYY), return date, country and reason, then copy and paste the the first row into the page. The script will automatically submit the form and then return to it, ready for the next row.
// ==UserScript==
// @name gov.uk - paste travel dates
// @description Paste travel data from a spreadsheet into the gov.uk citizenship application pages. Make a four column spreadsheet with departure date (DD/MM/YYYY), return date, country and reason, then copy and paste the the first row into the page. The script will automatically submit the form and then return to it, ready for the next row. Disable the userscript when done adding additional trips.
// @match https://visas-immigration.service.gov.uk/*
// @version 1
// @grant none
// @run-at document-end
// ==/UserScript==
function fillDate(date, prefix) {
const date_parts = date.split('/')
if(date_parts.length != 3) {
return false;
}
document.getElementById(prefix + 'day').value = date_parts[0];
document.getElementById(prefix + 'month').value = date_parts[1];
document.getElementById(prefix + 'year').value = date_parts[2];
return true;
}
function fill(txt) {
const parts = txt.split('\t')
if(parts.length != 4) {
return false;
}
if(!fillDate(parts[0], 'departureDateOfTrip_')) {
return false;
}
if(!fillDate(parts[1], 'returnDateOfTrip_')) {
return false;
}
document.getElementById('countryVisited_ui').value = parts[2];
document.getElementById('reasonForTrip').value = parts[3];
return true;
}
if(document.title.startsWith('Application - Details of trips outside the UK')) {
document.addEventListener('paste', (event) => {
const paste = (event.clipboardData || window.clipboardData).getData('text');
if(fill(paste)) {
document.getElementById('submit').click();
} else {
alert('Failed to process pasted text. Should be departure date (DD/MM/YYYY), return date, country and reason, separated by tabs.');
}
});
}
if(document.title == 'Application - Additional trips outside the UK') {
const addAnother = document.getElementById('addAnother_true');
if(addAnother) {
addAnother.checked = true;
document.getElementById('submit').click();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment