UofT Library Proxy

Adds a floating button to proxy Nature, ACSPublications, JAMA and ScienceDirect pages through UofT library access

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         UofT Library Proxy
// @namespace    https://gist.github.com/jackjona/3f8a0b39f23b78c6f681fa7c25b265bf
// @homepageURL  https://gist.github.com/jackjona/3f8a0b39f23b78c6f681fa7c25b265bf
// @supportURL   https://gist.github.com/jackjona/3f8a0b39f23b78c6f681fa7c25b265bf
// @version      1.2.2
// @author       Jack Jona
// @description  Adds a floating button to proxy Nature, ACSPublications, JAMA and ScienceDirect pages through UofT library access
// @match        https://www.nature.com/*
// @match        https://www.sciencedirect.com/*
// @match        https://onlinelibrary.wiley.com/*
// @match        https://*.onlinelibrary.wiley.com/*
// @match        https://www.science.org/*
// @match        https://link.springer.com/*
// @match        https://pubs.acs.org/*
// @match        https://jamanetwork.com/*
// @icon         https://icons.duckduckgo.com/ip3/library.utoronto.ca.ico
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const PROXY_SUFFIX = '.myaccess.library.utoronto.ca';

    // If already proxied, do nothing
    if (location.hostname.includes(PROXY_SUFFIX)) return;

    // Create floating button
    const btn = document.createElement('div');
    btn.textContent = 'UofT Proxy';
    btn.style.position = 'fixed';
    btn.style.bottom = '20px';
    btn.style.right = '20px';
    btn.style.padding = '10px 14px';
    btn.style.background = '#00204E';
    btn.style.color = 'white';
    btn.style.fontSize = '14px';
    btn.style.borderRadius = '6px';
    btn.style.cursor = 'pointer';
    btn.style.zIndex = '999999';
    btn.style.boxShadow = '0 2px 6px rgba(0,0,0,0.3)';
    btn.style.opacity = '0.85';
    btn.style.transition = 'opacity 0.2s ease';
    btn.onmouseenter = () => btn.style.opacity = '1';
    btn.onmouseleave = () => btn.style.opacity = '0.85';

    document.body.appendChild(btn);

    btn.onclick = () => {
        let host = location.hostname;
        let path = location.pathname;
        let search = location.search;
        let hash = location.hash;

        // Special rule: ScienceDirect — strip /abs/ and remove query/hash
        if (host.includes('sciencedirect.com')) {
            path = path.replace('/abs/', '/');
            search = '';
            hash = '';
        }

        // Convert dots to dashes for proxy domain
        const proxiedHost = host.replace(/\./g, '-') + PROXY_SUFFIX;

        const newUrl = location.protocol + '//' + proxiedHost + path + search + hash;

        window.location.href = newUrl;
    };
})();