Created
June 11, 2016 06:00
-
-
Save sineau/2a6ee8121584bab42f145e19c0637acd to your computer and use it in GitHub Desktop.
Sefarat Notifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name sefaratNotifier | |
// @namespace aisus | |
// @include about:addons | |
// @include https://ais.usvisa-info.com/*/niv/schedule/*/payment | |
// @version 0.1 | |
// @grant none | |
// ==/UserScript== | |
var notifPlayer = document.createElement('AUDIO') | |
notifPlayer.src = 'https://dl.dropbox.com/u/7079101/coin.mp3' | |
notifPlayer.preload = 'auto' | |
var date = new Date, | |
weekDays = ["Sunday", "Monday", "Tuesday", "Wednsday", "Thursday", "Friday", "Saturday"] | |
dateValues = weekDays[date.getDay()] + " - " + date.getHours() | |
+ ":" + date.getMinutes() + ":" + date.getSeconds() | |
var desiredTime = new Date(2016, 8, 30) | |
console.log(desiredTime) | |
function notifyMe (city, time) { | |
var notif = true | |
if (Notification.permission !== "denied") | |
Notification.requestPermission(function (permit) { | |
if (permit === "granted") var notif = new Notification(city + ": " + time) | |
}) | |
else if (Notification.permission === "granted") | |
var notif = new Notification(city + ": " + time) | |
if (notif) { | |
notifPlayer.play() | |
setTimeout(setInterval(function() { | |
notifPlayer.play() | |
}, 30000), 2* 60 * 60 * 1000) | |
} | |
} | |
var scheduleTable = $(".firstAvailableAppointment tr").map(function() { | |
var parseDate = $(this).find("td:nth-child(2)").html().trim().split(/\s|,\s/) | |
return { | |
city: $(this).find("td:nth-child(1)").find("strong").html(), | |
time: new Date(parseDate[1] + " " + parseDate[0] + ", " + parseDate[2]) | |
} | |
}).filter(function(_, i) { | |
console.log(i.time < desiredTime) | |
if (!isNaN(i.time) && i.time < desiredTime) { | |
console.log("It happened") | |
return true | |
} else return false | |
}) | |
console.log(scheduleTable) | |
if (scheduleTable.length !== 0) { | |
notifyMe(scheduleTable[0].city, scheduleTable[0].time) | |
} else { | |
var timeOut = Math.random() * (300000 - 60000) + 60000 | |
console.log(dateValues + "-- going for reload in " + timeOut) | |
setTimeout(function() {document.location.reload()}, timeOut) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment