Skip to content

Instantly share code, notes, and snippets.

@JustinShenk
Last active April 25, 2018 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JustinShenk/ee522dac8d140e3a57486c8354804c84 to your computer and use it in GitHub Desktop.
Save JustinShenk/ee522dac8d140e3a57486c8354804c84 to your computer and use it in GitHub Desktop.
Schedule me at the Auslanderbehörde Osnabrück
/**
* @author Justin Shenk <shenk.justin@gmail.com>
*
* This script schedules the next available meeting in a given month by
* continuous reloading and automatically filling out a form.
*
* INSTRUCTIONS:
* - Replace the personal details below with your information.
* - Navigate to the scheduling site.
* - Select iFrame as context: In Firefox, open the Web Console (Tools > Web
* Developer > Web Console) and paste the following. If you using Chrome, omit
* the first line, open the console (View > Developer > JavaScript Console) and
* in the drop-down menu at the top of the console, change 'top' to 'true', then
* paste the rest.
* More info on issue in Chrome: https://stackoverflow.com/a/38903747
* NOTE: This is for educational purposes only.
* NO GUARANTEES COME WITH THIS SCRIPT. BY USING THIS SCRIPT YOU ACCEPT ALL
* LIABILITY AND RESPONSIBILITY.
*/
// Firefox-only: change directory to iFrame BEFORE running the script:
// cd(document.getElementsByTagName('iframe')[0]);
var firstName = 'MYFIRSTNAME';
var lastName = 'MYLASTNAME';
var phone = '0176123456';
var email = 'MYEMAIL@gmail.com';
var targetMonth = ''; // all-caps string, eg. OCTOBER
var autoSubmit = false; // submit form automatically (not yet tested)
var delay = 2000; // milliseconds
var monthTimerID = 0;
var timeTimerID = 0;
var confirmed = $(".confirmation_section").css('display') !== 'none';
function showButton() {
console.log("show apply button");
// Select booking for one person
$("#service_apply_button").css("display", "block");
$("#service_option423").addClass("active");
$('select>option:eq(1)').attr('selected', true);
$("#service_apply_button").click();
var isVisible = $("#service_apply_button").css("display") === 'block';
if (!isVisible) {
console.log("try showing apply button again");
setTimeout(showButton, delay);
} else {
setTimeout(selectMonth, delay);
}
}
function fillOutForm() {
console.log("filling in my information");
$("input#register_first_name").val(firstName);
$("input#register_last_name").val(lastName);
$("input#register_telephone").val(phone);
$("input#register_email").val(email);
$("input#print_ticket").prop('checked', true);
if (autoSubmit) {
setTimeout(submitForm, delay);
}
}
function submitForm() {
console.log("submitting the form");
$("#booking_button").click();
}
function selectTime() {
console.log("picking first time slot");
$("#times_container div").eq(0).click();
confirmed = $(".confirmation_section").css('display') !== 'none';
if (confirmed) {
console.log("time selection confirmed");
clearInterval(timeTimerID);
}
setTimeout(fillOutForm, delay);
}
function selectDate() {
var timeslots = $("#times_container div").length;
if (timeslots > 0) {
setTimeout(selectTime, 1000);
} else {
console.log("picking first date");
$(".ui-datepicker-calendar a").eq(0).click();
setTimeout(selectDate, delay);
}
}
function nextMonth(targetMonth) {
var month = $(".ui-datepicker-month").get(0).innerHTML;
if (targetMonth === '') targetMonth = month;
if (month !== targetMonth) {
$(".ui-datepicker-next").click();
return false;
} else {
console.log("picking a date in " + targetMonth);
clearInterval(monthTimerID);
monthTimerID = null;
return true;
}
}
function clickApply() {
var waitingBox = $("#waiting_overlay").css("display") === "block";
if (waitingBox) {
console.log("waiting for overlay to disappear");
return false;
}
console.log("clicking apply");
$("#service_apply_button").click();
setTimeout(function() {
var datesAvailable = $(".ui-datepicker-calendar a").length;
var success = (datesAvailable > 0);
if (success) {
console.log("dates available!");
}
return success;
}, 1500);
}
function selectMonth() {
console.log("selecting month");
if ($(".ui-datepicker-month").length !== 1) {
console.log("month not visible, try extending wait time");
return;
}
var month = $(".ui-datepicker-month").get(0).innerHTML;
if (month !== targetMonth) { // click through months until reached
monthTimerID = setInterval(function() {
console.log("seeking " + targetMonth);
var success = nextMonth(targetMonth);
if (success) {
console.log("found " + targetMonth);
apply();
}
}, delay);
} else { // current month selected
console.log("found " + targetMonth);
clearInterval(monthTimerID);
monthTimerID = null;
apply();
}
}
function apply() {
var waitingBox = $("#waiting_overlay").css("display") === "block";
if (waitingBox) {
setTimeout(apply, delay); // wait until 'waiting' box disappears
return;
}
if (monthTimerID !== null) { // wait until target month found
console.log("waiting to find month");
setTimeout(apply, delay);
return;
}
// click 'apply' until a date can be selected
var datesAvailable = $(".ui-datepicker-calendar a").length;
if (datesAvailable < 1) {
console.log("click apply until date is available");
var success = clickApply();
if (!success) {
// re-enter
setTimeout(apply, delay);
} else {
console.log("dates available!");
setTimeout(selectDate, delay);
}
} else {
console.log("dates available!");
setTimeout(selectDate, delay);
}
}
function start() {
// start cascade
setTimeout(showButton, delay);
return "starting scheduleMe";
}
start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment