Skip to content

Instantly share code, notes, and snippets.

@bernardo-cs
Last active September 21, 2017 09:15
Show Gist options
  • Save bernardo-cs/5e77d4755ee7325e276c1804617d0d11 to your computer and use it in GitHub Desktop.
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
// ==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