// ==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)); }