Jefreesujit / VISA Interview Availability Checker

// ==UserScript==
// @name         VISA Interview Availability Checker
// @namespace    http://tampermonkey.net/
// @version      1.0
// @copyright    2018, Jefreesujit (https://openuserjs.org/users/Jefreesujit)
// @license      BSD-2-Clause
// @description  A simple script to check for Visa interview availability date slots
// @author       Jefreesujit
// @match        https://cgifederal.secure.force.com/applicanthome
// @grant        none
// ==/UserScript==

let curDate = new Date("07/20/2018"),
  emailParams = {
    "service_id": "default_service",
    "template_id": "template",
    "user_id": "user"
  },
  intervalId;

function sendEmail(messageBody, availDate) {
  emailParams.template_params = {
    "message_html": messageBody,
    "to_name": "Sidheswar"
  };
  console.log(emailParams);
  $.ajax({
    url: "https://api.emailjs.com/api/v1.0/email/send",
    type: 'POST',
    contentType: "application/json",
    data: JSON.stringify(emailParams),
    success: function () {
      // clearInterval(intervalId);
      curDate = availDate;
      alert(messageBody);
    },
    error: errorhandler
  });
}

function successHandler(data) {
  let rawText = $(data).find('.leftPanelText').text(),
    dateString = rawText.substring(rawText.indexOf('Is ') + 3),
    availDate = new Date(dateString);
  if (availDate < curDate) {
    console.log(rawText);
    sendEmail(rawText, availDate);
  }
  else {
    console.log(dateString);
  }
}

function errorhandler(XMLHttpRequest, textStatus, errorThrown) {
  console.log('err', errorThrown);
}

(function () {
  intervalId = setInterval(function () {
    $.ajax({
      url: "https://cgifederal.secure.force.com/applicanthome",
      xhrFields: {
        withCredentials: true
      },
      success: successHandler,
      error: errorhandler
    });
  }, 10000);
})();