summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2018-09-19 11:12:54 -0400
committerAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2018-09-19 11:12:54 -0400
commite8d499f682950d02fb143b504ced7cefac23534a (patch)
treea8258e1c15b4c80bb1f474c38937b6ab5b0f4eea
parent87c3ae27d68cdecb967d91a56146dc7874867a8b (diff)
downloadyorku-course-query-e8d499f682950d02fb143b504ced7cefac23534a.tar.xz
yorku-course-query-e8d499f682950d02fb143b504ced7cefac23534a.zip
Update
-rw-r--r--index.html21
-rw-r--r--script.js118
-rw-r--r--style.css33
3 files changed, 111 insertions, 61 deletions
diff --git a/index.html b/index.html
index 806ab96..6417825 100644
--- a/index.html
+++ b/index.html
@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>Unofficial York University Course Query</title>
- <script src="script.js"></script>
+ <script async src="script.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
@@ -21,25 +21,36 @@
<a href="#" class="sample-query">ADMS 1000 3</a>,
<a href="#" class="sample-query">LE EECS 3000 Cr=3.00 A Term:F Professional Practice in Computing</a>
</span>
+ </div>
+ <hr>
<div>
<form method="GET">
<table>
<tr>
- <td><input type="text" id="input"></td>
+ <td style="width: 100%"><input type="text" id="input"></td>
<td><select id="sessions" size="2"></select></td>
</tr>
</table>
</form>
</div>
<hr>
- <div>
- <span id="error"></span>
+ <div id="error">
</div>
<div id="link-container">
<p><a id="link" rel="noopener noreferrer">Course Query</a></p>
</div>
+ <div id="warning">
+ </div>
<div>
- <span id="warning"></span>
+ <p>
+ Tips:
+ <ul>
+ <li id="ywh-ad">works best with YorkU Web Helper, available for Firefox and Chrome</li>
+ <li><strong>you can bookmark the link, and it will always bring you to the right page (no more "Your session has expired"!)</strong></li>
+ <li>ctrl-enter in the box opens the result in a new tab, shift-enter opens in a new window</li>
+ <li>remember to select the session you want on the right of the search box</li>
+ </ul>
+ </p>
</div>
</div>
</body>
diff --git a/script.js b/script.js
index 494bfca..1536c4d 100644
--- a/script.js
+++ b/script.js
@@ -2,7 +2,7 @@
"use strict";
const FACS = new Set();
const DEPTS = new Map();
-// maintain: CDM Advanced Search
+// 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"],
@@ -18,7 +18,7 @@ const DEPTS = new Map();
].forEach((arr) => {
let faculty = arr.shift();
FACS.add(faculty);
- arr.forEach((dept) => DEPTS.set(dept, faculty));
+ arr.forEach((subj) => DEPTS.set(subj, faculty));
});
const TOKEN_DELIM_RE = /[^A-Za-z0-9.=]/;
@@ -32,7 +32,8 @@ const IGNORE_RE = /^[A-Z]$/;
let ycq_storage = JSON.parse(localStorage.ycq || "{}");
if (!ycq_storage)
ycq_storage = {};
-ycq_storage.courses = ycq_storage.courses || {};
+ycq_storage.course_creds = ycq_storage.course_creds || {};
+ycq_storage.course_subjs = ycq_storage.course_subjs || {};
let now = new Date();
let month = now.getMonth();
@@ -64,9 +65,14 @@ switch (ycq_storage.sess) {
fw_sess.selected = true;
}
-let ENGLISH_TYPES = {"fac": "faculty", "dept": "department/subject", "crsn": "course number", "cred": "credit number", "sess": "session (pick on the right)"};
+let ENGLISH_TYPES = {"fac": "faculty", "subj": "subject/subject", "crsn": "course number", "cred": "credit number", "sess": "session (pick on the right)"};
+
+function ready() {
+ let ywhAd = document.getElementById("ywh-ad");
+ if (location.protocol != "http:" && location.protocol != "https:" && location.protocol != "file:") {
+ ywhAd.style.display = "none";
+ }
-document.addEventListener("DOMContentLoaded", function () {
let sessions = document.querySelector("#sessions");
sessions.appendChild(fw_sess);
sessions.appendChild(s_sess);
@@ -75,12 +81,10 @@ document.addEventListener("DOMContentLoaded", function () {
let link = document.getElementById("link");
let linkContainer = document.getElementById("link-container");
- var crsn, cred;
-
- var state;
+ let state;
let apply = function () {
- state = {dept: "", fac: "", crsn: "", cred: ""};
+ state = {subj: "", fac: "", crsn: "", cred: ""};
let multiple = new Set();
let warn = [], error = [];
@@ -91,14 +95,14 @@ document.addEventListener("DOMContentLoaded", function () {
};
let tryParse = function (token) {
- let deptcrsn, cred;
+ let subjcrsn, cred;
if (DEPTS.has(token)) {
- got("dept", token);
+ got("subj", token);
} else if (FACS.has(token)) {
got("fac", token);
- } else if ((deptcrsn = DEPTCRSN_RE.exec(token))) {
- got("dept", deptcrsn[1]);
- got("crsn", deptcrsn[2]);
+ } else if ((subjcrsn = DEPTCRSN_RE.exec(token))) {
+ got("subj", subjcrsn[1]);
+ got("crsn", subjcrsn[2]);
} else if ((cred = CRED_RE.exec(token))) {
got("cred", parseFloat(cred[1] || cred[2]).toFixed(2));
} else if (CRSN_RE.test(token)) {
@@ -107,7 +111,7 @@ document.addEventListener("DOMContentLoaded", function () {
got("cred", parseFloat(token).toFixed(2));
warn.push(`assuming ${token} is the number of credits`);
} else if (MAYBE_DEPT_RE.test(token)) {
- state.maybeDept = token;
+ state.maybeSubj = token;
} else if (!IGNORE_RE.test(token)) {
return false;
}
@@ -120,21 +124,26 @@ document.addEventListener("DOMContentLoaded", function () {
warn.push("don't understand search term: " + token);
});
- if (!state.dept && state.maybeDept) {
- state.dept = state.maybeDept;
- warn.push("guessing department is " + state.maybeDept);
+ if (!state.subj && state.maybeSubj) {
+ state.subj = state.maybeSubj;
+ warn.push("guessing subject is " + state.maybeSubj);
+ }
+
+ if (!state.subj && ycq_storage.course_subjs[state.crsn]) {
+ state.subj = ycq_storage.course_subjs[state.crsn];
+ warn.push(`using saved subject for ${state.crsn}: ${state.subj}`);
}
- if (!state.fac && state.dept) {
- state.fac = DEPTS.get(state.dept);
+ if (!state.fac && state.subj) {
+ state.fac = DEPTS.get(state.subj);
if (!state.fac)
- error.push("no faculty provided and unknown department");
+ error.push("no faculty provided and unknown subject");
}
- if (state.crsn && !state.cred) {
- if (ycq_storage.courses[state.dept + state.crsn]) {
- state.cred = ycq_storage.courses[state.crsn];
- warn.push(`using saved credit number for ${state.dept} ${state.crsn}: ${state.cred}`);
+ if (state.subj && state.crsn && !state.cred) {
+ if (ycq_storage.course_creds[state.subj + state.crsn]) {
+ state.cred = ycq_storage.course_creds[state.crsn];
+ warn.push(`using saved credit number for ${state.subj} ${state.crsn}: ${state.cred}`);
} else {
state.cred = "3.00";
warn.push("assuming the number of credits is 3.00");
@@ -144,19 +153,19 @@ document.addEventListener("DOMContentLoaded", function () {
let r_sess = document.getElementById("sessions").value;
let sess = r_sess.split(" ");
state.sess = sess[0];
- state.year = parseInt(sess[1]);
-
- if (state.fac && state.dept && 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.dept}&cn=${state.crsn}&cr=${state.cred}&ay=${state.year}&ss=${state.sess}`;
- link.textContent = `York University: ${state.fac}/${state.dept} ${state.crsn} ${state.cred} (${sessions.selectedOptions[0].textContent})`;
- linkContainer.style = "display: block";
- } else if (state.fac && state.dept && state.sess) {
- link.href = `https://w2prod.sis.yorku.ca/Apps/WebObjects/cdm.woa/wa/crsq1?faculty=${state.fac}&subject=${state.dept}&academicyear=${state.year}&studysession=${state.sess}`;
- link.textContent = `York University: ${state.fac}/${state.dept} Courses (${sessions.selectedOptions[0]. textContent})`;
- linkContainer.style = "display: block";
+ 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 = `York University: ${state.fac}/${state.subj} ${state.crsn} ${state.cred} (${sessions.selectedOptions[0].textContent})`;
+ 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 = `York University: ${state.fac}/${state.subj} Courses (${sessions.selectedOptions[0]. textContent})`;
+ linkContainer.style.display = "block";
} else {
- linkContainer.style = "display: none";
- error.push("insufficient search parameters. need at least department/subject. see examples above");
+ linkContainer.style.display = "none";
+ error.push("insufficient search parameters. need at least subject. see examples above");
}
if (multiple.size)
@@ -174,18 +183,30 @@ document.addEventListener("DOMContentLoaded", function () {
document.getElementById("sample-queries").addEventListener("click", function (e) {
if (e.target.tagName == "A") {
e.preventDefault();
- input.value = e.target.textContent;
+ input.select();
+ // doesn't work in Firefox, oh well
+ if (!document.execCommand || !document.execCommand("insertText", false, e.target.textContent))
+ input.value = e.target.textContent;
apply();
input.focus();
}
});
- var apply_crsn_cred = function () {
- if (state.crsn && state.cred) {
- ycq_storage.courses[state.dept + state.crsn] = state.cred;
- localStorage.ycq = JSON.stringify(ycq_storage);
+ let save_crsn = function () {
+ let modified = false;
+ if (state.crsn) {
+ if (state.subj && state.cred) {
+ ycq_storage.course_creds[state.subj + state.crsn] = state.cred;
+ modified = true;
+ }
+ if (state.subj) {
+ ycq_storage.course_subjs[state.crsn] = state.subj;
+ modified = true;
+ }
}
+ if (modified)
+ localStorage.ycq = JSON.stringify(ycq_storage);
};
- link.addEventListener("click", apply_crsn_cred);
+ link.addEventListener("click", save_crsn);
document.forms[0].addEventListener("submit", function (e) {
e.preventDefault();
if (linkContainer.style.display == "block")
@@ -202,7 +223,8 @@ document.addEventListener("DOMContentLoaded", function () {
link.click();
link.target = "";
} else if (e.shiftKey) {
- apply_crsn_cred();
+ // only need save_crsn here because other methods already trigger the link click event
+ save_crsn();
window.open(link.href, "_blank",
"noopener,width=625,resizable,menubar,toolbar,location,personalbar,status,scrollbars");
} else {
@@ -215,5 +237,11 @@ document.addEventListener("DOMContentLoaded", function () {
}
});
apply();
-});
+}
+
+if (document.readyState === "interactive" || document.readyState === "complete") {
+ ready();
+} else {
+ document.addEventListener("DOMContentLoaded", ready);
+}
}());
diff --git a/style.css b/style.css
index 1f40764..15cf320 100644
--- a/style.css
+++ b/style.css
@@ -1,14 +1,10 @@
html {
- box-sizing: border-box;
- font-size: 16px;
+ box-sizing: border-box;
+ font-size: 16px;
}
*, *:before, *:after {
- box-sizing: inherit;
-}
-
-.container {
- margin: 5px 20%;
+ box-sizing: inherit;
}
div {
@@ -19,17 +15,32 @@ td, th {
padding: 5px;
}
+table {
+ width: 100%;
+}
+
+select {
+ overflow-y: auto;
+}
+
+.container {
+ min-width: 25em;
+ width: 80%;
+ max-width: 60em;
+ margin: 5px auto;
+}
+
#input {
width: 100%;
font-size: 1.3em;
}
-table {
- width: 100%;
+#link-container {
+ text-align: center;
}
-.default {
- color: #aaa;
+#link {
+ font-size: 120%;
}
#error {