From 7a4b3595a3265495ffa44e0aff57964517ad4cb3 Mon Sep 17 00:00:00 2001 From: "Alex Xu (Hello71)" Date: Mon, 10 Sep 2018 09:35:27 -0400 Subject: Initial commit --- index.html | 36 ++++++++++++++++++++ script.js | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ style.css | 44 +++++++++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100644 index.html create mode 100644 script.js create mode 100644 style.css diff --git a/index.html b/index.html new file mode 100644 index 0000000..757de9d --- /dev/null +++ b/index.html @@ -0,0 +1,36 @@ + + + + + Unofficial York University Course Query + + + + +
+
+
+ + +
+
+
+ + + + + + + + + + + + + +
FacultyDept./Subj.NumberCredits
+ Course Query +
+
+ + 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(); +}); diff --git a/style.css b/style.css new file mode 100644 index 0000000..4ac2f88 --- /dev/null +++ b/style.css @@ -0,0 +1,44 @@ +html { + box-sizing: border-box; + font-size: 16px; +} + +*, *:before, *:after { + box-sizing: inherit; +} + +body, h1, h2, h3, h4, h5, h6, p, ol, ul { + margin: 0; + padding: 0; + font-weight: normal; +} + +ol, ul { + list-style: none; +} + +img { + max-width: 100%; + height: auto; +} + +.container { + margin: 5px; +} + +div { + margin: 5px; +} + +table { + border-collapse: collapse; +} + +table, td, th { + border: 1px solid black; + padding: 5px; +} + +.default { + color: #aaa; +} -- cgit v1.2.3-70-g09d2