From 0b78e2b37215301acd00e44e8a2c41fc953a73a7 Mon Sep 17 00:00:00 2001 From: adlsdztony Date: Thu, 30 Nov 2023 13:46:59 +0800 Subject: [PATCH] Update version and add redirect script --- manifest.json | 6 +++++- scripts/redirect_to_login.js | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 scripts/redirect_to_login.js diff --git a/manifest.json b/manifest.json index ecdf266..f013108 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "FastHKU", - "version": "2.1", + "version": "2.2", "description": "One step to access HKU services", "content_scripts": [ { @@ -21,6 +21,10 @@ "matches": ["https://moodle.hku.hk/login/index.php"], "js": ["scripts/moodle_goto_login.js"], "run_at": "document_end" + }, + { + "matches": ["https://moodle.hku.hk/"], + "js": ["scripts/redirect_to_login.js"] } ], "action": { diff --git a/scripts/redirect_to_login.js b/scripts/redirect_to_login.js new file mode 100644 index 0000000..794bd45 --- /dev/null +++ b/scripts/redirect_to_login.js @@ -0,0 +1,13 @@ + + +try { + // check if user is logged in + if (document.getElementsByClassName("pull-right")[0].getElementsByTagName("a")[0].innerHTML == "login") { + // user is not logged in + // redirect to login page "https://moodle.hku.hk/login/index.php" + document.location.href = "https://moodle.hku.hk/login/index.php"; +} +} catch (error) { + // user is logged in + // do nothing +}