// ==UserScript==
// @name Google Scholar to Sci-Hub
// @namespace ScholarToSciHub
// @version 1.1
// @description Adds Sci-Hub and LibGen buttons to Google Scholar results
// @author Bui Quoc Dung
// @include https://scholar.google.*/*
// @license AGPL-3.0-or-later
// @downloadURL none
// ==/UserScript==
const SCIHUB_URL = 'https://www.tesble.com/';
const LIBGEN_URL = 'https://libgen.li/index.php?req=';
function addButtons() {
const results = document.querySelectorAll('#gs_res_ccl_mid .gs_r.gs_or.gs_scl');
results.forEach(result => {
const titleLink = result.querySelector('.gs_rt a');
let buttonContainer = result.querySelector('.gs_or_ggsm');
if (!buttonContainer) {
const div = document.createElement('div');
div.className = 'gs_ggs gs_fl';
div.innerHTML = '
';
result.insertBefore(div, result.firstChild);
buttonContainer = div.querySelector('.gs_or_ggsm');
const sciHubLink = document.createElement('a');
sciHubLink.textContent = 'Sci-Hub';
sciHubLink.addEventListener('click', () => window.open(SCIHUB_URL + titleLink.href));
buttonContainer.appendChild(sciHubLink);
const libGenLink = document.createElement('a');
libGenLink.textContent = ' LibGen';
libGenLink.addEventListener('click', () => window.open(LIBGEN_URL + encodeURIComponent(titleLink.textContent)));
buttonContainer.appendChild(libGenLink);
}
});
}
// Initial setup
addButtons();
// Watch for dynamic content changes
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.addedNodes.length) {
addButtons();
}
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});