From 5515cf27e8ef5ee0e4552d83ce5584f2ec477eb2 Mon Sep 17 00:00:00 2001
From: "Alex Xu (Hello71)" <alex_y_xu@yahoo.ca>
Date: Wed, 19 Sep 2018 15:07:33 -0400
Subject: add default subject

---
 script.js | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/script.js b/script.js
index 1536c4d..dbece30 100644
--- a/script.js
+++ b/script.js
@@ -34,6 +34,7 @@ if (!ycq_storage)
     ycq_storage = {};
 ycq_storage.course_creds = ycq_storage.course_creds || {};
 ycq_storage.course_subjs = ycq_storage.course_subjs || {};
+ycq_storage.default_subj = ycq_storage.default_subj || "";
 
 let now = new Date();
 let month = now.getMonth();
@@ -134,6 +135,11 @@ function ready() {
             warn.push(`using saved subject for ${state.crsn}: ${state.subj}`);
         }
 
+        if (!state.subj && ycq_storage.default_subj) {
+            state.subj = ycq_storage.default_subj;
+            warn.push(`using saved default subject: ${state.subj}`);
+        }
+
         if (!state.fac && state.subj) {
             state.fac = DEPTS.get(state.subj);
             if (!state.fac)
@@ -142,7 +148,7 @@ function ready() {
 
         if (state.subj && state.crsn && !state.cred) {
             if (ycq_storage.course_creds[state.subj + state.crsn]) {
-                state.cred = ycq_storage.course_creds[state.crsn];
+                state.cred = ycq_storage.course_creds[state.subj + state.crsn];
                 warn.push(`using saved credit number for ${state.subj} ${state.crsn}: ${state.cred}`);
             } else {
                 state.cred = "3.00";
@@ -161,11 +167,11 @@ function ready() {
             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})`;
+            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 subject. see examples above");
+            error.push("need at least subject. see examples above");
         }
 
         if (multiple.size)
@@ -177,9 +183,9 @@ function ready() {
         ycq_storage.sess = r_sess;
         localStorage.ycq = JSON.stringify(ycq_storage);
     };
-
     input.addEventListener("input", apply);
     sessions.addEventListener("change", apply);
+
     document.getElementById("sample-queries").addEventListener("click", function (e) {
         if (e.target.tagName == "A") {
             e.preventDefault();
@@ -191,6 +197,7 @@ function ready() {
             input.focus();
         }
     });
+
     let save_crsn = function () {
         let modified = false;
         if (state.crsn) {
@@ -200,6 +207,7 @@ function ready() {
             }
             if (state.subj) {
                 ycq_storage.course_subjs[state.crsn] = state.subj;
+                ycq_storage.default_subj = state.subj;
                 modified = true;
             }
         }
-- 
cgit v1.2.3-70-g09d2