Redirect to UNSW Library

Redirect ACM, IEEE, Springer and ScienceDirect to UNSW Library.

目前為 2024-04-19 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name            Redirect to UNSW Library
// @namespace       https://github.com/Caikun-Peng/Redirect-to-UNSW-Library/blob/main/redirection.js
// @version         1.1
// @description:en  Redirect ACM, IEEE, Springer and ScienceDirect to UNSW Library.
// @description:zh  将ACM、IEEE、Springer和ScienceDirect网站重定向至UNSW图书馆。
// @author          Caikun-Peng
// @match           https://dl.acm.org/*
// @match           https://ieeexplore.ieee.org/*
// @match           https://link.springer.com/*
// @match           https://www.sciencedirect.com/*
// @grant           GM_xmlhttpRequest
// @license         MIT
// @description Redirect ACM, IEEE, Springer and ScienceDirect to UNSW Library.
// ==/UserScript==

(function(){
    'use strict';

    var origin
    var newURL
    var flag

    function main() {
        GM_xmlhttpRequest({ // Get IP address
            method: "GET",
            url: "https://api.ipify.org?format=json",
            onload: function(response) {
                var ip = JSON.parse(response.responseText).ip;
                if (ip.includes("129.94")) {
                    flag = 0;
                } else{
                    flag = 1;
                }
                if (flag) {
                    newURL = changeURL();
                    window.location.href = newURL;
                }
            }
        });
    }

    function changeURL(){
        if (origin.startsWith("https://dl.acm.org/")) {
            return origin.replace("https://dl.acm.org/", "https://dl-acm-org.wwwproxy1.library.unsw.edu.au/");
        }
        else if (origin.startsWith("https://ieeexplore.ieee.org/")) {
            return origin.replace("https://ieeexplore.ieee.org/", "https://ieeexplore-ieee-org.wwwproxy1.library.unsw.edu.au/");
        }
        else if (origin.startsWith("https://link.springer.com/")) {
            return origin.replace("https://link.springer.com/", "https://link-springer-com.wwwproxy1.library.unsw.edu.au/");
        }
        else if (origin.startsWith("https://www.sciencedirect.com/")) {
            return origin.replace("https://www.sciencedirect.com/", "https://www-sciencedirect-com.wwwproxy1.library.unsw.edu.au/");
        }
    }

    origin = window.location.href;
    main();

})();