// ==UserScript==
// @name Auto Fetch
// @namespace anonDeveloper
// @description This script will automagically blah blah blah
// @include https://ais.usvisa-info.com/en-ca/niv/schedule/*/appointment
// @require https://code.jquery.com/jquery-3.6.0.min.js
// ==/UserScript==
console.log('Hello From Auto Fetcher!');
async function ajax() {
console.log('Getting all available dates...');
let found = false;
for (let i = 0; i < 10000000; i++) {
if (found) {
break;
}
let href = $(location).attr('href');
const aprtId = href.split("/")[6];
// sending ais-usvisa to get the available dates
let appointmentUrl = 'https://ais.usvisa-info.com/en-ca/niv/schedule/' + aprtId + '/appointment/days/95.json?appointments[expedite]=false';
// 95.json refers to Vancouver, 89.json is Calgary
console.log(`Sending ${i} request to appointment Url: ${appointmentUrl}`);
$.ajax ({
type: 'GET',
url: appointmentUrl,
dataType: 'JSON',
success: function (apiJson) {
for (let i = 0; i <= 5; i++) {
let availableDate = new Date(apiJson[i].date);
console.log(`Current time ${new Date()}, the ${i}th available date is: " ${availableDate}`);
var current = new Date();
var tar1 = new Date("2022-09-24");
var tar2 = new Date("2022-10-15");
var tar3 = new Date("2022-11-07");
if (availableDate <= tar1 || tar2 <= availableDate && availableDate <= tar3) {
const audio = new Audio("https://cdn.freesound.org/previews/91/91926_7037-lq.mp3");
audio.play();
alert(`Congratulations! Found a target date ${availableDate}`);
found = true;
break;
} else {
console.log("No target date found, continue.");
}
}
} // success
}); // ajax
console.log(`Waiting ${60} seconds...`);
await sleep(60000);
}
console.log('Done');
}
$(document).ready(function() {
console.log('Ready...');
ajax();
});
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}