Skip to content

Instantly share code, notes, and snippets.

@kandrejevs
Created July 24, 2019 20:25
Show Gist options
  • Select an option

  • Save kandrejevs/5c44fba7c68321872e4e13fc11e86e3c to your computer and use it in GitHub Desktop.

Select an option

Save kandrejevs/5c44fba7c68321872e4e13fc11e86e3c to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://e.csdd.lv/examp/
// @grant none
// @require https://code.jquery.com/jquery-3.3.1.min.js
// @require https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js
// @require https://cdn.emailjs.com/sdk/2.2.4/email.min.js
// @require http://momentjs.com/downloads/moment.js
// ==/UserScript==
(function() {
'use strict';
var step = 0;
var currentExamDate = moment("2018-10-04");
getStep();
switch(step) {
case 1:
applyForExam();
break;
case 2:
selectLocation();
break;
case 3:
setReason();
break;
case 4:
setExamType();
break;
case 5:
showAvailableDates();
break;
case 6:
break;
default:
console.log("something went wrong")
}
// functions finds in which step we are
function getStep() {
var title = $(document).find('h2').text();
if (title === "Pieteiktie eksāmeni:") {
step = 1;
console.log("Step 1 detected");
return;
}
title = $(document).find('td.value').text();
if (_.includes(title, "CSDD nodaļa:")) {
step = 2;
console.log("Step 2 detected");
return;
}
if (_.includes(title, "Iemesls:")) {
step = 3;
console.log("Step 3 detected");
return;
}
if (_.includes(title, "Eksāmena veids:")) {
step = 4;
console.log("Step 4 detected");
return;
}
if (_.includes(title, "Eksāmena datums:")) {
step = 5;
console.log("Step 5 detected");
return;
}
}
function applyForExam() {
$("#uniforma").find("#confirmNor").click();
}
function selectLocation() {
$('#nodala option[value=1]').prop('selected', true);
$("#uniforma").find("#find").click();
}
function setReason() {
$("#uniforma").find("input#6").click();
$("#uniforma").find("#find").click();
}
function setExamType() {
$("#uniforma").find("input#3").click();
$("#uniforma").find("#find").click();
}
function showAvailableDates() {
var dates = $("#uniforma").find("#datums").find("option");
_.forEach(dates, function(date) {
var words = _.words($(date).text());
console.log($(date).text());
var newDate = moment(words[2] + "-" + words[1] + "-" + words[0]);
if (newDate < currentExamDate && words[5] > 0) {
console.log("Found a free spot");
sendEmail(date);
}
});
setTimeout(function(){
goToStart();
}, 1000 * 60 * 1);
}
function goToStart() {
window.location.href = 'https://e.csdd.lv/examp/';
}
function sendEmail(date) {
emailjs.init("user_9a6sRfO2h3HrZRelLFwQV");
var template_params = {
"text": $(date).text(),
}
var service_id = "default_service";
var template_id = "alert";
emailjs.send(service_id,template_id,template_params);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment