UofT Library Proxy

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

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==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;
    };
})();