UofT Library Proxy

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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;
    };
})();