Bypass paywalls for scientific documents

Bypass paywalls for scientific documents by downloading them from sci-hub instead of paying something like 50 bucks for each paper. This script adds download buttons on Google Scholar, Scopus and Web Of Science, which lead to sci-hub.tw. In this way you can get free access to scientific papers even if you (or your university) can't afford their prices.

目前為 2018-06-14 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Bypass paywalls for scientific documents
// @namespace    StephenP
// @version      3.1.3
// @description  Bypass paywalls for scientific documents by downloading them from sci-hub instead of paying something like 50 bucks for each paper. This script adds download buttons on Google Scholar, Scopus and Web Of Science, which lead to sci-hub.tw. In this way you can get free access to scientific papers even if you (or your university) can't afford their prices.
// @author       StephenP
// @include      http://scholar.google.*/scholar?*
// @match        http://www.scopus.com/record/display.uri?*
// @match        http://apps.webofknowledge.com/full_record.do?*
// @match        http://apps.webofknowledge.com/InterService.do?*
// @match        http://apps.webofknowledge.com/CitedFullRecord.do?*
// @include      https://scholar.google.*/scholar?*
// @match        https://www.scopus.com/record/display.uri?*
// @match        https://apps.webofknowledge.com/full_record.do?*
// @match        https://apps.webofknowledge.com/InterService.do?*
// @match        https://apps.webofknowledge.com/CitedFullRecord.do?*
// @match        *://*.sci-hub.tw/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    //If Sci-Hub address changes, just replace the URL below with the new one
    var sciHubUrl='https://sci-hub.tw/';
    var documentId;
    var site=window.location.href.toString();
    var i;
    if(site.includes("://www.scopus.com/")){
        var fullDocument=document.querySelector('[title="Full Text(opens in a new window)"]');
        //fullDocument.href=fullDocument.href.slice(54);
        documentId=document.getElementById("recordDOI").innerHTML;
        var section=document.getElementById("outwardLinks");
        section.removeChild(section.lastChild);
        fullDocument.parentNode.insertAdjacentHTML('beforeend','<a><img class="outwardLink" src="data:image/gif;base64, R0lGODlhZQAPAKU2AGZmZghapZmZmYD//8rKyunr6enq6urr6erq6uzt7Ozt7e3t7O3t7e3u7e3u7u7u7e7u7u/v8O/w7+/w8PDw7/Ly8vLz8vLz8/Py8vPz8vPz8/P09PT08/T09PX19vX29fX29vb19fb29ff39/f49/j4+Pj5+Pj5+fn4+Pn4+fn5+Pn5+fn6+vr6+fr6+v39/f39/v3+/f3+/v79/f7+/f7+/v///////////////////////////////////////yH5BAEKAD8ALAAAAABlAA8AAAb+wJ9gSCwaj8ikcslsOpNCm3RKrVqv2Kx2y+1eawCBDfaKyV4vckydLrNj7XX5HGer1fR7uY5H6+F/fXV7fzEEYTYuLIsujYyMiiyRkI+QkZeXi5KOkpSbmo2Zn52km6KNAQGXh2KpJionJ66uJyUrJrYmt7W3ubC8uLu5Jam/wyupySW+scQBucCutqnNvcKpuSasNiSpI9+pJCQj4+Xl5Oji6N/m6eTdAd/p8OgB6uPs7+7w6t7z6eHebfOQ6kOIVCI+FAxBMJnCAAxTeRCRKgTDhA0dJqs48UPDix4nbmzYEWRBkRAPBvDIcWMAD9s6pOogM8CGmjRn1twwMxn+zwA0O9wUmhMozqBDXQbVWZQozZsudUo1OvPnNgsZUmlIlcFCKgtbXWYN4NXrWA0asFrAunHtV7Rq2bb1Shbu17Ffv8pFq1crXbnbIkTYKFhCKsMBIkgoPDiZ4cGLBStuLDjA4sOSJ2tO1VhCZMqaFWMGjZkz6QDbHEDYqNpBKtWvYUNw/TrZAwizZ7/W7YD27dy9A7SOneo37dbAY68OgJs48+PLtylIkCDZ9OoBqCtwST1V91QLtGvnPj1ZguvbN54vbz3V9fPf4XvHrj69+W0IDhQwcOBA/gL/+adfgAUICKB+/BkY4H//Jcigfgo22N+DBVIooYIQUmjANgQndOjhhyCGKOKIJJZo4okoigjADwC06OKLMMYo44w01mjjjTjO+EMQADs=" alt="Download from Sci-Hub" title="Full Text(opens in a new window)" height="15" width="101"></a><a style="font-size: 12px; color: green; text-decoration: underline;" href="javascript:;">Donate to Sci-Hub project</a><span class="divider">|</span>');
        fullDocument.parentNode.children[4].addEventListener("click", function(){window.open(sciHubUrl+documentId);});
        //setAttribute('onclick','window.open(\"'+sciHubUrl+documentId+'\");');
        fullDocument.parentNode.children[5].addEventListener("click", function(){donate(sciHubUrl);});
        //setAttribute('onclick',donate(sciHubUrl));
    }
    else if(site.includes("://apps.webofknowledge.com/")){
        var mode;
        var genericID=document.getElementsByClassName("block-record-info block-record-info-source")[0];
        for(i=4;i<=genericID.children.length;i++){
            var compare=genericID.children[i].children[0].innerHTML;
            if((compare.localeCompare("DOI:")==0)||(compare.localeCompare("PMID:")==0)){
                if(genericID.children[i].children.length<2){
                    documentId=genericID.children[i].lastChild.data.toString();
                    mode=1;
                }
                else{
                    documentId=genericID.children[i].children[1].innerHTML;
                    mode=0;
                }
                break;
            }
        }
        if(documentId!==undefined){
            addButtonWOS(sciHubUrl,documentId,mode);
        }
    }
    else if(site.includes("://scholar.google.")){
        var resourcesList=document.getElementById('gs_res_ccl_mid');
        var results=resourcesList.children.length;
        var gs_ggs_gs_fl;
        for(i=0;i<results;i++){
            try{
                if(resourcesList.children[i].getElementsByClassName("gs_ggs gs_fl").length==0){
                    gs_ggs_gs_fl=document.createElement("div");
                    gs_ggs_gs_fl.setAttribute("class","gs_ggs gs_fl");
                    resourcesList.children[i].insertBefore(gs_ggs_gs_fl,resourcesList.children[i].firstChild);
                    addButtonScholar(sciHubUrl,resourcesList.children[i].firstChild);
                }
                else{
                    addButtonScholar(sciHubUrl,resourcesList.children[i].firstChild);
                }
            }
            catch(err){
                alert(err+"//"+resourcesList.children[i].lastElementChild.innerHTML);
            }
        }
    }
    else if(site.includes("://sci-hub.")){
        var sPDFLink = document.getElementById("save").children[0].children[0].getAttribute("onClick");
        sPDFLink=sPDFLink.substring(15,sPDFLink.length-1);
        window.open(sPDFLink,"_blank");
        window.close();
    }
})();
function addButtonWOS(sciHubUrl,documentId,mode){
    try{
        var site=window.location.href.toString();
        var sciHubBtn;
        var list;
        if(site.includes("full_record.do")){
            list=document.getElementsByClassName("l-columns-item")[0];
            try{
                list.appendChild(list.children[1].cloneNode(true));
            }
            catch(err){
                list.appendChild(list.children[0].cloneNode(true));
            }
            if(mode==0){
                sciHubBtn=list.lastChild.children[1].children[0];
            }
            else if(mode==1){
                sciHubBtn=list.lastChild.children[1];
            }
            sciHubBtn.removeAttribute("href");
            sciHubBtn.setAttribute("alt","Break the walls and free the knowledge that publishers taken hostage\!");
            sciHubBtn.setAttribute("title","Break the walls and free the knowledge that publishers taken hostage\!");
            sciHubBtn.innerHTML="Full Text from Sci-Hub";
            sciHubBtn.addEventListener("click", function(){window.open(sciHubUrl+documentId);});
            list.insertAdjacentHTML('beforeend','<li><a style="font-size: 12px; color: green; text-decoration: underline;" href="javascript:;">Donate to Sci-Hub project</a></li>');
            list.lastChild.lastChild.removeAttribute("href");
            list.lastChild.lastChild.addEventListener("click", function(){donate(sciHubUrl);});
        }
        else if(site.includes("CitedFullRecord.do")){
            list=document.getElementsByClassName("popup-ft-list")[0];
            try{
                list.appendChild(list.children[0].cloneNode(true));
            }
            catch(err){
                list.appendChild(list.children[1].cloneNode(true));
            }
            if(mode==0){
                sciHubBtn=list.lastChild.children[0].children[0];
            }
            else if(mode==1){
                sciHubBtn=list.lastChild.children[1];
            }
            sciHubBtn.removeAttribute("href");
            sciHubBtn.removeAttribute("onclick");
            sciHubBtn.setAttribute("alt","Break the walls and free the knowledge that publishers taken hostage\!");
            sciHubBtn.setAttribute("title","Break the walls and free the knowledge that publishers taken hostage\!");
            sciHubBtn.innerHTML="Full Text from Sci-Hub";
            sciHubBtn.addEventListener("click", function(){window.open(sciHubUrl+documentId);});
            list.insertAdjacentHTML('beforeend','<li><a style="font-size: 12px; color: green; text-decoration: underline;" href="javascript:;">Donate to Sci-Hub project</a></li>');
            list.lastChild.lastChild.removeAttribute("href");
            list.lastChild.lastChild.addEventListener("click", function(){donate(sciHubUrl);});
        }
    }
    catch(err){
        console.log(err);
    }
    //setAttribute('onclick',donate(sciHubUrl));
}
function addButtonScholar(sciHubUrl,linkDiv){
    var link=linkDiv.parentNode.getElementsByClassName("gs_rt")[0].lastChild.href;
    var creatingElement;
    if((link!=undefined)&&(link.search("patents.google")==-1)){
        creatingElement=document.createElement("div");
        creatingElement.setAttribute("class","gs_ggsd");
        creatingElement.innerHTML='<a>Full Text on Sci-Hub</a>';
        linkDiv.appendChild(creatingElement);
        linkDiv.lastChild.addEventListener("click", function(){window.open(sciHubUrl+link);});
        //setAttribute("onclick",'window.open(\"'+sciHubUrl+link+'\");');
    }
}
function donate(sciHubUrl){
    window.open(sciHubUrl+'#donate');
}