Facebook
From Lousy Meerkat, 1 Year ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 121
  1. // ==UserScript==
  2. // @name Auto Fetch
  3. // @namespace anonDeveloper
  4. // @description This script will automagically blah blah blah
  5. // @include https://ais.usvisa-info.com/en-ca/niv/schedule/*/appointment
  6. // @require https://code.jquery.com/jquery-3.6.0.min.js
  7.  
  8. // ==/UserScript==
  9.  
  10. console.log('Hello From Auto Fetcher!');
  11.  
  12.  
  13.  
  14. async function ajax() {
  15.         console.log('Getting all available dates...');
  16.   let found = false;
  17.           for (let i = 0; i < 10000000; i++) {
  18.         if (found) {
  19.           break;
  20.         }
  21.      
  22.         let href = $(location).attr('href');
  23.         const aprtId = href.split("/")[6];
  24.  
  25.        
  26.         // sending ais-usvisa to get the available dates
  27.        
  28.         let appointmentUrl = 'https://ais.usvisa-info.com/en-ca/niv/schedule/' + aprtId + '/appointment/days/95.json?appointments[expedite]=false';
  29.         // 95.json refers to Vancouver, 89.json is Calgary
  30.         console.log(`Sending ${i} request to appointment Url: ${appointmentUrl}`);
  31.         $.ajax ({
  32.           type:       'GET',
  33.           url:         appointmentUrl,
  34.           dataType:   'JSON',
  35.           success:    function (apiJson) {
  36.            
  37.             for (let i = 0; i <= 5; i++) {
  38.               let availableDate = new Date(apiJson[i].date);
  39.               console.log(`Current time ${new Date()}, the ${i}th available date is: " ${availableDate}`);
  40.              
  41.               var current = new Date();
  42.               var tar1 = new Date("2022-09-24");
  43.               var tar2 = new Date("2022-10-15");
  44.               var tar3 = new Date("2022-11-07");
  45.              
  46.               if (availableDate <= tar1 || tar2 <= availableDate && availableDate <= tar3) {
  47.                 const audio = new Audio("https://cdn.freesound.org/previews/91/91926_7037-lq.mp3");
  48.                                                         audio.play();
  49.                 alert(`Congratulations! Found a target date ${availableDate}`);
  50.                 found = true;
  51.                 break;
  52.               } else {
  53.                 console.log("No target date found, continue.");
  54.               }
  55.             }
  56.           }  // success
  57.         }); // ajax
  58.      
  59.         console.log(`Waiting ${60} seconds...`);
  60.         await sleep(60000);
  61.        
  62.        
  63.     }
  64.     console.log('Done');
  65. }
  66.  
  67. $(document).ready(function() {
  68.   console.log('Ready...');
  69.   ajax();
  70.  
  71. });
  72.  
  73.  
  74.  
  75. function sleep(ms) {
  76.     return new Promise(resolve => setTimeout(resolve, ms));
  77. }
  78.  
  79.