// ==UserScript== // @name IEEE Xplore → KU OA Quick Switch (+ PDF) // @namespace https://github.com/coolmoon327/ieeexplore-ku-oa // @version 1.1.0 // @description Adds a floating button on ieeexplore.ieee.org to reopen the current path via Khalifa University EZproxy; shows a second button on /document/ pages to open the PDF directly. // @author coolmoon327 // @match https://ieeexplore.ieee.org/* // @run-at document-idle // @grant GM_openInTab // @license MIT // @homepageURL https://github.com/coolmoon327/ieeexplore-ku-oa // @supportURL https://github.com/coolmoon327/ieeexplore-ku-oa/issues // @downloadURL https://raw.githubusercontent.com/coolmoon327/ieeexplore-ku-oa/main/userscripts/ieee-ku-oa.user.js // @updateURL https://raw.githubusercontent.com/coolmoon327/ieeexplore-ku-oa/main/userscripts/ieee-ku-oa.user.js // ==/UserScript== (function () { 'use strict'; const PROXY_ROOT = 'https://ieeexplore-ieee-org.khalifa.idm.oclc.org'; const WRAP_ID = 'ku-oa-fab'; if (document.getElementById(WRAP_ID)) return; // --- UI helpers ----------------------------------------------------------- function makeBtn(text, title) { const b = document.createElement('button'); b.type = 'button'; b.setAttribute('aria-label', text); b.textContent = text; b.title = title || ''; Object.assign(b.style, { padding: '8px 12px', borderRadius: '9999px', border: 'none', cursor: 'pointer', fontSize: '12px', lineHeight: '1', background: '#00629b', // IEEE blue color: '#fff', boxShadow: '0 2px 10px rgba(0,0,0,.15)', opacity: '0.92' }); b.addEventListener('mouseenter', () => (b.style.opacity = '1')); b.addEventListener('mouseleave', () => (b.style.opacity = '0.92')); return b; } // Floating wrapper (top-right) const wrap = document.createElement('div'); wrap.id = WRAP_ID; Object.assign(wrap.style, { position: 'fixed', top: '14px', right: '14px', zIndex: '99999', display: 'flex', flexDirection: 'column', gap: '8px' }); // Main button: open same path via KU proxy const btnMain = makeBtn('KU OA', 'Open this page via Khalifa University\'s EZproxy in a new tab'); btnMain.addEventListener('click', () => { const path = location.pathname + location.search + location.hash; const target = PROXY_ROOT + path; try { GM_openInTab(target, { active: true }); } catch (e) { // Fallback in case GM_openInTab is unavailable window.open(target, '_blank'); } }); // Secondary button: PDF (only on /document/) const btnPdf = makeBtn('KU PDF', 'Open the proxied PDF view for this document in a new tab'); function getArnumber() { const m = location.pathname.match(/\/document\/(\d+)/); return m ? m[1] : null; } function updatePdfBtn() { const ar = getArnumber(); if (ar) { if (!btnPdf.isConnected) wrap.appendChild(btnPdf); btnPdf.onclick = () => { // Stable PDF viewer route on IEEE Xplore const url = `${PROXY_ROOT}/stamp/stamp.jsp?tp=&arnumber=${ar}`; try { GM_openInTab(url, { active: true }); } catch (e) { window.open(url, '_blank'); } }; } else if (btnPdf.isConnected) { btnPdf.remove(); } } // Mount UI wrap.appendChild(btnMain); document.documentElement.appendChild(wrap); updatePdfBtn(); // Handle SPA navigation on IEEE Xplore function onUrlChange() { updatePdfBtn(); } const origPush = history.pushState; history.pushState = function () { const r = origPush.apply(this, arguments); onUrlChange(); return r; }; const origReplace = history.replaceState; history.replaceState = function () { const r = origReplace.apply(this, arguments); onUrlChange(); return r; }; window.addEventListener('popstate', onUrlChange); })();