Last active
September 21, 2017 09:15
-
-
Save bernardo-cs/5e77d4755ee7325e276c1804617d0d11 to your computer and use it in GitHub Desktop.
Verify dom changes every second, reload after 1 minute, send notification if change happened with Tampermonkey and RxJS
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 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 https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.4.3/Rx.js | |
// ==/UserScript== | |
const interval$ = Rx.Observable.interval(1000); | |
const borderClasses$ = interval$ | |
.map(() => document.getElementById('aula-heading468444').parentNode.className) | |
.map(borderNode => borderNode !== "panel panel-red"); | |
const isntAvailable$ = borderClasses$ | |
.filter(x => !x) | |
.distinctUntilChanged() | |
.do(x => console.log('class unavailable, will reload in one minute')) | |
.delay(60000) | |
.do(() => location.reload()) | |
.subscribe(); | |
const isAvailable$ = borderClasses$ | |
.filter(x => x) | |
.do(x => { | |
new Notification('Yey!', { | |
icon: 'https://image.freepik.com/free-icon/dumbbell-exercise_318-35207.png', | |
body: "A aula esta livre :)", | |
}); | |
}).subscribe(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment