diff options
author | Alex Xu (Hello71) <alex_y_xu@yahoo.ca> | 2018-09-10 09:35:27 -0400 |
---|---|---|
committer | Alex Xu (Hello71) <alex_y_xu@yahoo.ca> | 2018-09-10 09:35:27 -0400 |
commit | 7a4b3595a3265495ffa44e0aff57964517ad4cb3 (patch) | |
tree | 7598a13fcfecbefb18aae353c9abd49bb353f87b /script.js | |
download | yorku-course-query-7a4b3595a3265495ffa44e0aff57964517ad4cb3.tar.xz yorku-course-query-7a4b3595a3265495ffa44e0aff57964517ad4cb3.zip |
Initial commit
Diffstat (limited to 'script.js')
-rw-r--r-- | script.js | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/script.js b/script.js new file mode 100644 index 0000000..6325077 --- /dev/null +++ b/script.js @@ -0,0 +1,110 @@ +var FACS = new Set(); +var DEPTS = new Map(); +// maintain: CDM Advanced Search +// console.log(Array.prototype.map.call(document.getElementsByName("subjectPopup")[0].children, (e)=>'"' + e.textContent.match(/[A-Z]{2,4}/)[0] + '"').join(", ")) +[ + ["AP", "ADMB", "ADMS", "ANTH", "ARB", "ASL", "CCY", "CDNS", "CH", "CLST", "CLTR", "COGS", "COMN", "CRIM", "DEMS", "DLLL", "ECON", "EN", "ESL", "FND", "FR", "GCIN", "GEOG", "GER", "GK", "GKM", "GWST", "HEB", "HIST", "HREQ", "HRM", "HUMA", "INDG", "INDV", "IT", "ITEC", "JC", "JP", "KOR", "LA", "LASO", "LING", "LLS", "MIST", "MODR", "PERS", "PHIL", "POLS", "POR", "PPAS", "PRWR", "RU", "SOCI", "SOSC", "SOWK", "SP", "SWAH", "SXST", "TESL", "TYP", "WKLS", "WRIT"], + ["ED", "AUCO", "BBED", "BIOL", "CHEM", "DANC", "DEST", "DRAA", "ECON", "EDFE", "EDFR", "EDIN", "EDIS", "EDJI", "EDPJ", "EDPR", "EDST", "EDUC", "EN", "ENVS", "FAST", "FREN", "GEOG", "HEB", "HIST", "INDS", "LAW", "LLDV", "MATH", "MUSI", "ORCO", "PHED", "PHIL", "PHYS", "POLS", "PRAC", "SCIE", "SLGS", "SOSC", "TECH", "TLSE", "VISA"], + ["ES", "ENVS"], + ["FA", "ARTH", "DANC", "DATT", "DESN", "FACS", "FILM", "INDV", "MUSI", "PANF", "THEA", "VISA", "YSDN"], + ["GL", "BIOL", "BUEC", "CAT", "CDNS", "COMS", "CSLA", "DRST", "ECON", "EN", "ENSL", "FRAN", "FSL", "GWST", "HIST", "HUMA", "ILST", "ITEC", "LIN", "LYON", "MATH", "MODR", "NATS", "PHIL", "PHYS", "POLS", "PSYC", "SOCI", "SOSC", "SP", "SXST", "TRAN", "WKST", "WMST"], + ["GS", "ANTH", "ARTH", "BIOL", "BLIS", "CDIS", "CGTA", "CHEM", "CIVL", "CMCT", "DANC", "DEMS", "DIGM", "DVST", "ECON", "EDUC", "EECS", "EIL", "EN", "ENG", "ENVS", "ESS", "FACC", "FILM", "FREN", "GEOG", "GFWS", "HIST", "HLTH", "HRM", "HUMA", "INST", "INTE", "ITEC", "KAHS", "LAL", "LAW", "LREL", "MATH", "MDES", "MECH", "MUSI", "NURS", "OVGS", "PACC", "PHIL", "PHYS", "PIA", "POLS", "PPAL", "PSYC", "SLST", "SOCI", "SOWK", "SPTH", "STS", "THEA", "THST", "TRAN", "TRAS", "TXLW", "VISA", "WMST"], + ["HH", "HLST", "IHST", "KINE", "NURS", "PKIN", "PSYC"], + ["LE", "CIVL", "COOP", "EECS", "ENG", "ESSE", "MECH"], + ["SB", "ACTG", "ARTM", "BSUS", "DCAD", "ECON", "EMBA", "ENTR", "EXCH", "FINE", "FNEN", "FNSV", "HIMP", "IBUS", "MBA", "INTL", "MACC", "MBAN", "MFIN", "MGMT", "MINE", "MKTG", "MSTM", "OMIS", "ORGS", "OVGS", "PLCY", "PROP", "PUBL", "SGMT", "SOCM"], + ["SC", "BC", "BCHM", "BIOL", "BPHS", "CHEM", "COOP", "ENVB", "GEOG", "ISCI", "MATH", "NATS", "PHYS", "SENE", "STS"] +].forEach((arr) => { + var faculty = arr.shift(); + FACS.add(faculty); + arr.forEach((dept) => DEPTS.set(dept, faculty)); +}); + +var TOKEN_DELIM_RE = /[^A-Za-z0-9.]/; +var CRSN_RE = /^[0-9]{4}$/; +var DEPTCRSN_RE = /^([A-Z]{2,4})([0-9]{4})$/; +var CRED_RE = /(?:Cr=)?([0-9]{1,2}\.[0-9]{1,2})/; +var MAYBE_DEPT_RE = /[A-Z]{2,4}/; +var USELESS_RE = /^(?:[A-Z])$/; + +function warn(str) { + console.warn(str); +} + +function got(state, type, token, guess) { + if (state[type]) + warn("already have " + type); + state[type] = token; +} + +function fullyear(str) { + return str.length == 2 + ? "" + CENTURY + str + : str; +} + +document.addEventListener("DOMContentLoaded", function () { + var faculty = document.querySelector("#faculty"); + var dept = document.querySelector("#dept"); + var crsn = document.querySelector("#crsn"); + var input = document.querySelector("#input"); + var link = document.querySelector("#link"); + + var defaults = {"fac": "AP", "dept": "ADMS", "crsn": "1000"}; + + var apply = function () { + var state = {}; + + input.value.split(TOKEN_DELIM_RE).forEach(function (token) { + if (DEPTS.has(token)) { + got(state, "dept", token); + return; + } + if (FACS.has(token)) { + got(state, "fac", token, true); + return; + } + var deptcrsn = DEPTCRSN_RE.exec(token); + if (deptcrsn) { + got(state, "dept", deptcrsn[1]); + got(state, "crsn", deptcrsn[2]); + return; + } + var cred = CRED_RE.exec(token); + if (cred) { + got(state, "cred", parseFloat(cred[1]).toFixed(2)); + return; + } + if (CRSN_RE.test(token)) { + got(state, "crsn", token); + return; + } + if (MAYBE_DEPT_RE.test(token)) { + got(state, "maybeDept", token); + return; + } + if (USELESS_RE.test(token)) { + return; + } + warn("don't understand search term: " + token); + }); + + if (!state.dept && state.maybeDept) { + state.dept = state.maybeDept; + warn("guessing department is " + state.maybeDept); + } + + if (!state.fac && state.dept) { + state.fac = DEPTS.get(state.dept); + if (!state.fac) + warn("unknown department"); + } + + console.log(state); + + if (state.fac && state.dept && state.crsn && state.cred && state.year && state.term) + link.href = `https://w2prod.sis.yorku.ca/Apps/WebObjects/cdm.woa/wa/crsq?fa=${state.fac}&sj=${state.dept}&cn=${state.crsn}&cr=${state.cred}&ay=${state.year}&ss=${state.sess}` + }; + + input.addEventListener("input", apply); + apply(); +}); |