-
Notifications
You must be signed in to change notification settings - Fork 1
/
UoA-EZproxy-Redirector.user.js
41 lines (36 loc) · 1.68 KB
/
UoA-EZproxy-Redirector.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// ==UserScript==
// @name UoA EZproxy Redirector
// @namespace spectopo.io
// @copyright Copyright © 2023 SpecterShell
// @version 1.0.0
// @description Add menu commands in Tampermonkey/ViolentMonkey to open current page in UoA EZproxy
// @description:zh 在Tampermonkey或ViolentMonkey中添加菜单命令,以在奥克兰大学EZproxy打开当前网页
// @icon https://www.auckland.ac.nz/favicon.ico
// @grant GM_registerMenuCommand
// @grant GM_openInTab
// @author SpecterShell
// @homepage https://github.com/SpecterShell/UoA-EZproxy-Redirector
// @include *
// @match *://*/*
// @exclude *://*.ezproxy.auckland.ac.nz/*
// @run-at document-start
// @updateURL https://raw.githubusercontent.com/SpecterShell/UoA-EZproxy-Redirector/main/UoA-EZproxy-Redirector.user.js
// @downloadURL https://raw.githubusercontent.com/SpecterShell/UoA-EZproxy-Redirector/main/UoA-EZproxy-Redirector.user.js
// @supportURL https://github.com/SpecterShell/UoA-EZproxy-Redirector/issues
// ==/UserScript==
(function () {
"use strict";
const baseProtocol = "https";
const baseHost = "ezproxy.auckland.ac.nz";
function rewriteUrl(url) {
const oldUrl = new URL(url);
const newUrl = baseProtocol + "://" + oldUrl.hostname.replaceAll(".", "-") + "." + baseHost + oldUrl.pathname;
return newUrl;
}
GM_registerMenuCommand("Open Current Page in UoA EZproxy", () => {
location.href = rewriteUrl(location.href);
});
GM_registerMenuCommand("Open Current Page in UoA EZproxy in New Tab", () => {
GM_openInTab(rewriteUrl(location.href), { active: true });
});
})();