Created
June 13, 2012 13:22
-
-
Save bangonkali/2924002 to your computer and use it in GitHub Desktop.
My.IIT COR Scheduler
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 Graphical Scheduler | |
// @namespace https://sites.google.com/site/kinalibangon/ventures/javascript/graphical-scheduler | |
// @description My.IIT Graphical Scheduler for COR | |
// @include http://x4150my.msuiit.edu.ph/my/student/cor.php | |
// @version 0.0.7 | |
// ==/UserScript== | |
// subject/course counters. | |
var subjects = new Array(); | |
var subjecCount = 0; | |
// important iterators. :) | |
var days=new Array("M","T","W","Th","F"); | |
days[-1]=""; | |
var hemis = new Array("AM", "PM"); | |
var timeframe = new Array( "07:00AM-09:00AM", | |
"07:30AM-09:00AM", | |
"09:00AM-10:30AM", | |
"10:30AM-12:00PM", | |
"12:00AM-01:30PM", | |
"12:30PM-01:30PM", | |
"01:30PM-03:00PM", | |
"03:00PM-04:30PM", | |
"04:30PM-06:00PM", | |
"04:30PM-06:30PM", | |
"06:00PM-07:30PM", | |
"07:30PM-09:00PM"); | |
// etirate throught the document object model starting | |
// from the id'ed content-body towards the table that | |
// contains the relevant data. | |
var mybody, rightcol, contendiv, scheduleTable; | |
mybody = document.getElementById("content-body"); | |
rightcol = mybody.firstChild.nextSibling.nextSibling.nextSibling; | |
contendiv = rightcol.firstChild.nextSibling.nextSibling.nextSibling; | |
scheduleTable = contendiv.firstChild.nextSibling.nextSibling.nextSibling; | |
// get the subject information from the document model and put it in the subject | |
// object. also check for lab's that have no name as class code. L is affixed to unnamed labs. | |
for (var i = 1; i < scheduleTable.rows.length; i++){ | |
subject = new Object(); | |
subject.code = scheduleTable.rows[i].cells[0].innerHTML.replace(" ",""); | |
if (subject.code == ''){ | |
prevSubject = new Object(); | |
prevSubject = subjects[i-1]; | |
subject.code = prevSubject.code + "L"; | |
} | |
subject.section = scheduleTable.rows[i].cells[1].innerHTML.replace(" ",""); | |
subject.description = scheduleTable.rows[i].cells[2].innerHTML.replace(" ",""); | |
subject.days = scheduleTable.rows[i].cells[3].innerHTML.replace(" ",""); | |
subject.time = scheduleTable.rows[i].cells[4].innerHTML.replace(" ",""); | |
subject.room = scheduleTable.rows[i].cells[5].innerHTML.replace(" ",""); | |
subject.grade = scheduleTable.rows[i].cells[6].innerHTML.replace(" ",""); | |
subject.compl = scheduleTable.rows[i].cells[7].innerHTML.replace(" ",""); | |
subject.begin = subject.time.substring(0,7); //get rid of the zeroes in the first character | |
if ( subject.begin[0]=='0') subject.begin = subject.begin.substring(1,subject.begin.length); | |
subject.end = subject.time.substring(8,15); //get rid of the zeroes in the first character | |
if ( subject.end[0]=='0') subject.end = subject.end.substring(1,subject.end.length); | |
subjects[i] = subject; | |
} | |
// container of the arrays of subjects taken each day | |
// hence this will be like a double dimension array. | |
var weekday = new Array(); | |
// get the days of which every course is taken | |
// for example if, TThF then put it in the | |
// proper index at weekday array. | |
for (var day = 0; day < days.length; day++){ | |
var subjectCountOfTheDay = 0; | |
var subjectsOfTheDay = new Array(); | |
for (var i = 1; i < scheduleTable.rows.length; i++){ | |
subject = new Object(); | |
subject = subjects[i]; | |
if (subject.days.indexOf(days[day]) > -1) { | |
if (days[day] == "T"){ | |
var tFound = subject.days.indexOf(days[day]); | |
if (subject.days.indexOf("Th", tFound + 1) > -1){ | |
subjectsOfTheDay[subjectCountOfTheDay] = subject; | |
subjectCountOfTheDay++; | |
} | |
else { | |
if (subject.days.indexOf("Th") < 0){ | |
subjectsOfTheDay[subjectCountOfTheDay] = subject; | |
subjectCountOfTheDay++; | |
} | |
} | |
} | |
else { | |
subjectsOfTheDay[subjectCountOfTheDay] = subject; | |
subjectCountOfTheDay++; | |
} | |
} | |
} | |
weekday[day] = subjectsOfTheDay; | |
} | |
var myDay = new Array(); | |
for (var day = 0; day < days.length; day++){ | |
var x; | |
var subjectsOfTheDay = new Array(); | |
var subjectsofMyDay = new Array(); | |
subjectsOfTheDay = weekday[day]; | |
for (x in subjectsOfTheDay){ | |
subject = new Object(); | |
subject = subjectsOfTheDay[x]; | |
// add timeframes to subject | |
var totalSubjTimeFrames = 0; | |
var subjTimeFrames = new Array(); | |
var exactMatch = false; | |
for (i=0; i<timeframe.length; i++){ | |
if (timeframe[i]==subject.time){ | |
subjTimeFrames[totalSubjTimeFrames]=timeframe[i]; | |
totalSubjTimeFrames++; | |
exactMatch = true; | |
break; | |
} | |
} | |
if (exactMatch==false){ | |
for (i=0; i<timeframe.length; i++){ | |
if(timeframe[i].substring(0,7)==subject.time.substring(0,7)){ | |
subjTimeFrames[totalSubjTimeFrames]=timeframe[i]; | |
totalSubjTimeFrames++; | |
} | |
else if(timeframe[i].substring(8,15)==subject.time.substring(8,15)){ | |
subjTimeFrames[totalSubjTimeFrames]=timeframe[i]; | |
totalSubjTimeFrames++; | |
} | |
} | |
} | |
subject.timecells=subjTimeFrames; | |
subjectsOfTheDay[x] = subject; | |
subjectsofMyDay[x] = subject; | |
} | |
myDay[day] = subjectsofMyDay; | |
} | |
newTable = document.createElement("table"); | |
var innerCode = "<tbody><tr>"; | |
var percentage = 730 / (days.length + 1); | |
for (var day = -1; day < days.length; day++){ | |
innerCode = innerCode + "<th width=\"" + percentage + "\" align=\"center\">" + days[day] + "</th>"; | |
} | |
for (var t=0; t<timeframe.length;t++){ | |
GM_log("begin " + timeframe[t]); | |
innerCode = innerCode + "<tr>"; | |
innerCode = innerCode + "<td width=\"" + percentage + "\" align=\"center\">" + timeframe[t] + "</td>"; | |
for (var d=0; d<days.length;d++){ | |
GM_log("day " + days[d]); | |
var resfound = false; | |
var mySubjs = myDay[d]; | |
for (var s=0; s<mySubjs.length;s++){ | |
subject = new Object(); | |
subject = mySubjs[s]; | |
var subjTimes = subject.timecells; | |
for (var st=0; st<subjTimes.length;st++){ | |
if (subjTimes[st] == timeframe[t]){ | |
resfound=true; | |
GM_log("subject " + subject.code); | |
innerCode = innerCode + "<td width=\"" + percentage + "\" align=\"center\">" + subject.section + "</td>"; | |
break; | |
} | |
} | |
if (resfound==true){ | |
break; | |
} | |
} | |
if (resfound==false) { | |
GM_log("subject " + "none"); | |
innerCode = innerCode + "<td width=\"" + percentage + "\" align=\"center\"> </td>"; | |
} | |
} | |
GM_log("end " + timeframe[t]); | |
innerCode = innerCode + "</tr>"; | |
} | |
// begin presentation layer | |
innerCode =innerCode + "</tbody>"; | |
newTable.innerHTML = innerCode; | |
contendiv.insertBefore(newTable,scheduleTable); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment