From 763030ff4e2af3c54f869b2749aef167488666b7 Mon Sep 17 00:00:00 2001 From: "Alex Xu (Hello71)" Date: Thu, 20 Sep 2018 11:25:35 -0400 Subject: Update script.js --- script.js | 120 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 62 insertions(+), 58 deletions(-) (limited to 'script.js') diff --git a/script.js b/script.js index b363ce7..9ec7707 100644 --- a/script.js +++ b/script.js @@ -240,7 +240,7 @@ switch (cached_ycq_s.sess) { fw_sess.selected = true; } -let ENGLISH_TYPES = {"fac": "faculty", "subj": "subject/subject", "crsn": "course number", "cred": "credit number", "sess": "session (pick on the right)"}; +let ENGLISH_TYPES = {"fac": "faculty", "subj": "subject", "crsn": "course number", "cred": "credit number"}; function ready() { let ywhAd = document.getElementById("ywh-ad"); @@ -286,7 +286,7 @@ function ready() { got("cred", parseFloat(token).toFixed(2)); warn.push(`assuming ${token} is the number of credits`); } else if (MAYBE_DEPT_RE.test(token)) { - state.maybeSubj = token; + state["maybeSubj"] = token; } else if (!IGNORE_RE.test(token)) { return false; } @@ -299,84 +299,84 @@ function ready() { warn.push(`don't understand search term: ${token}`); }); - if (!state.subj && state.maybeSubj) { - state.subj = state.maybeSubj; - warn.push("guessing subject is " + state.maybeSubj); + if (!state["subj"] && state["maybeSubj"]) { + state["subj"] = state["maybeSubj"]; + warn.push("guessing subject is " + state["maybeSubj"]); } - if (!state.subj && state.crsn && cached_ycq_s.course_subjs[state.crsn]) { - state.subj = cached_ycq_s.course_subjs[state.crsn]; - warn.push(`using saved subject for ${state.crsn}: ${state.subj}`); + if (!state["subj"] && state["crsn"] && cached_ycq_s.course_subjs[state["crsn"]]) { + state["subj"] = cached_ycq_s.course_subjs[state["crsn"]]; + warn.push(`using saved subject for ${state["crsn"]}: ${state["subj"]}`); } - if (!state.subj && cached_ycq_s.default_subj) { - state.subj = cached_ycq_s.default_subj; - warn.push(`using saved default subject: ${state.subj}`); + if (!state["subj"] && cached_ycq_s.default_subj) { + state["subj"] = cached_ycq_s.default_subj; + warn.push(`using saved default subject: ${state["subj"]}`); } - if (!state.fac && state.subj) { + if (!state["fac"] && state["subj"]) { // if no faculty, try: // 1. most recent faculty for this course // 2. most recent faculty for this subject // 3. most recent compatible faculty // 4. first compatible faculty + if (SUBJS.hasOwnProperty(state["subj"])) { + var compat_facs = SUBJS[state["subj"]]; + let other_facs = compat_facs + .filter(f => f != state["fac"]) + .map(f => `${f}`) + .join(", "); + var other_options = `, other options: ${other_facs}`; + } // 1. most recent faculty for this course - if (state.crsn && cached_ycq_s.course_facs[state.subj + state.crsn]) { - state.fac = cached_ycq_s.course_facs[state.subj + state.crsn]; - warn.push(`using saved faculty for ${state.subj} ${state.crsn}: ${state.fac}, other options maybe: ${other_facs}`); - } else if (cached_ycq_s.subj_facs[state.subj]) { + if (state["crsn"] && cached_ycq_s.course_facs[state["subj"] + state["crsn"]]) { + state["fac"] = cached_ycq_s.course_facs[state["subj"] + state["crsn"]]; + warn.push(`using saved faculty for ${state["subj"]} ${state["crsn"]}: ${state["fac"]}${other_options}`); + } else if (cached_ycq_s.subj_facs[state["subj"]]) { // 2. most recent faculty for this subject - state.fac = cached_ycq_s.subj_facs[state.subj]; - warn.push(`using saved faculty for ${state.subj}: ${state.fac}, other options: ${other_facs}`); - } else if (SUBJS.hasOwnProperty(state.subj)) { - let compat_facs = SUBJS[state.subj]; - + state["fac"] = cached_ycq_s.subj_facs[state["subj"]]; + warn.push(`using saved faculty for ${state["subj"]}: ${state["fac"]}${other_options}`); + } else if (compat_facs) { // 3. most recent compatible faculty if (cached_ycq_s.default_facs) for (let i = cached_ycq_s.default_facs.length - 1; i >= 0; i--) if (compat_facs.indexOf(cached_ycq_s.default_facs[i]) > -1) - state.fac = cached_ycq_s.default_facs[i]; + state["fac"] = cached_ycq_s.default_facs[i]; - let using_faculty = "saved"; - // 4. first compatible faculty - if (!state.fac) { - state.fac = compat_facs[0]; - using_faculty = "default"; + if (state["fac"]) { + warn.push(`using saved faculty: ${state["fac"]}${other_options}`); + } else { + // 4. first compatible faculty + state["fac"] = compat_facs[0]; + warn.push(`using default faculty for ${state["subj"]}: ${state["fac"]}${other_options}`); } - - let other_facs = compat_facs - .filter(f => f != state.fac) - .map(f => `${f}`) - .join(", "); - if (other_facs) - warn.push(`using ${using_faculty} faculty for ${state.subj}: ${state.fac}, other options: ${other_facs}`); } else { error.push("no faculty provided and unknown subject"); } } - if (state.subj && state.crsn && !state.cred) { - if (cached_ycq_s.course_creds[state.subj + state.crsn]) { - state.cred = cached_ycq_s.course_creds[state.subj + state.crsn]; - warn.push(`using saved credit number for ${state.subj} ${state.crsn}: ${state.cred}`); + if (state["subj"] && state["crsn"] && !state["cred"]) { + if (cached_ycq_s.course_creds[state["subj"] + state["crsn"]]) { + state["cred"] = cached_ycq_s.course_creds[state["subj"] + state["crsn"]]; + warn.push(`using saved credit number for ${state["subj"]} ${state["crsn"]}: ${state["cred"]}`); } else { - state.cred = "3.00"; + state["cred"] = "3.00"; warn.push("assuming the number of credits is 3.00"); } } let sess = document.getElementById("sessions").value.split(" "); - state.sess = sess[0]; - state.year = parseInt(sess[1], 10); + state["sess"] = sess[0]; + state["year"] = parseInt(sess[1], 10); - if (state.fac && state.subj && state.crsn && state.cred && state.year && state.sess) { - link.href = `https://w2prod.sis.yorku.ca/Apps/WebObjects/cdm.woa/wa/crsq?fa=${state.fac}&sj=${state.subj}&cn=${state.crsn}&cr=${state.cred}&ay=${state.year}&ss=${state.sess}`; - link.textContent = `${state.fac}/${state.subj} ${state.crsn} ${state.cred} (${sessions.selectedOptions[0].textContent}) | York University`; + if (state["fac"] && state["subj"] && state["crsn"] && state["cred"] && state["year"] && state["sess"]) { + link.href = `https://w2prod.sis.yorku.ca/Apps/WebObjects/cdm.woa/wa/crsq?fa=${state["fac"]}&sj=${state["subj"]}&cn=${state["crsn"]}&cr=${state["cred"]}&ay=${state["year"]}&ss=${state["sess"]}`; + link.textContent = `${state["fac"]}/${state["subj"]} ${state["crsn"]} ${state["cred"]} (${sessions.selectedOptions[0].textContent}) | York University`; linkContainer.style.display = "block"; - } else if (state.fac && state.subj && state.sess) { - link.href = `https://w2prod.sis.yorku.ca/Apps/WebObjects/cdm.woa/wa/crsq1?faculty=${state.fac}&subject=${state.subj}&academicyear=${state.year}&studysession=${state.sess}`; - link.textContent = `${state.fac}/${state.subj} Courses (${sessions.selectedOptions[0].textContent}) | York University`; + } else if (state["fac"] && state["subj"] && state["sess"]) { + link.href = `https://w2prod.sis.yorku.ca/Apps/WebObjects/cdm.woa/wa/crsq1?faculty=${state["fac"]}&subject=${state["subj"]}&academicyear=${state["year"]}&studysession=${state["sess"]}`; + link.textContent = `${state["fac"]}/${state["subj"]} Courses (${sessions.selectedOptions[0].textContent}) | York University`; linkContainer.style.display = "block"; } else { linkContainer.style.display = "none"; @@ -418,10 +418,10 @@ function ready() { let old_ycq_s_s = localStorage.ycq; let new_ycq_s = parse_ycq_s(old_ycq_s_s); - if (state.fac) { + if (state["fac"]) { let default_facs = new Set(new_ycq_s.default_facs); - default_facs.delete(state.fac); - default_facs.add(state.fac); + default_facs.delete(state["fac"]); + default_facs.add(state["fac"]); let new_facs = Array.from(default_facs); if (new_facs.length != new_ycq_s.default_facs.length || new_facs.some((v, i) => v !== new_ycq_s.default_facs[i])) { @@ -429,18 +429,22 @@ function ready() { } } - if (state.subj) { - if (state.crsn) { - if (state.fac) - new_ycq_s.course_facs[state.subj + state.crsn] = state.fac; + if (state["subj"]) { + if (state["fac"]) { + if (state["crsn"]) + new_ycq_s.course_facs[state["subj"] + state["crsn"]] = state["fac"]; + + new_ycq_s.subj_facs[state["subj"]] = state["fac"]; + } - if (state.cred) - new_ycq_s.course_creds[state.subj + state.crsn] = state.cred; + if (state["crsn"]) { + if (state["cred"]) + new_ycq_s.course_creds[state["subj"] + state["crsn"]] = state["cred"]; - new_ycq_s.course_subjs[state.crsn] = state.subj; + new_ycq_s.course_subjs[state["crsn"]] = state["subj"]; } - new_ycq_s.default_subj = state.subj; + new_ycq_s.default_subj = state["subj"]; } new_ycq_s.sess = document.getElementById("sessions").value; -- cgit v1.2.3-54-g00ecf