UofT Library Proxy

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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;
    };
})();