From 0d046223e2b2478473bef39e053d3021fbe169b0 Mon Sep 17 00:00:00 2001 From: "Alex Xu (Hello71)" Date: Tue, 18 Sep 2018 16:08:48 -0400 Subject: Initial commit --- .gitmodules | 3 ++ action_popup/action_popup.html | 19 ++++++++++++ action_popup/action_popup.js | 5 ++++ crsq.js | 66 ++++++++++++++++++++++++++++++++++++++++++ manifest.json | 18 ++++++++++++ yorku-course-query | 1 + 6 files changed, 112 insertions(+) create mode 100644 .gitmodules create mode 100644 action_popup/action_popup.html create mode 100644 action_popup/action_popup.js create mode 100644 crsq.js create mode 100644 manifest.json create mode 160000 yorku-course-query diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c4f5b49 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "yorku-course-query"] + path = yorku-course-query + url = https://git.alxu.ca/yorku-course-query.git diff --git a/action_popup/action_popup.html b/action_popup/action_popup.html new file mode 100644 index 0000000..720b4ec --- /dev/null +++ b/action_popup/action_popup.html @@ -0,0 +1,19 @@ + + + + + + + +
+ +
YorkU Web Helper
+
+
+ +
+ + + diff --git a/action_popup/action_popup.js b/action_popup/action_popup.js new file mode 100644 index 0000000..914041a --- /dev/null +++ b/action_popup/action_popup.js @@ -0,0 +1,5 @@ +document.getElementById("course-query-link").addEventListener("click", function () { + chrome.tabs.create({ + "url": "/yorku-course-query/index.html" + }); +}); diff --git a/crsq.js b/crsq.js new file mode 100644 index 0000000..3fb7ea5 --- /dev/null +++ b/crsq.js @@ -0,0 +1,66 @@ +(function () { +"use strict"; + +var scheduleLink = document.evaluate('//a[contains(text(), " Schedule")]', document.body).iterateNext(); + +if (!scheduleLink) + return; + +if (document.getElementById("loading-notice")) + return; + +var loadingNotice = document.createElement("span"); +loadingNotice.id = "loading-notice"; +loadingNotice.innerHTML = " (loading, please wait)"; +scheduleLink.parentNode.appendChild(loadingNotice); + +var xhr; +// show the xhr in dev tools +try { + xhr = XPCNativeWrapper(new window.wrappedJSObject.XMLHttpRequest()); +} catch (e) { + xhr = new XMLHttpRequest(); +} +xhr.responseType = 'document'; +xhr.open('GET', scheduleLink.href, true); +xhr.onreadystatechange = function () { + if (xhr.readyState !== xhr.DONE) + return; + + if (xhr.status === 200 && + xhr.responseXML && + xhr.responseXML.title === "York University Courses Website - Courses Schedule" + ) { + // emulate document.write script + xhr.responseXML.body.querySelector("script").parentNode.innerHTML = + /(?:mayaauth|mayaanyoneauth)/.test(document.cookie) ? + '


All About Passport York

' : + '
New Student?
All about Passport York
'; + + var avs = xhr + .responseXML + .evaluate( + '//a[contains(text(), "Please click here to see availability.")]', + xhr.responseXML.body + ); + var avsa = []; + var av; + while ((av = avs.iterateNext())) + avsa.push(av); + avsa.forEach(function (av) { + var newHref = av.href + .replace(/(https?:\/\/[^.\/]*\.sis\.yorku\.ca\/Apps\/WebObjects\/cdm\.woa\/wa\/loginppy\?url=).*/, + "$1" + encodeURIComponent(location.pathname + location.search + location.hash) + ); + if (newHref != av.href) + av.href = newHref; + }); + + document.body.replaceChild(xhr.responseXML.body.children[0], document.body.children[0]); + } else { + loadingNotice.innerHTML = " (loading failed)"; + } +}; +xhr.send(null); + +}()); diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..aa3b565 --- /dev/null +++ b/manifest.json @@ -0,0 +1,18 @@ +{ + "manifest_version": 2, + "name": "YorkU Web Helper", + "version": "1.0", + "description": "Unofficial York University website helper extension.", + "content_scripts": [ + { + "matches": ["*://*.sis.yorku.ca/Apps/WebObjects/cdm.woa/wa/crsq?*"], + "run_at": "document_end", + "js": ["crsq.js"] + } + ], + "browser_action": { + "browser_style": true, + "default_title": "YorkU Web Helper", + "default_popup": "action_popup/action_popup.html" + } +} diff --git a/yorku-course-query b/yorku-course-query new file mode 160000 index 0000000..6d1016e --- /dev/null +++ b/yorku-course-query @@ -0,0 +1 @@ +Subproject commit 6d1016e2dfb3d0b10d8e7203dd217382821ab42a -- cgit v1.2.3-54-g00ecf