diff options
author | Alex Xu (Hello71) <alex_y_xu@yahoo.ca> | 2018-09-18 16:08:48 -0400 |
---|---|---|
committer | Alex Xu (Hello71) <alex_y_xu@yahoo.ca> | 2018-09-18 16:08:48 -0400 |
commit | 0d046223e2b2478473bef39e053d3021fbe169b0 (patch) | |
tree | 1c1cec190c8c2f78a2982408ca80e76701e2bc8a /crsq.js | |
download | yorku-web-helper-0d046223e2b2478473bef39e053d3021fbe169b0.tar.xz yorku-web-helper-0d046223e2b2478473bef39e053d3021fbe169b0.zip |
Initial commit
Diffstat (limited to 'crsq.js')
-rw-r--r-- | crsq.js | 66 |
1 files changed, 66 insertions, 0 deletions
@@ -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) ? + '<TABLE width="200" cellpadding="5" cellspacing="0" border="0"><TR><TD><P><a href="https://passportyork.yorku.ca/ppylogin/ppylogout"><IMG src="https://w2prod.sis.yorku.ca/WebObjects/YorkUimages/logout.gif" width="154" height="45" border="0"></a><BR><SPAN class="smallbodytext"><A href="http://www.yorku.ca/yorkweb/currentstudents/ppystudents.html">All About Passport York</A></SPAN></P></TD></TR></TABLE>' : + '<TABLE border="0"><TR><TD><img src="https://w2prod.sis.yorku.ca/WebObjects/YorkUimages/passportyorksmall2.gif" width="73" height="42"></TD><TD><B>New Student?</B><BR><a href="http://www.yorku.ca/yorkweb/currentstudents/ppystudents.html">All about Passport York</a></TD></TR></TABLE>'; + + 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); + +}()); |