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 --- crsq.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 crsq.js (limited to 'crsq.js') 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); + +}()); -- cgit v1.2.3-54-g00ecf