Last active
January 7, 2019 10:29
-
-
Save bekicot/66c57bf906a60d0060cc5e2d37a063d5 to your computer and use it in GitHub Desktop.
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
Notification.requestPermission(); | |
function notifyMe(matkul, kelas) { | |
if (Notification.permission !== "granted") | |
Notification.requestPermission(); | |
else { | |
var notification = new Notification(matkul + ' - ' + kelas + " Tersedia", { | |
body: "Ayo cepet daftar!!!!", | |
}); | |
} | |
} | |
async function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
function htmlToElement(html) { | |
var template = document.createElement('template'); | |
html = html.trim(); // Never return a text node of whitespace as the result | |
template.innerHTML = html; | |
return template.content.firstChild; | |
} | |
async function checkKelas(matkul, kelas) { | |
urls = [ | |
"https://igracias.telkomuniversity.ac.id/libraries/ajax/ajax.reg.php?act=viewOfferedCourse&tk=3&pre=2&studentStartYear=1516&studyProgram=31&facultyId=7", | |
"https://igracias.telkomuniversity.ac.id/libraries/ajax/ajax.reg.php?act=viewOfferedCourse&tk=2&pre=2&studentStartYear=1516&studyProgram=31&facultyId=7", | |
"https://igracias.telkomuniversity.ac.id/libraries/ajax/ajax.reg.php?act=viewOfferedCourse&tk=4&pre=2&studentStartYear=1516&studyProgram=31&facultyId=7", | |
"https://igracias.telkomuniversity.ac.id/libraries/ajax/ajax.reg.php?act=viewOfferedCourse&tk=1&pre=2&studentStartYear=1516&studyProgram=31&facultyId=7" | |
] | |
for(let url of urls) { | |
let kelasTable = await fetch(url, { | |
"credentials": "include", | |
"headers": { | |
"accept": "*/*", | |
"accept-language": "en-US,en;q=0.9,id-ID;q=0.8,id;q=0.7", | |
"cache-control": "no-cache", | |
"pragma": "no-cache", | |
"x-firephp-version": "0.0.6", | |
"x-requested-with": "XMLHttpRequest" | |
}, | |
"referrer": "https://igracias.telkomuniversity.ac.id/registration/?pageid=761", | |
"referrerPolicy": "no-referrer-when-downgrade", | |
"body": null, | |
"method": "GET", | |
"mode": "cors" | |
}).then((response) => { return response.text() } ).then((table) => { return table }); | |
$kelas = htmlToElement(kelasTable); | |
$trs = $kelas.querySelectorAll('tr'); | |
for(let $tr of $trs) { | |
if($tr.childNodes[1].textContent == matkul && $tr.childNodes[5].textContent == kelas && $tr.childNodes[6].textContent != "(Penuh)") { | |
notifyMe(matkul, kelas); | |
} | |
} | |
} | |
} | |
async function startFetching(max) { | |
let counter = 0; | |
while(true) { | |
await checkKelas("CSH3I3 - SISTEM INFORMASI", "IF-40-02"); | |
await sleep(30 * 1000) // Check tiap 30 detik | |
if(counter > max) | |
return | |
} | |
} | |
startFetching(10000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment