Skip to content

Instantly share code, notes, and snippets.

@bernardo-cs
Created January 10, 2017 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bernardo-cs/f70b17d9ffc0681bc732bde23ea42f20 to your computer and use it in GitHub Desktop.
Save bernardo-cs/f70b17d9ffc0681bc732bde23ea42f20 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Verify fitness hut class availability
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.myhut.pt/myhut/aulas/*
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
(function() {
'use strict';
const class_id = '#aula-heading323069';
const classIsAvailable = (class_id) => {
const classNode = $(class_id).parent(".panel-off, .panel-red");
return classNode.length === 0;
};
const todayClassIsAvailable = () => { return classIsAvailable(class_id); };
const notifyMe = () => {
return new Notification('Yey!', {
icon: 'https://image.freepik.com/free-icon/dumbbell-exercise_318-35207.png',
body: "Go a aula esta livre :)",
});
};
// Verify if class isnt red, otherwise refresh the page (the script will run again).
const run_until_success = (run, onSuccess) => {
if (run()){
return onSuccess();
}else{
console.log("Not available... Refreshing in a minute...");
setTimeout(function(){ location.reload(); }, 60000);
}
};
// Wait a little bit for the page to load.
setTimeout(() => run_until_success(todayClassIsAvailable, notifyMe), 5000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment