Skip to content

Commit

Permalink
support for french course overview pages and show year with term in t…
Browse files Browse the repository at this point in the history
…erm image tooltip
  • Loading branch information
demetrios-koziris committed Dec 26, 2016
1 parent d68a83a commit 41411c9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 32 deletions.
69 changes: 42 additions & 27 deletions src/js/addProfLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,27 @@ The GNU General Public License can also be found at <http://www.gnu.org/licenses

function makeProfLinks() {



terms = {
'Fall': 'https://www.mcgill.ca/ece/sites/all/modules/mcgill/courses/fall.gif',
'Winter': 'https://www.mcgill.ca/ece/sites/all/modules/mcgill/courses/winter.gif',
'Summer': 'https://www.mcgill.ca/ece/sites/all/modules/mcgill/courses/summer.gif'
'Fall': {
'code': 9,
'year': urlYearF
},
'Winter': {
'code': 1,
'year': urlYearW
},
'Summer': {
'code': 5,
'year': urlYearW
}
};
inst = {
'en': 'Instructors:',
'fr': 'Chargés de cours :'
};
profs = {};
const profsByTerm = {};
const minervaProfs = getProfData();
let profsLength = 0;

Expand All @@ -39,41 +53,42 @@ function makeProfLinks() {

if (!profsFullSource.match(/There are no professors/)) {

const profsFullSourceArray = profsFullSource.match(/(Fall|Winter|Summer)/g);
for (let a = 0; a < profsFullSourceArray.length; a++) {
if (!(profsFullSourceArray[a] in profsByTerm)) {
profsByTerm[profsFullSourceArray[a]] = [];
}
if (profsFullSource.match(inst[lang])) {
profsFullSource = profsFullSource.split(inst[lang])[1];
}
else {
// this is necessary because some french pages use the english language for 'Instructors:'
profsFullSource = profsFullSource.split(inst.en)[1];
}

profsFullSource = profsFullSource.split("Instructors:")[1];

for (let termKey in profsByTerm) {
for (let termKey in terms) {

const profsTermSource = profsFullSource.split("(" + termKey + ")");
if (profsTermSource.length > 1) {
profsByTerm[termKey] = profsTermSource[0].split(",");
profsForTerm = profsTermSource[0].split(",");

for (let p=0; p<profsByTerm[termKey].length; p++) {
for (let p=0; p<profsForTerm.length; p++) {

let prof = generateProfObject(minervaProfs, profsByTerm[termKey][p], termKey);
if (prof.key in profs) {
profs[prof.key].terms[termKey] = '';
let newProfObject = generateProfObject(minervaProfs, profsForTerm[p], termKey);
if (newProfObject.key in profs) {
// add term to prof object
profs[newProfObject.key].termsTeaching[termKey] = terms[termKey];
console.log(terms[termKey]);
}
else {
profs[prof.key] = prof;
profs[newProfObject.key] = newProfObject;
profs[newProfObject.key].termsTeaching[termKey] = terms[termKey];
console.log(newProfObject);
}
}

logForDebug(profsByTerm[termKey]);
profsFullSource = profsTermSource[1];
}
}

const profSection = document.createElement('div');

const profSectionTitle = document.createElement('div');
profSectionTitle.innerHTML = '<b>Instructors:</b>';
profSectionTitle.innerHTML = '<b>' + inst[lang] + '</b>';
profSection.appendChild(profSectionTitle);

for (let profKey in profs) {
Expand Down Expand Up @@ -125,10 +140,11 @@ function makeProfLinks() {
termImg.src = chrome.extension.getURL('icons/empty-15.png');
termDiv.appendChild(termImg);

if (termKey in prof.terms) {
termDiv.title = termKey;
if (termKey in prof.termsTeaching) {
termInfo = prof.termsTeaching[termKey];
termDiv.title = termNames[lang][termInfo.code] + ' ' + termInfo.year;
termDiv.className += ' tooltip';
termImg.src = terms[termKey];
termImg.src = 'https://www.mcgill.ca/ece/sites/all/modules/mcgill/courses/' + termKey.toLowerCase() + '.gif';
}
}

Expand Down Expand Up @@ -183,7 +199,7 @@ function makeProfLinks() {
}


function generateProfObject(minervaProfs, origName, term) {
function generateProfObject(minervaProfs, origName, termKey) {
const name = origName.trim();
const splitName = name.split(' ');
const profName = {
Expand All @@ -193,14 +209,13 @@ function generateProfObject(minervaProfs, origName, term) {
};
const prof = {
key: name.replace(/\W/g, ''),
terms: {},
termsTeaching: {},
minerva: minervaProfs[name],
name: profName,
urlCourses: 'https://www.mcgill.ca/study/' + urlYears + '/courses/search' + (isNewStyle ? '?search_api_views_fulltext=' : '/') + profName.full,
urlGoogle: 'https://www.google.ca/search?q="rate"+"mcgill"+' + profName.first + '+' + profName.last,
urlMercury: 'https://horizon.mcgill.ca/pban1/bzskmcer.p_display_form?form_mode=ar&inst_tab_in=' + minervaProfs[profName.full]
};
prof.terms[term] = '';
return prof;
}

6 changes: 3 additions & 3 deletions src/js/addSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ function makeSidebarContent() {

const courseTerms = document.getElementsByClassName("catalog-terms")[0].innerHTML;
const courseTermsCodes = [];
if (courseTerms.match(/Fall/)) {
if (courseTerms.match(termNames[lang][9])) {
courseTermsCodes.push( {
name: "Fall " + urlYearF,
code: urlYearF + "09",
vsbURL: "https://vsb.mcgill.ca/vsb/criteria.jsp?term=" + urlYearF + "09&course_0_0=" + courseSubject + "-" + courseNumber + "&ca_0_0=&bbs="
} );
}
if (courseTerms.match(/Winter/)) {
if (courseTerms.match(termNames[lang][1])) {
courseTermsCodes.push( {
name: "Winter " + urlYearW,
code: urlYearW + "01",
vsbURL: "https://vsb.mcgill.ca/vsb/criteria.jsp?term=" + urlYearW + "01&course_0_0=" + courseSubject + "-" + courseNumber + "&ca_0_0=&bbs="
} );
}
if (courseTerms.match(/Summer/)) {
if (courseTerms.match(termNames[lang][05])) {
courseTermsCodes.push( {
name: "Summer " + urlYearW,
code: urlYearW + "05"
Expand Down
20 changes: 19 additions & 1 deletion src/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,37 @@ if (url.match(/.+www\.mcgill\.ca\/study\/.+/)) {

const start = Date.now();

const courseNameRegex = /([A-Z]{3,4}[0-9]{0,1})\s([0-9]{3}[A-Za-z]{0,1}[0-9]{0,1})/g;
courseNameRegex = /([A-Z]{3,4}[0-9]{0,1})\s([0-9]{3}[A-Za-z]{0,1}[0-9]{0,1})/g;
isNewStyle = document.getElementsByClassName("transition").length > 0;
urlYearF = parseInt(url.match(/.+(20[0-9][0-9])-.+/)[1]);
urlYearW = urlYearF+1;
urlYears = urlYearF + "-" + urlYearW;
sysYear = new Date().getFullYear();
sysMonth = new Date().getMonth();
var lang = 'en';
if (url.match(/\/fr\//)) {
lang = 'fr';
}

if (url.match(/.+(20[0-9][0-9])-(20[0-9][0-9]).+/)) {
addYearMenu();
}

if (url.match(/.+study.+courses.+[-]+/)) {

termNames = {
'en': {
9: 'Fall',
1: 'Winter',
5: 'Summer'
},
'fr': {
9: 'Automne',
1: 'Hiver',
5: 'Été'
},
};

makeProfLinks();
makeCourseLinks(courseNameRegex);
makeSidebarContent();
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "McGill Enhanced",
"author": "Demetrios Koziris",
"manifest_version": 2,
"version": "3.0.27",
"version": "3.0.28",
"description": "Enhance the functionality of McGill.ca",
"permissions" : [
"declarativeContent",
Expand Down

0 comments on commit 41411c9

Please sign in to comment.