// ==UserScript== // @name PMC Figure Embedder // @namespace http://tampermonkey.net/ // @version 0.1 // @description Embed PMC article figures below PMC links on wiki pages // @author MuaddibLLM // @match *://*/* // @grant GM_xmlhttpRequest // ==/UserScript== (function() { 'use strict'; // Find all PMC links on the page const pmcLinks = document.querySelectorAll('a[href*="pubmedcentral"], a[href*="pmc/articles"], a[href*="ncbi.nlm.nih.gov/pmc"]'); pmcLinks.forEach(async (link, index) => { // Extract PMC ID from various URL formats const pmcMatch = link.href.match(/(?:PMC|pmc\/articles\/PMC)(\d+)/i); if (!pmcMatch) return; const pmcId = pmcMatch[1]; const pmcUrl = `https://www.ncbi.nlm.nih.gov/pmc/articles/PMC${pmcId}/`; // Create container for figures const figContainer = document.createElement('div'); figContainer.style.cssText = 'margin: 10px 0; padding: 10px; border: 1px solid #ddd; border-radius: 5px; background: #f9f9f9;'; figContainer.innerHTML = '
Loading PMC figures...
'; // Insert after the PMC link link.parentNode.insertBefore(figContainer, link.nextSibling); // Fetch PMC page GM_xmlhttpRequest({ method: 'GET', url: pmcUrl, onload: function(response) { try { const parser = new DOMParser(); const doc = parser.parseFromString(response.responseText, 'text/html'); // Find figure images - PMC uses various selectors const figures = doc.querySelectorAll('.fig img, .figure img, figure img, .fig-image img'); if (figures.length === 0) { figContainer.innerHTML = '
No figures found
'; return; } // Create figure grid (max 6 figures to avoid overwhelming) const maxFigures = Math.min(6, figures.length); const figGrid = document.createElement('div'); figGrid.style.cssText = 'display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px;'; for (let i = 0; i < maxFigures; i++) { const fig = figures[i]; let imgSrc = fig.src || fig.getAttribute('data-src'); if (!imgSrc) continue; // Make URL absolute if (imgSrc.startsWith('/')) { imgSrc = 'https://www.ncbi.nlm.nih.gov' + imgSrc; } else if (imgSrc.startsWith('//')) { imgSrc = 'https:' + imgSrc; } // Create thumbnail const thumb = document.createElement('img'); thumb.src = imgSrc; thumb.style.cssText = 'width: 100%; max-width: 150px; height: auto; cursor: pointer; border: 1px solid #ccc; border-radius: 3px;'; thumb.title = `Figure ${i+1} - Click to view full size`; // Click to open full image thumb.onclick = () => window.open(imgSrc, '_blank'); figGrid.appendChild(thumb); } figContainer.innerHTML = `
PMC${pmcId} Figures (${maxFigures}/${figures.length}):
`; figContainer.appendChild(figGrid); } catch (error) { figContainer.innerHTML = '
Error loading figures
'; console.error('PMC Figure Embedder error:', error); } }, onerror: function() { figContainer.innerHTML = '
Failed to fetch PMC page
'; } }); // Add small delay between requests to be nice to NCBI await new Promise(resolve => setTimeout(resolve, 200 * index)); }); })();