summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.html13
-rw-r--r--script.js56
2 files changed, 49 insertions, 20 deletions
diff --git a/index.html b/index.html
index 79196ff..81f9e6f 100644
--- a/index.html
+++ b/index.html
@@ -33,23 +33,26 @@
</table>
</form>
</div>
- <div id="error">
+ <div id="error" style="display: none">
+ Errors (fix these to generate a link):
+ <ul id="error-list"></ul>
</div>
<div id="link-container" style="display: none">
<p><a id="link" rel="noopener noreferrer">Course Query</a></p>
</div>
- <div id="warning">
+ <div id="warning" style="display: none">
+ Warnings (you can probably ignore these):
+ <ul id="warning-list"></ul>
</div>
<hr style="margin: 2em auto; width: 80%;">
<div>
<p>
Tips:
<ul>
- <li id="ywh-ad">it is highly recommended to install YorkU Web Helper, available for Firefox and for Chrome.</li>
- <li><strong>no more "You have exceeded the maximum time limit"!</strong> bookmark the generated link, and it will always bring you to the right page. works best with YorkU Web Helper.</li>
+ <li id="ywh-ad">it is highly recommended to install YorkU Web Helper, available <a href="">for Firefox</a> and <a href="">for Chrome</a>.</li>
+ <li><strong>no more "You have exceeded the maximum time limit"!</strong> bookmark the generated link, and it will always bring you to the right page. works best with YorkU Web Helper for automatic schedule loading</li>
<li>pressing enter in the box opens the result. ctrl-enter opens 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>
- <li>this tries to remember your favorite subject. you need to open the search page though, otherwise it doesn't know when you're done typing.</li>
</ul>
</p>
</div>
diff --git a/script.js b/script.js
index 0951b5b..6c74539 100644
--- a/script.js
+++ b/script.js
@@ -197,7 +197,7 @@ const DEPTCRSN_RE = /^([A-Z]{2,4})([0-9]{4})$/;
const CRED_RE = /^(?:Cr=([0-9]{1,2}(?:\.[0-9]{0,2})?)|([0-9]{1,2}\.[0-9]{0,2}))$/;
const MAYBE_CRED_RE = /^[0-9]{1,2}$/;
const MAYBE_DEPT_RE = /^[A-Z]{2,4}$/;
-const IGNORE_RE = /^[A-Z]$/;
+const IGNORE_RE = /^[A-Za-z]$/; // note: this has to be lowercase, otherwise "ignored search terms" will incorrectly uppercase the input
function parse_ycq_s(str) {
let ycq_s = JSON.parse(str || "{}");
@@ -258,6 +258,15 @@ function ready() {
let state;
+ let apply_list = function (n, l) {
+ if (l.length) {
+ document.getElementById(n).style.display = "block";
+ document.getElementById(n + "-list").innerHTML = l.map(s => `<li>${s}</li>`).join('');
+ } else {
+ document.getElementById(n).style.display = "none";
+ }
+ };
+
let apply = function () {
state = {subj: "", fac: "", crsn: "", cred: ""};
let multiple = new Set();
@@ -269,6 +278,8 @@ function ready() {
state[type] = token;
};
+ let ignored_tokens = [];
+
let tryParse = function (token) {
let subjcrsn, cred;
if (SUBJS.hasOwnProperty(token)) {
@@ -287,31 +298,43 @@ function ready() {
warn.push(`assuming ${token} is the number of credits`);
} else if (MAYBE_DEPT_RE.test(token)) {
state["maybeSubj"] = token;
- } else if (!IGNORE_RE.test(token)) {
+ } else if (IGNORE_RE.test(token)) {
+ ignored_tokens.push(token);
+ } else {
return false;
}
return true;
};
+ let unk_tokens = [];
input.value.split(TOKEN_DELIM_RE).forEach(function (token) {
if (!token || tryParse(token) || tryParse(token.toUpperCase()))
return;
- warn.push(`don't understand search term: ${token}`);
+ unk_tokens.push(token);
});
+ if (unk_tokens.length) {
+ let dont_understand = unk_tokens.map(t => `"${t}"`).join(', ');
+ warn.push(`don't understand search terms: ${dont_understand}.`);
+ }
+
+ if (ignored_tokens.length) {
+ let ignored_terms = ignored_tokens.map(t => `"${t}"`).join(', ');
+ warn.push(`ignored search terms: ${ignored_terms}.`);
+ }
if (!state["subj"] && state["maybeSubj"]) {
state["subj"] = state["maybeSubj"];
- warn.push("guessing subject is " + 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"]}`);
+ warn.push(`assuming ${state["crsn"]} means ${state["subj"]} ${state["crsn"]}, because you last used ${state["subj"]} for ${state["crsn"]}.`);
}
if (!state["subj"] && cached_ycq_s.default_subj) {
state["subj"] = cached_ycq_s.default_subj;
- warn.push(`using saved default subject: ${state["subj"]}`);
+ warn.push(`using ${state["subj"]}, because that was your most recently searched subject.`);
}
if (!state["fac"] && state["subj"]) {
@@ -321,6 +344,8 @@ function ready() {
// 3. most recent compatible faculty
// 4. first compatible faculty
let compat_facs = SUBJS[state["subj"]];
+
+ // needs to be a function so it can remove the current selection
let other_options = function () {
if (compat_facs) {
let other_facs = compat_facs
@@ -328,7 +353,7 @@ function ready() {
.map(f => `<a href="#" class="prepend-query">${f}</a>`)
.join(", ");
if (other_facs.length)
- return ", other options: " + other_facs;
+ return "other options: " + other_facs;
}
return "";
}
@@ -336,11 +361,11 @@ function ready() {
// 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()}`);
+ warn.push(`assuming ${state["subj"]} ${state["crsn"]} is ${state["fac"]}/${state["subj"]}, because you last used ${state["fac"]} for ${state["subj"]} ${state["crsn"]}. ${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()}`);
+ warn.push(`assuming ${state["subj"]} means ${state["fac"]}/${state["subj"]}, because you last used ${state["fac"]} for ${state["subj"]}. ${other_options()}`);
} else if (compat_facs) {
// 3. most recent compatible faculty
if (cached_ycq_s.default_facs)
@@ -349,11 +374,11 @@ function ready() {
state["fac"] = cached_ycq_s.default_facs[i];
if (state["fac"]) {
- warn.push(`using saved faculty: ${state["fac"]}${other_options()}`);
+ warn.push(`assuming ${state["subj"]} means ${state["fac"]} ${state["subj"]}, because you recently used ${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()}`);
+ warn.push(`assuming ${state["subj"]} means ${state["fac"]} ${state["subj"]}, because ${state["fac"]} is the default for ${state["subj"]}. ${other_options()}`);
}
} else {
error.push("no faculty provided and unknown subject");
@@ -363,10 +388,10 @@ function ready() {
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"]}`);
+ warn.push(`assuming ${state["subj"]} ${state["crsn"]} is ${state["cred"]} credits, because you last used ${state["cred"]} for ${state["subj"]} ${state["crsn"]}.`);
} else {
state["cred"] = "3.00";
- warn.push("assuming the number of credits is 3.00");
+ warn.push("assuming the number of credits is 3.00, because that's the most common number.");
}
}
@@ -390,8 +415,8 @@ function ready() {
if (multiple.size)
warn.push("multiple terms for " + Array.from(multiple.values()).join(", ") + ", using last occurrence for each");
- document.getElementById("warning").innerHTML = warn.map(w => 'warning: ' + w).join("<br>");
- document.getElementById("error").innerHTML = error.map(e => 'error: ' + e).join("<br>");
+ apply_list("warning", warn);
+ apply_list("error", error);
};
input.addEventListener("input", apply);
sessions.addEventListener("change", apply);
@@ -465,6 +490,7 @@ function ready() {
if (linkContainer.style.display == "block")
link.click();
});
+ input.addEventListener("blur", save_defaults);
input.addEventListener("keydown", function (e) {
if (e.key == "Enter") {
e.preventDefault();