Last active
May 9, 2019 09:23
-
-
Save meghprkh/3ae064196d562f18d156c6d902505d20 to your computer and use it in GitHub Desktop.
Convenient attendance viewing for IIIT-H Moodle - See first *comment* at the end of the page #userscript
This file contains hidden or 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 iiith-moodle-attendance | |
// @namespace http://meghprkh.github.io/ | |
// @version 0.6 | |
// @description Convenient attendance viewing for IIIT-H Moodle | |
// @author Megh Parikh <[email protected]> | |
// @match https://moodle.iiit.ac.in/my/ | |
// @match https://moodle.iiit.ac.in/mod/attendance/view.php?*mode=1* | |
// @homepage https://gist.github.com/meghprkh/3ae064196d562f18d156c6d902505d20 | |
// @updateURL https://gist.github.com/meghprkh/3ae064196d562f18d156c6d902505d20/raw/iiith-moodle-attendance.user.js | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// First navigate to dashboard to get this filled | |
let currentSubjects = GM_getValue('currentSubjects', []) | |
let subjectHeaders = document.querySelectorAll('h3'); | |
let attendance = [] | |
for (let subjectHeader of subjectHeaders) { | |
const subjectName = subjectHeader.innerText; | |
if (currentSubjects.indexOf(subjectName) == -1) continue; | |
const table = subjectHeader.nextElementSibling.nextElementSibling; | |
const total = table.querySelector('tr:nth-child(1) > .cell.c1').innerText | |
const present = table.querySelector('tr:nth-child(2) > .cell.c1').innerText | |
if (total == 0) continue | |
attendance.push({ | |
name: subjectName, | |
present: parseInt(present), | |
total: parseInt(total), | |
}) | |
} | |
let output = ` | |
<style> | |
.attendanceTable { | |
width: 100%; | |
border-collapse: collapse; | |
} | |
.attendanceTable td { | |
border: 1px solid black; | |
font-size: 1.5em; | |
padding: 0.5em; | |
} | |
.attendanceTable thead { | |
font-weight: bold; | |
} | |
</style> | |
<table class="attendanceTable"> | |
<thead> | |
<tr> | |
<td>Subject</td> | |
<td>Present</td> | |
<td>Completed</td> | |
</tr> | |
</thead> | |
<tbody> | |
` | |
for (let subject of attendance) { | |
output += ` | |
<tr> | |
<td>${subject.name}</td> | |
<td>${subject.present}</td> | |
<td>${subject.total}</td> | |
</tr> | |
` | |
} | |
output += ` | |
</tbody> | |
</table> | |
<br /> | |
` | |
let main = document.querySelector('div[role="main"]'); | |
if (window.location.pathname == '/my/') { | |
subjectHeaders = document.querySelectorAll('h2.title') | |
currentSubjects = [] | |
for (let header of subjectHeaders) | |
currentSubjects.push(header.innerText) | |
GM_setValue('currentSubjects', currentSubjects) | |
} else { | |
if (currentSubjects.length == 0) output = `<h1>Please navigate to <a href='/my/'>dashboard</a> once</h1>` | |
main.innerHTML = output + main.innerHTML | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install tampermonkey and then go here https://gist.github.com/meghprkh/3ae064196d562f18d156c6d902505d20/raw/iiith-moodle-attendance.user.js and then go to Attendance page