@@ -20,11 +20,22 @@ var isIndividual = false;
var done = true ;
var curr _course = { }
//This extension may be super lit, but you know what's even more lit?
//Matthew Tran's twitter and insta: @MATTHEWTRANN and @matthew.trann
console . log ( 'UT Registration Plus is running on this page.' ) ;
semesterCode = new URL ( window . location . href ) . pathname . split ( '/' ) [ 4 ] ;
$ ( window ) . scroll ( function ( ) {
if ( $ ( document ) . height ( ) <= $ ( window ) . scrollTop ( ) + $ ( window ) . height ( ) + 150 ) {
loadNextPages ( ) ;
}
} ) ;
if ( document . querySelector ( '#fos_fl' ) ) {
let params = ( new URL ( document . location ) ) . searchParams ;
let dep = params . get ( "fos_fl" ) ;
@@ -47,17 +58,19 @@ if (next) {
} ) ;
}
//make heading and modal
if ( ! $ ( "#kw_results_table" ) . length ) {
$ ( "table thead th:last-child" ) . after ( '<th scope=col>Plus</th>' ) ;
$ ( "table" ) . after ( ` <div style="text-align:center">
< div class = "loader" id = 'loader' > < / d i v >
< br >
< h1 id = "nextlabel" style = "color: #FF9800;display:none;" > Loading Courses < / h 1 >
< h1 id = "retrylabel" style = "color: #F44336;display:none;" > Failed to Load Courses < / h 1 >
< br >
< button class = matbut id = "retry" style = "background: #F44336;display:none;" > Retry < / b u t t o n >
< / d i v > ` ) ;
< div class = "loader" id = 'loader' > < / d i v >
< br >
< h1 id = "nextlabel" style = "color: #FF9800;display:none;" > Loading Courses < / h 1 >
< h1 id = "retrylabel" style = "color: #F44336;display:none;" > Failed to Load Courses < / h 1 >
< br >
< button class = matbut id = "retry" style = "background: #F44336;display:none;" > Retry < / b u t t o n >
< / d i v > ` ) ;
var modhtml = ` <div class=modal id=myModal>
< div class = modal - content >
< span class = close > × < / s p a n >
@@ -89,17 +102,12 @@ if (!$("#kw_results_table").length) {
< / d i v >
< / d i v > ` ;
$ ( "#container" ) . prepend ( modhtml ) ;
$ ( "#myModal" ) . prepend ( "<div id='snackbar'>defaultmessage ..</div>" ) ;
$ ( "#myModal" ) . prepend ( "<div id='snackbar'>save course popup. ..</div>" ) ;
//go through all the rows in the list
$ ( 'table' ) . find ( 'tr' ) . each ( function ( ) {
if ( ! ( $ ( this ) . find ( 'td' ) . hasClass ( "course_header" ) ) && $ ( this ) . has ( 'th' ) . length == 0 ) {
//if a course row, then add the extension button
$ ( this ) . append ( ` <td data-th="Plus"><input type="image" class="distButton" id="distButton" style="vertical-align: bottom; display:block;" width="20" height="20" src=' ${ chrome . extension . getURL ( 'images/disticon.png' ) } '/></td> ` ) ;
// if ($(this).find('td[data-th="Status"]').text().includes('waitlisted')) {
// $(this).find('td').each(function () {
// $(this).css('background-color', '#E0E0E0');
// });
// }
}
} ) ;
}
@@ -112,15 +120,10 @@ $("body").on('click', '#distButton', function () {
scrollTop : 0
} , 500 ) ;
$ ( this ) . blur ( ) ;
getCourseInfo ( row ) ;
getDistribution ( ) ;
curr _course = getCourseInfo( row ) ;
getDistribution ( curr _course ) ;
} ) ;
$ ( window ) . scroll ( function ( ) {
if ( $ ( document ) . height ( ) <= $ ( window ) . scrollTop ( ) + $ ( window ) . height ( ) + 150 ) {
loadNextPages ( ) ;
}
} ) ;
$ ( "#myModal" ) . on ( 'click' , '#saveCourse' , function ( ) {
setTimeout ( function ( ) {
@@ -130,28 +133,28 @@ $("#myModal").on('click', '#saveCourse', function () {
$ ( "#Syllabi" ) . click ( function ( ) {
setTimeout ( function ( ) {
window . open ( ` https://utdirect.utexas.edu/apps/student/coursedocs/nlogon/?semester=&department= ${ department } &course_number= ${ course _nbr } &course_title=&unique=&instructor_first=&instructor_last= ${ profname } &course_type=In+Residence&search=Search ` ) ;
window . open ( curr _ course[ "links" ] [ "syllabi" ] ) ;
} , butdelay ) ;
} ) ;
$ ( "#rateMyProf" ) . click ( function ( ) {
setTimeout ( function ( ) {
window . open ( rmpLink ) ;
window . open ( curr _course [ "links" ] [ "rate_my_prof" ] ) ;
} , butdelay ) ;
} ) ;
$ ( "#eCIS" ) . click ( function ( ) {
setTimeout ( function ( ) {
window . open ( eCISLink ) ;
window . open ( curr _course [ "links" ] [ "ecis" ] ) ;
} , butdelay ) ;
} ) ;
$ ( "#textbook" ) . click ( function ( ) {
setTimeout ( function ( ) {
window . open ( textbookLink ) ;
window . open ( curr _course [ "links" ] [ " textbook" ] ) ;
} , butdelay ) ;
} ) ;
$ ( "#semesters" ) . on ( 'change' , function ( ) {
var sem = $ ( this ) . val ( ) ;
sem = sem == "Aggregate" ? undefined : sem ;
getDistribution ( sem ) ;
getDistribution ( curr _course , sem) ;
} ) ;
$ ( "#retry" ) . click ( function ( ) {
@@ -159,22 +162,126 @@ $("#retry").click(function () {
$ ( this ) . hide ( ) ;
loadNextPages ( ) ;
} ) ;
$ ( document ) . keydown ( function ( e ) {
/*Close Modal when hit escape*/
if ( e . keyCode == 27 ) {
close ( ) ;
} else if ( e . keyCode == 13 && $ ( '#myModal' ) . is ( ':visible' ) ) {
/*save course when hit enter*/
saveCourse ( ) ;
}
} ) ;
/*Listen for update mssage coming from popup*/
chrome . runtime . onMessage . addListener (
function ( request , sender , sendResponse ) {
if ( request . command == "updateCourseList" ) {
update ( 0 ) ;
}
} ) ;
}
) ;
function sepNameParts ( name ) {
numIndex = name . search ( /\d/ ) ;
department = name . substring ( 0 , numIndex ) . trim ( ) ;
number = name . substring ( numIndex , name . indexOf ( " " , numIndex ) ) . trim ( ) ;
name = capitalizeString ( name . substring ( name . indexOf ( " " , numIndex ) ) . trim ( ) ) ;
return [ name , department , number ] ;
}
function buildCourseLinks ( course _info ) {
let {
department ,
number ,
unique ,
prof _name
} = course _info
links = {
"textbook" : ` https://www.universitycoop.com/adoption-search-results?sn= ${ semesterCode } __ ${ department } __ ${ number } __ ${ unique } ` ,
"syllabi" : ` https://utdirect.utexas.edu/apps/student/coursedocs/nlogon/?semester=&department= ${ department } &course_number= ${ number } &course_title=&unique=&instructor_first=&instructor_last= ${ prof _name } &course_type=In+Residence&search=Search ` ,
//default ones (before first name can be used)
"rate_my_prof" : "http://www.ratemyprofessors.com/campusRatings.jsp?sid=1255" ,
"ecis" : "http://utdirect.utexas.edu/ctl/ecis/results/index.WBX?"
}
course _info [ "links" ] = links ;
return course _info ;
}
function buildBasicCourseInfo ( row , course _name , individual ) {
let namedata = sepNameParts ( course _name )
let instructor _text = $ ( row ) . find ( 'td[data-th="Instructor"]' ) . text ( ) ;
let has _initial = instructor _text . indexOf ( ',' ) > 0 ;
course _info = {
"full_name" : course _name ,
"name" : namedata [ 0 ] ,
"department" : namedata [ 1 ] ,
"number" : namedata [ 2 ] ,
"individual" : individual ? individual : $ ( row ) . find ( 'td[data-th="Unique"] a' ) . prop ( 'href' ) ,
"register" : $ ( row ) . find ( 'td[data-th="Add"] a' ) . prop ( 'href' ) ,
"unique" : $ ( row ) . find ( 'td[data-th="Unique"]' ) . text ( ) ,
"status" : $ ( row ) . find ( 'td[data-th="Status"]' ) . text ( ) ,
"prof_name" : instructor _text ? has _initial ? capitalizeString ( instructor _text . split ( ', ' ) [ 0 ] ) : capitalizeString ( instructor _text ) : "Undecided" ,
"initial" : instructor _text && has _initial ? instructor _text . split ( ', ' ) [ 1 ] . substring ( 0 , 1 ) : "" ,
"time_data" : {
"days" : $ ( row ) . find ( 'td[data-th="Days"]>span' ) . toArray ( ) . map ( x => $ ( x ) . text ( ) . trim ( ) ) ,
"times" : $ ( row ) . find ( 'td[data-th="Hour"]>span' ) . toArray ( ) . map ( x => $ ( x ) . text ( ) . trim ( ) ) ,
"places" : $ ( row ) . find ( 'td[data-th="Room"]>span' ) . toArray ( ) . map ( x => $ ( x ) . text ( ) . trim ( ) )
} ,
"links" : { }
}
return buildCourseLinks ( course _info ) ;
}
function buildTimeTitle ( course _info ) {
$ ( "h2.dateTimePlace" ) . remove ( ) ;
let {
days ,
times ,
places
} = course _info [ "time_data" ]
datetimearr = [ ] ;
var lines = [ ] ;
for ( var i = 0 ; i < days . length ; i ++ ) {
var date = days [ i ] ;
var time = times [ i ] ;
var place = places [ i ] ;
lines . push ( $ ( ` <h2 class="dateTimePlace"> ${ makeLine ( date , time , place ) } </th> ` ) ) ;
}
return lines ;
}
/*For a row, get all the course information and add the date-time-lines*/
function getCourseInfo ( row ) {
let course _name = "" ;
let course _row = { }
let individual = undefined ;
if ( $ ( "#textbook_button" ) . length ) {
course _name = $ ( "#details h2" ) . text ( ) ;
course _row = $ ( 'table' ) ;
individual = document . URL ;
} else {
$ ( 'table' ) . find ( 'tr' ) . each ( function ( ) {
if ( $ ( this ) . find ( 'td' ) . hasClass ( "course_header" ) ) {
course _name = $ ( this ) . find ( 'td' ) . text ( ) + "" ;
}
if ( $ ( this ) . is ( row ) ) {
course _row = row ;
return false ;
}
} ) ;
}
curr _course = buildBasicCourseInfo ( course _row , course _name , individual ) ;
getDescription ( curr _course ) ;
return curr _course ;
}
function loadNextPages ( ) {
chrome . storage . sync . get ( 'loadAll' , function ( data ) {
@@ -201,19 +308,12 @@ function loadNextPages() {
let hasCourseHead = $ ( this ) . find ( 'td' ) . hasClass ( "course_header" ) ;
if ( ! ( hasCourseHead && $ ( this ) . has ( 'th' ) . length == 0 ) ) {
$ ( this ) . append ( ` <td data-th="Plus"><input type="image" class="distButton" id="distButton" style="vertical-align: bottom;" width="20" height="20" src=' ${ chrome . extension . getURL ( 'images/disticon.png' ) } '/></td> ` ) ;
// if ($(this).find('td[data-th="Status"]').text().includes('waitlisted')) {
// $(this).find('td').each(function () {
// $(this).css('background-color', '#E0E0E0');
// });
// }
}
if ( ! ( hasCourseHead && last == $ ( this ) . find ( 'td' ) . text ( ) ) ) {
newrows . push ( $ ( this ) ) ;
}
} ) ;
current . append ( newrows ) ;
// console.log($('tbody tr').length + " " + $('tr>td.course_header').length);
// update(oldlength + 1);
update ( oldlength + 1 )
}
} ) . fail ( function ( ) {
@@ -229,27 +329,41 @@ function loadNextPages() {
}
function saveCourse ( ) {
var c = new Course ( coursename , uniquenum , profname , datetimearr , status , profurl , registerlink ) ;
let {
full _name ,
unique ,
prof _name ,
status ,
individual ,
register
} = curr _course ;
let dtarr = getDayTimeArray ( undefined , curr _course ) ;
var c = new Course ( full _name , unique , prof _name , dtarr , status , individual , register ) ;
chrome . runtime . sendMessage ( {
command : "courseStorage" ,
course : c ,
action : $ ( "#saveCourse" ) . text ( ) . substring ( 0 , $ ( "#saveCourse" ) . text ( ) . indexOf ( " " ) ) . toLowerCase ( )
} , function ( response ) {
$ ( "#saveCourse" ) . text ( response . label ) ;
$ ( "#snackbar" ) . text ( response . done ) ;
setTimeout ( function ( ) {
$ ( "#snackbar" ) . attr ( "class" , "show" ) ;
} , 200 ) ;
setTimeout ( function ( ) {
$ ( "#snackbar" ) . attr ( "class" , "" ) ;
} , 3000 ) ;
toggleSnackbar ( ) ;
chrome . runtime . sendMessage ( {
command : "updateCourseList"
} ) ;
} ) ;
}
function toggleSnackbar ( ) {
setTimeout ( function ( ) {
$ ( "#snackbar" ) . attr ( "class" , "show" ) ;
} , 200 ) ;
setTimeout ( function ( ) {
$ ( "#snackbar" ) . attr ( "class" , "" ) ;
} , 3000 ) ;
}
/* Update the course list to show if the row contains a course that conflicts with the saved course is one of the saved courses */
function update ( start ) {
chrome . storage . sync . get ( 'courseConflictHighlight' , function ( data ) {
@@ -261,23 +375,19 @@ function update(start) {
if ( ! ( $ ( this ) . find ( 'td' ) . hasClass ( "course_header" ) ) && $ ( this ) . has ( 'th' ) . length == 0 ) {
var thisForm = this ;
var uniquenum = $ ( this ) . find ( 'td[data-th="Unique"]' ) . text ( ) ;
// console.log(uniquenum);
chrome . runtime . sendMessage ( {
command : "isSingleConflict" ,
dtarr : getDtarr ( this ) ,
dtarr : getDayTimeArray ( this ) ,
unique : uniquenum
} , function ( response ) {
var tds = $ ( thisForm ) . find ( 'td' ) ;
// console.log(tds.css('color'));
if ( response . isConflict && data . courseConflictHighlight && ! response . alreadyContains ) {
if ( tds . css ( 'color' ) != 'rgb(244, 67, 54)' ) {
console . log ( 'made red ' + uniquenum ) ;
red ++ ;
tds . css ( 'color' , '#F44336' ) . css ( 'text-decoration' , 'line-through' ) . css ( 'font-weight' , 'normal' ) ;
}
} else if ( ! response . alreadyContains ) {
if ( tds . css ( 'color' ) != 'rgb(51, 51, 51)' ) {
console . log ( 'made black ' + uniquenum ) ;
black ++ ;
tds . css ( 'color' , 'black' ) . css ( 'text-decoration' , 'none' ) . css ( 'font-weight' , 'normal' ) ;
}
@@ -285,7 +395,6 @@ function update(start) {
if ( response . alreadyContains ) {
if ( tds . css ( 'color' ) != 'rgb(76, 175, 80)' ) {
green ++ ;
console . log ( 'made green ' + uniquenum ) ;
tds . css ( 'color' , '#4CAF50' ) . css ( 'text-decoration' , 'none' ) . css ( 'font-weight' , 'bold' ) ;
}
}
@@ -293,199 +402,80 @@ function update(start) {
}
}
} ) ;
//console.log(`red: ${red} black: ${black} green: ${green}`);
} ) ;
}
/* For a row, get the date-time-array for checking conflicts*/
function getDtarr ( row ) {
var numlines = $ ( row ) . find ( 'td[data-th="Days"]>span' ) . length ;
var dtarr = [ ] ;
for ( var i = 0 ; i < numlin es; i ++ ) {
var date = $ ( row ) . find ( 'td[data-th="Days "]>span:eq(' + i + ')' ) . text ( ) ;
var time = $ ( row ) . find ( 'td[data-th="Hour"]>span:eq(' + i + ')' ) . text ( ) ;
var place = $ ( row ) . find ( 'td[data-th="Room"]>span:eq(' + i + ')' ) . text ( ) ;
function getDayTimeArray ( row , course _info ) {
var daytimearray = [ ]
let days = course _info ? course _info [ "time_data" ] [ "days" ] : $ ( row ) . find ( 'td[data-th="Days"]>span' ) . toArray ( ) . map ( x => $ ( x ) . text ( ) . trim ( ) ) ;
let times = course _info ? course _info [ "time_data" ] [ "tim es" ] : $ ( row ) . find ( 'td[data-th="Hour"]>span' ) . toArray ( ) . map ( x => $ ( x ) . text ( ) . trim ( ) ) ;
let places = course _info ? course _info [ "time_data" ] [ "places" ] : $ ( row ) . find ( 'td[data-th="Room "]>span' ) . toArray ( ) . map ( x => $ ( x ) . text ( ) . trim ( ) ) ;
for ( var i = 0 ; i < days . length ; i ++ ) {
let date = days [ i ] ;
let time = times [ i ] ;
let place = places [ i ] ;
for ( var j = 0 ; j < date . length ; j ++ ) {
var letter = date . charAt ( j ) ;
var day = "" ;
let letter = date . charAt ( j ) ;
if ( letter == "T" && j < date . length - 1 && date . charAt ( j + 1 ) == "H" ) {
dt arr . push ( [ "TH" , convertTime ( time ) , place ] ) ;
daytime array . push ( [ "TH" , convertTime ( time ) , place ] ) ;
} else {
if ( letter != "H" ) {
dt arr . push ( [ letter , convertTime ( time ) , place ] ) ;
}
if ( letter != "H" )
daytime array . push ( [ letter , convertTime ( time ) , place ] ) ;
}
}
}
return dt arr ;
return daytime array ;
}
/*Course object for passing to background*/
function Course ( coursename , unique , profname , datetimearr , status , link , registerlink ) {
this . coursename = coursename ;
this . unique = unique ;
this . profname = profname ;
this . datetimearr = datetimearr ;
this . status = status ;
this . link = link ;
this . registerlink = registerlink ;
}
/*For a row, get all the course information and add the date-time-lines*/
function getCourseInfo ( row ) {
console . log ( row ) ;
semesterCode = new URL ( window . location . href ) . pathname . split ( '/' ) [ 4 ] ;
$ ( "h2.dateTimePlace" ) . remove ( ) ;
$ ( 'table' ) . find ( 'tr' ) . each ( function ( ) {
if ( $ ( this ) . find ( 'td' ) . hasClass ( "course_header" ) ) {
coursename = $ ( this ) . find ( 'td' ) . text ( ) + "" ;
}
if ( $ ( this ) . is ( row ) ) {
profurl = $ ( this ) . find ( 'td[data-th="Unique"] a' ) . prop ( 'href' ) ;
registerlink = $ ( this ) . find ( 'td[data-th="Add"] a' ) . prop ( 'href' ) ;
// console.log(registerlink);
uniquenum = $ ( this ) . find ( 'td[data-th="Unique"]' ) . text ( ) ;
status = $ ( this ) . find ( 'td[data-th="Status"]' ) . text ( ) ;
profname = $ ( this ) . find ( 'td[data-th="Instructor"]' ) . text ( ) . split ( ', ' ) [ 0 ] ;
profinit = $ ( this ) . find ( 'td[data-th="Instructor"]' ) . text ( ) . split ( ', ' ) [ 1 ] ;
if ( profname . indexOf ( " " ) == 0 ) {
profname = profname . substring ( 1 ) ;
}
var numlines = $ ( this ) . find ( 'td[data-th="Days"]>span' ) . length ;
datetimearr = [ ] ;
var lines = [ ] ;
for ( var i = 0 ; i < numlines ; i ++ ) {
var date = $ ( this ) . find ( 'td[data-th="Days"]>span:eq(' + i + ')' ) . text ( ) ;
var time = $ ( this ) . find ( 'td[data-th="Hour"]>span:eq(' + i + ')' ) . text ( ) ;
var place = $ ( this ) . find ( 'td[data-th="Room"]>span:eq(' + i + ')' ) . text ( ) ;
lines . push ( $ ( ` <h2 class="dateTimePlace"> ${ makeLine ( date , time , place ) } </th> ` ) ) ;
}
$ ( "#topbuttons" ) . before ( lines ) ;
return false ;
}
} ) ;
/*Handle if on the individual course page, ie if the textbook button exists*/
if ( $ ( "#textbook_button" ) . length ) {
coursename = $ ( "#details h2" ) . text ( ) ;
var gotname = $ ( "table" ) . find ( "td[data-th='Instructor']" ) . text ( ) ;
if ( gotname != "" ) {
profinit = gotname . split ( ", " ) [ 1 ] . substring ( 0 , 1 ) ;
} else {
profinit = "" ;
}
profurl = document . URL ;
// console.log(profurl);
}
getDescription ( ) ;
department = coursename . substring ( 0 , coursename . search ( /\d/ ) - 2 ) ;
course _nbr = coursename . substring ( coursename . search ( /\d/ ) , coursename . indexOf ( " " , coursename . search ( /\d/ ) ) ) ;
textbookLink = ` https://www.universitycoop.com/adoption-search-results?sn= ${ semesterCode } __ ${ department } __ ${ course _nbr } __ ${ uniquenum } `
}
/* Make the day-time-arr and make the text for the date-time-line*/
function makeLine ( date , time , place ) {
var arr = [ ] ;
var output = "" ;
for ( var i = 0 ; i < date . length ; i ++ ) {
var letter = date . charAt ( i ) ;
var day = "" ;
if ( letter == "T" && i < date . length - 1 && date . charAt ( i + 1 ) == "H" ) {
arr . push ( days . get ( "TH" ) ) ;
datetimearr . push ( [ "TH" , convertTime ( time ) , place ] ) ;
} else {
if ( letter != "H" ) {
arr . push ( days . get ( letter ) ) ;
datetimearr . push ( [ letter , convertTime ( time ) , place ] ) ;
}
}
}
if ( arr . length > 2 ) {
for ( var i = 0 ; i < arr . length ; i ++ ) {
if ( i < arr . length - 1 ) {
output += arr [ i ] + ", "
}
if ( i == arr . length - 2 ) {
output += "and " ;
}
if ( i == arr . length - 1 ) {
output += arr [ i ] ;
}
}
} else if ( arr . length == 2 ) {
output = arr [ 0 ] + " and " + arr [ 1 ] ;
} else {
output += arr [ 0 ] ;
}
var arr = seperateDays ( date )
var output = prettifyDaysText ( arr )
var building = place . substring ( 0 , place . search ( /\d/ ) - 1 ) ;
if ( building == "" ) {
building = "Undecided Location" ;
}
building = building == "" ? "Undecided Location" : building ;
return ` ${ output } at ${ time . replace ( /\./g , '' ) . replace ( /\-/g , ' to ' ) } in <a style='font-size:medium' target='_blank' href='https://maps.utexas.edu/buildings/UTM/ ${ building } '> ${ building } </> ` ;
}
/*Convert time to 24hour format*/
function convertTime ( ti me) {
var converted = time . replace ( /\./g , '' ) . split ( "-" ) ;
for ( var i = 0 ; i < 2 ; i ++ ) {
converted [ i ] = moment ( converted [ i ] , [ "h:mm A" ] ) . format ( "HH:mm" ) ;
}
return converted ;
function badData ( course _data , res ) {
return typeof res == 'undefined' || course _data [ "prof_na me" ] == "Undecided" ;
}
/*Query the grades database*/
function getDistribution ( sem ) {
var query ;
if ( ! sem ) {
query = "select * from agg" ;
} else {
query = "select * from grades" ;
}
query += " where dept like '%" + department + "%'" ;
query += " and prof like '%" + profname . replace ( /'/g , "" ) + "%'" ;
query += " and course_nbr like '%" + course _nbr + "%'" ;
if ( sem ) {
query += "and sem like '%" + sem + "%'" ;
}
query += "order by a1+a2+a3+b1+b2+b3+c1+c2+c3+d1+d2+d3+f desc" ;
function getDistribution ( course _data , sem) {
// showLoading(true);
let query = buildQuery ( course _data , sem ) ;
chrome . runtime . sendMessage ( {
command : "gradesQuery" ,
query : query
} , function ( response ) {
var res = response . data ;
if ( ! sem ) {
openDialog ( department , coursename , "aggregate" , profname , res ) ;
openDialog ( course _data , res ) ;
} else {
var data ;
if ( typeof res == 'undefined' || profname == "" ) {
data = [ ] ;
} else {
data = res . values [ 0 ] ;
}
var data = badData ( course _data , res ) ? [ ] : res . values [ 0 ] ;
setChart ( data ) ;
}
} ) ;
}
/*Open the modal and show all the data*/
function openDialog ( dep , cls , sem , professor , res ) {
$ ( "#myModal" ) . fadeIn ( fadetime ) ;
//initial text on the "save course button"
chrome . runtime . sendMessage ( {
command : "alreadyContains" ,
unique : uniquenum
} , function ( response ) {
if ( response . alreadyContains ) {
$ ( "#saveCourse" ) . text ( "Remove Course -" ) ;
} else {
$ ( "#saveCourse" ) . text ( "Add Course +" ) ;
}
} ) ;
//set if no grade distribution
var data ;
function buildTitle ( course _data ) {
return ` ${ course _data [ "name" ] } ( ${ course _data [ "department" ] } ${ course _data [ "number" ] } ) `
}
function buildProfTitle ( course _data ) {
const {
initial ,
prof _name
} = course _data ;
return ` with ${ initial ? initial + ". " : "" } ${ prof _name } ` ;
}
function buildSemestersDropdown ( course _data , res ) {
$ ( "#semesters" ) . empty ( ) ;
if ( typeof res == 'undefined' || profname == "" ) {
if ( badData ( course _data , res ) ) {
$ ( "#semesters" ) . append ( "<option>No Data</option>" )
data = [ ] ;
} else {
var semesters = res . values [ 0 ] [ 18 ] . split ( "," ) ;
semesters . sort ( semesterSort ) ;
@@ -495,43 +485,49 @@ function openDialog(dep, cls, sem, professor, res) {
sems . push ( $ ( ` <option value=" ${ semesters [ i ] } "> ${ semesters [ i ] } </option> ` ) ) ;
}
$ ( "#semesters" ) . append ( sems ) ;
}
}
/*Open the modal and show all the data*/
function openDialog ( course _info , res ) {
$ ( "#title" ) . text ( buildTitle ( course _info ) )
$ ( "#topbuttons" ) . before ( buildTimeTitle ( course _info ) ) ;
$ ( "#profname" ) . text ( buildProfTitle ( course _info ) ) ;
$ ( "#myModal" ) . fadeIn ( fadetime ) ;
//initial text on the "save course button"
chrome . runtime . sendMessage ( {
command : "alreadyContains" ,
unique : course _info [ "unique" ]
} , function ( response ) {
if ( response . alreadyContains ) {
$ ( "#saveCourse" ) . text ( "Remove Course -" ) ;
} else {
$ ( "#saveCourse" ) . text ( "Add Course +" ) ;
}
} ) ;
buildSemestersDropdown ( course _info , res )
var data = [ ]
if ( ! badData ( course _info , res ) )
data = res . values [ 0 ] ;
}
var modal = document . getElementById ( 'myModal' ) ;
var span = document . getElementsByClassName ( "close" ) [ 0 ] ;
modal . style . display = "block" ;
var color = "black" ;
if ( status . includes ( "open" ) ) {
color = "#4CAF50" ;
} else if ( status . includes ( "waitlisted" ) ) {
color = "#FF9800"
} else if ( status . includes ( "closed" ) || status . includes ( "cancelled" ) ) {
color = "#FF5722" ;
}
$ ( "#title" ) . text ( prettifyTitle ( ) ) . append ( "<span style='color:" + color + ";font-size:medium;'>" + " #" + uniquenum + "</>" ) ;
if ( typeof profinit != "undefined" && profinit . length > 1 ) {
profinit = profinit . substring ( 0 , 1 ) ;
}
var name ;
if ( profname == "" ) {
name = "Undecided Professor " ;
} else {
name = prettifyName ( ) ;
}
$ ( "#profname" ) . text ( "with " + name ) ;
let status _color = getStatusColor ( course _info [ "status" ] ) ;
//close button
span . onclick = function ( ) {
close ( ) ;
}
allowClosing ( ) ;
setChart ( data ) ;
// When clicks anywhere outside of the modal, close it
window . onclick = function ( event ) {
if ( event . target == modal ) {
}
function allowClosing ( ) {
$ ( '.close' ) . click ( function ( ) {
close ( ) ;
} ) ;
$ ( '#myModal' ) . click ( function ( event ) {
if ( event . target . id == 'myModal' ) {
close ( ) ;
}
}
} ) ;
}
function close ( ) {
@@ -560,83 +556,70 @@ function setChart(data) {
} ) ;
}
/*Format the title*/
function prettifyTitle ( ) {
val = department . length + course _nbr . length + 3 ;
output = coursename . substring ( val ) . replace ( /\b\w*/g , function ( txt ) {
return txt . charAt ( 0 ) . toUpperCase ( ) + txt . substr ( 1 ) . toLowerCase ( ) ;
} ) ;
return output + " (" + department + " " + course _nbr + ")" ;
}
/* Format the Professor Name */
function prettifyName ( ) {
var fixedprofinit = "" ;
if ( profinit ) {
fixedprofinit = profinit + ". " ;
function buildFormattedDescription ( description _lines ) {
let description = ""
for ( let i in description _lines ) {
let sentence = description _lines [ i ] ;
if ( sentence . indexOf ( "Prerequisite" ) == 0 )
sentence = ` <li style='font-weight: bold;' class='descriptionli'> ${ sentence } </li> ` ;
else if ( sentence . indexOf ( "May be" ) >= 0 )
sentence = ` <li style='font-style: italic;' class='descriptionli'> ${ sentence } </li> ` ;
else if ( sentence . indexOf ( "Restricted to" ) == 0 )
sentence = ` <li style='color:red;' class='descriptionli'> ${ sentence } </li> ` ;
else
sentence = ` <li class='descriptionli'> ${ sentence } </li> ` ;
description + = sentence ;
}
return fixedprofinit + profname . replace ( /\w\S*/g , function ( txt ) {
return txt . charAt ( 0 ) . toUpperCase ( ) + txt . substr ( 1 ) . toLowerCase ( ) ;
if ( ! description )
description = "<p style='color:red;font-style:bold'>There was an error. Please refresh the page and/or log back in using your UT EID and password.</p>"
return description ;
}
function displayDescription ( description ) {
$ ( "#description" ) . animate ( {
'opacity' : 0
} , 200 , function ( ) {
$ ( this ) . html ( description ) . animate ( {
'opacity' : 1
} , 200 ) ;
} ) ;
}
/*Get the course description from the profurl and highlight the important elements, as well as set the eCIS, and rmp links.*/
function getDescription ( ) {
// console.log(window.location.href);
// console.log(profurl);
console . log ( 'hello' ) ;
function getDescription ( course _info ) {
console. log ( 'getting description for ' )
$ . ajax ( {
url : profurl ,
url : course _info [ "individual" ] ,
success : function ( response ) {
if ( response ) {
console . log ( profurl ) ;
var output = "" ;
var object = $ ( '<div/>' ) . html ( r esponse ) . content s( ) ;
object . find ( '#details > p' ) . each ( function ( ) {
var sentence = $ ( this ) . text ( ) ;
if ( sentence . indexOf ( "Prerequisite" ) == 0 ) {
sentence = "<li style='font-weight: bold;' class='descriptionli'>" + sentence + "</li>" ;
} else if ( sentence . indexOf ( "May be" ) >= 0 ) {
sentence = "<li style='font-style: italic;' class='descriptionli'>" + sentence + "</li>" ;
} else if ( sentence . indexOf ( "Restricted to" ) == 0 ) {
sentence = "<li style='color:red;' class='descriptionli'>" + sentence + "</li>" ;
} else {
sentence = "<li class='descriptionli'>" + sentence + "</li>" ;
}
output += sentence ;
} ) ;
description = output ;
console . log ( response ) ;
if ( ! description ) {
description = "<p style='color:red;font-style:bold'>There was an error. Please refresh the page and/or log back in using your UT EID and password.</p>"
}
$ ( "#description" ) . animate ( {
'opacity' : 0
} , 200 , function ( ) {
$ ( this ) . html ( description ) . animate ( {
'opacity' : 1
} , 200 ) ;
} ) ;
var first = object . find ( 'td[data-th="Instructor"]' ) . text ( ) ;
first = first . substring ( first . indexOf ( ", " ) , first . indexOf ( " " , first . indexOf ( ", " ) + 2 ) ) ;
first = first . substring ( 2 ) ;
rmpLink = ` http://www.ratemyprofessors.com/search.jsp?queryBy=teacherName&schoolName=university+of+texas+at+austin&queryoption=HEADER&query= ${ first } ${ profname } ;&facetSearch=true ` ;
if ( profname == "" ) {
eCISLink = ` http://utdirect.utexas.edu/ctl/ecis/results/index.WBX?s_in_action_sw=S&s_in_search_type_sw=C&s_in_max_nbr_return=10&s_in_search_course_dept= ${ department } &s_in_search_course_num= ${ course _nbr } ` ;
} else {
eCISLink = ` http://utdirect.utexas.edu/ctl/ecis/results/index.WBX?&s_in_action_sw=S&s_in_search_type_sw=N&s_in_search_name= ${ profname . substring ( 0 , 1 ) + profname . substring ( 1 ) . toLowerCase ( ) } %2C%20 ${ first . substring ( 0 , 1 ) + first . substring ( 1 ) . toLowerCase ( ) } ` ;
}
response _node = $ ( '<div/>' ) . html ( response ) . contents ( ) ;
description _lines = response _node . find ( '#details > p' ) . toArray ( ) . map ( x => $ ( x ) . text ( ) ) ;
displayDescription ( buildFormattedDescription ( d escription _line s) ) ;
let first _name = extractFirstName ( response _node ) ;
updateLinks ( course _info , first _name ) ;
} else {
description = "<p style='color:red;font-style:bold'>You have been logged out. Please refresh the page and log back in using your UT EID and password.</p>"
$ ( "#d escription" ) . animate ( {
'opacity' : 0
} , 200 , function ( ) {
$ ( this ) . html ( description ) . animate ( {
'opacity' : 1
} , 200 ) ;
} ) ;
rmpLink = "http://www.ratemyprofessors.com/campusRatings.jsp?sid=1255" ;
eCISLink = "http://utdirect.utexas.edu/ctl/ecis/results/index.WBX?" ;
displayD escription( description ) ;
}
}
} ) ;
}
function updateLinks ( course _info , first _name ) {
let {
prof _name ,
number
} = course _info ;
course _info [ "first_name" ] = first _name ;
course _info [ "links" ] [ "rate_my_prof" ] = ` http://www.ratemyprofessors.com/search.jsp?queryBy=teacherName&schoolName=university+of+texas+at+austin&queryoption=HEADER&query= ${ first _name } ${ prof _name } ;&facetSearch=true ` ;
course _info [ "links" ] [ "ecis" ] = profname ? ` http://utdirect.utexas.edu/ctl/ecis/results/index.WBX?&s_in_action_sw=S&s_in_search_type_sw=N&s_in_search_name= ${ prof _name } %2C%20 ${ first _name } ` :
` http://utdirect.utexas.edu/ctl/ecis/results/index.WBX?s_in_action_sw=S&s_in_search_type_sw=C&s_in_max_nbr_return=10&s_in_search_course_dept= ${ department } &s_in_search_course_num= ${ number } ` ;
}
function extractFirstName ( response _node ) {
let full _name = response _node . find ( 'td[data-th="Instructor"]' ) . text ( ) . split ( ', ' ) ;
let first = full _name [ full _name . length - 1 ] ;
return capitalizeString ( first ) ;
}