From bdcbd3d3aa21f9365a69d08c49863575d91e9687 Mon Sep 17 00:00:00 2001 From: js0ny Date: Mon, 17 Nov 2025 18:04:55 +0000 Subject: [PATCH] initial commit --- .envrc | 1 + .gitignore | 1 + autologin_at_ed.js | 127 +++++++++++++++++++++++++++++++++++++++++++++ flake.lock | 61 ++++++++++++++++++++++ flake.nix | 32 ++++++++++++ 5 files changed, 222 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 autologin_at_ed.js create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92b2793 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.direnv diff --git a/autologin_at_ed.js b/autologin_at_ed.js new file mode 100644 index 0000000..7ec9090 --- /dev/null +++ b/autologin_at_ed.js @@ -0,0 +1,127 @@ +// ==UserScript== +// @name AutoLogin@Ed +// @namespace https://git.js0ny.net/ +// @version 0.2 +// @description Auto Login on University of Edinburgh websites +// @author js0ny +// @match *://edadfed.ed.ac.uk/* +// @match *://login.microsoftonline.com/login.srf* +// @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/* +// @icon https://www.google.com/s2/favicons?sz=64&domain=ed.ac.uk +// @grant none +// @noframes +// ==/UserScript== +// Forked from: Jiaxun Yang's original script + +// FILL YOUR CREDENTIALS HERE +var uun = ""; +var password = ""; + +(function() { + + if (uun == "" || password == "") { + alert("Please fill your credentials") + return; + } + + // OAuth Redirection + if (location.hostname === "edadfed.ed.ac.uk") { + // alert("Debug"); + document.getElementById("userNameInput").value = uun + "@ed.ac.uk"; + document.getElementById("passwordInput").value = password; + document.getElementById("submitButton").click(); + } + + + // OAuth Microsoft Page + if (location.href.startsWith("https://login.microsoftonline.com/login.srf")) { + (function() { + 'use strict'; + + const DELAY_MS = 3000; + + setTimeout(function() { + const titleElement = document.getElementById('appConfirmTitle'); + if (titleElement.textContent.includes("Do you trust ed.ac.uk?")) { + document.getElementById("idSIButton9").click(); + } + }, DELAY_MS); + + })(); + } + + // For ease login page + if (location.hostname === "www.ease.ed.ac.uk") { + + + // 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() + } + } +})(); diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..477c915 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1763283776, + "narHash": "sha256-Y7TDFPK4GlqrKrivOcsHG8xSGqQx3A6c+i7novT85Uk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "50a96edd8d0db6cc8db57dab6bb6d6ee1f3dc49a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1c8a004 --- /dev/null +++ b/flake.nix @@ -0,0 +1,32 @@ +{ + description = "template for devShell"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem ( + system: let + pkgs = import nixpkgs {inherit system;}; + in { + # 定义默认的 devShell + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + nodejs_24 + typescript-language-server + ]; + + shellHook = '' + node --version + ''; + }; + } + ); +}