Last active
May 23, 2022 14:37
-
-
Save FlyGoat/f356ec0592c7b02334f3f1b92980e014 to your computer and use it in GitHub Desktop.
UoE Auto Login UserScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name UoE Auto Login | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Auto Login on University of Edinburgh websites | |
// @author Jiaxun Yang | |
// @match *://www.ease.ed.ac.uk/* | |
// @match *://www.myed.ed.ac.uk/* | |
// @match *://www.learn.ed.ac.uk/* | |
// @match *://www.ed.ac.uk/* | |
// @match *://www.wiki.ed.ac.uk/* | |
// @run-at document-idle | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=ed.ac.uk | |
// @grant none | |
// ==/UserScript== | |
// FILL YOUR CREDENTIALS HERE | |
var uun = ""; | |
var password = ""; | |
(function() { | |
// For ease login page | |
if (location.hostname === "www.ease.ed.ac.uk") { | |
if (uun == "" || password == "") { | |
alert("Please fill your credentials in user script!") | |
return; | |
} | |
// Input UUN | |
if (location.pathname === "/cosign.cgi") { | |
document.getElementById("login").value = uun; | |
document.getElementById("submit").click(); | |
} | |
// Input password | |
if (location.pathname === "/login/") { | |
document.getElementById("password").value = password; | |
document.getElementById("submit").click(); | |
} | |
} | |
if (location.hostname === "www.myed.ed.ac.uk") { | |
// MyEd use React to generate this element, so we must use observer | |
function waitForElm(elmId) { | |
return new Promise(resolve => { | |
if (document.getElementById(elmId)) { | |
return resolve(document.getElementById(elmId)); | |
} | |
const observer = new MutationObserver(mutations => { | |
if (document.getElementById(elmId)) { | |
resolve(document.getElementById(elmId)); | |
observer.disconnect(); | |
} | |
}); | |
observer.observe(document.body, { | |
childList: true, | |
subtree: true | |
}); | |
}); | |
} | |
waitForElm('login-btn').then((btn) => { | |
btn.click(); | |
}); | |
} | |
if (location.hostname === "www.learn.ed.ac.uk") { | |
// Hanlde Login button on homepage | |
const div = document.getElementsByClassName('easelogin-bt'); | |
if (div) { | |
div.item(0).click(); | |
} | |
// Handle login button on login page | |
const div1 = document.getElementById('ease'); | |
if (div1) { | |
div1.getElementsByTagName('a')[0].click(); | |
} | |
} | |
if (location.hostname === "www.ed.ac.uk") { | |
const loginLinkElm = document.getElementsByClassName('footer-login-link'); | |
if (loginLinkElm) { | |
loginLinkElm.item(0).href.click() | |
} | |
} | |
if (location.hostname === "www.wiki.ed.ac.uk") { | |
const loginLinkElm = document.getElementById('login-link'); | |
if (loginLinkElm) { | |
loginLinkElm.click() | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment