NUS e-journals download redirect

e-journals download redirect for NUS students V1.3.1 (fixed overlap & delay only for AIP sites)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         NUS e-journals download redirect
// @version      1.3.1
// @description  e-journals download redirect for NUS students V1.3.1 (fixed overlap & delay only for AIP sites)
// @namespace    https://greasyfork.org/users/741351
// @include      *://advanced.onlinelibrary.wiley.com/*
// @include      *://onlinelibrary.wiley.com/*
// @include      *://www.nature.com/*
// @include      *://www.science.org/*
// @include      *://aip.scitation.org/*
// @include      *://journals.aps.org/*
// @include      *://pubs.acs.org/*
// @include      *://link.springer.com/*
// @include      *://www.sciencedirect.com/*
// @include      *://www.osapublishing.org/*
// @include      *://ieeexplore.ieee.org/*
// @include      *://pubs.rsc.org/*
// @include      *://iopscience.iop.org/*
// @include      *://science.sciencemag.org/*
// @include      *://www.spiedigitallibrary.org/*
// @include      *://www.cambridge.org/*
// @include      *://www.pnas.org/*
// @include      *://royalsocietypublishing.org/*
// @include      *://opg.optica.org/*
// @include      *://pubs.aip.org/*
// @author       SAPEREAUDE&ChatGPT
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
    const href = document.location.href;
    
    const redirect = () => {
    document.location.href = href
        .replace('advanced.onlinelibrary.wiley.com', 'advanced-onlinelibrary-wiley-com.libproxy1.nus.edu.sg')
        .replace('onlinelibrary.wiley.com', 'onlinelibrary-wiley-com.libproxy1.nus.edu.sg')
        .replace('www.nature.com', 'www-nature-com.libproxy1.nus.edu.sg')
        .replace('www.science.org', 'www-science-org.libproxy1.nus.edu.sg')
        .replace('aip.scitation.org', 'aip-scitation-org.libproxy1.nus.edu.sg')
        .replace('journals.aps.org', 'journals-aps-org.libproxy1.nus.edu.sg')
        .replace('pubs.acs.org', 'pubs-acs-org.libproxy1.nus.edu.sg')
        .replace('link.springer.com', 'link-springer-com.libproxy1.nus.edu.sg')
        .replace('www.sciencedirect.com', 'www-sciencedirect-com.libproxy1.nus.edu.sg')
        .replace('www.osapublishing.org', 'www-osapublishing-org.libproxy1.nus.edu.sg')
        .replace('ieeexplore.ieee.org', 'ieeexplore-ieee-org.libproxy1.nus.edu.sg')
        .replace('pubs.rsc.org', 'pubs-rsc-org.libproxy1.nus.edu.sg')
        .replace('iopscience.iop.org', 'iopscience-iop-org.libproxy1.nus.edu.sg')
        .replace('science.sciencemag.org', 'science-sciencemag-org.libproxy1.nus.edu.sg')
        .replace('www.spiedigitallibrary.org', 'www-spiedigitallibrary-org.libproxy1.nus.edu.sg')
        .replace('www.cambridge.org', 'www-cambridge-org.libproxy1.nus.edu.sg')
        .replace('www.pnas.org', 'www-pnas-org.libproxy1.nus.edu.sg')
        .replace('royalsocietypublishing.org', 'royalsocietypublishing-org.libproxy1.nus.edu.sg')
        .replace('opg.optica.org', 'opg-optica-org.libproxy1.nus.edu.sg')
        .replace('pubs.aip.org', 'pubs-aip-org.libproxy1.nus.edu.sg');
    };

    // Apply delay only for AIP sites
    if (href.includes('aip.scitation.org') || href.includes('pubs.aip.org')) {
        const delay = Math.random() * (1867 - 1239) + 1239; // 1239 ms to 1867 ms
        setTimeout(redirect, delay);
    } else {
        redirect();
    }
})();