├── Assets ├── access-settings-page.png ├── reset-custom-base-URL.png └── set-custom-base-URL.png ├── LICENSE ├── README.md └── doi2scihub.user.js /Assets/access-settings-page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChaseChoi/doi2scihub/8be381d0f3531788f06ff1e8a27421e37edf47ed/Assets/access-settings-page.png -------------------------------------------------------------------------------- /Assets/reset-custom-base-URL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChaseChoi/doi2scihub/8be381d0f3531788f06ff1e8a27421e37edf47ed/Assets/reset-custom-base-URL.png -------------------------------------------------------------------------------- /Assets/set-custom-base-URL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChaseChoi/doi2scihub/8be381d0f3531788f06ff1e8a27421e37edf47ed/Assets/set-custom-base-URL.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Chase Choi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # doi2scihub 2 | [![license](https://img.shields.io/github/license/chasechoi/doi2scihub)](https://github.com/ChaseChoi/doi2scihub/blob/main/LICENSE) 3 | [![tag](https://img.shields.io/github/v/tag/chasechoi/doi2scihub)](https://github.com/ChaseChoi/doi2scihub/tags) 4 | 5 | A Greasemonkey script to highlight DOI link on the current webpage and redirect it to Sci-Hub. 6 | 7 | # Support user-defined base URL 8 | Click `Settings` button to configure custom base URL 9 | ![settings](./Assets/access-settings-page.png) 10 | 11 | ## Add custom base URL 12 | ![set-base-url](./Assets/set-custom-base-URL.png) 13 | 14 | 1. Enter custom base URL 15 | 2. Click `Save` button 16 | 3. Click `Close` button to close settings page 17 | 18 | 19 | ## Remove custom base URL 20 | ![reset-base-url](./Assets/reset-custom-base-URL.png) 21 | 22 | 1. Click `Reset to defaults` button 23 | 2. Click `Save` button 24 | 3. Click `Close` button to close settings page -------------------------------------------------------------------------------- /doi2scihub.user.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name DOI to Sci-Hub 3 | // @name:zh-CN DOI跳转Sci-Hub 4 | // @namespace https://greasyfork.org/users/692574 5 | // @version 1.0.31 6 | // @description Highlight DOI link on the current webpage and redirect it to Sci-Hub. 7 | // @description:zh-CN 高亮当前页面的DOI链接,并重定向至Sci-Hub。 8 | // @author Chase Choi 9 | // @license MIT 10 | // @match https://*.sciencemag.org/* 11 | // @match http*://*.webofknowledge.com/* 12 | // @match https://academic.oup.com/* 13 | // @match https://academic.microsoft.com/* 14 | // @match https://dl.acm.org/doi/* 15 | // @match https://ieeexplore.ieee.org/* 16 | // @match https://journals.sagepub.com/* 17 | // @match https://link.springer.com/* 18 | // @match https://onlinelibrary.wiley.com/doi/* 19 | // @match https://psycnet.apa.org/* 20 | // @match https://pubmed.ncbi.nlm.nih.gov/* 21 | // @match https://pubs.rsc.org/* 22 | // @match https://pubs.acs.org/doi/* 23 | // @match https://pubsonline.informs.org/doi/abs/* 24 | // @match https://schlr.cnki.net/Detail/index/* 25 | // @match https://schlr.cnki.net//Detail/index/* 26 | // @match https://xueshu.baidu.com/usercenter/paper/* 27 | // @match https://www.aeaweb.org/* 28 | // @match https://www.ingentaconnect.com/* 29 | // @match https://www.jstor.org/* 30 | // @match https://www.nature.com/* 31 | // @match https://www.ncbi.nlm.nih.gov/* 32 | // @match https://www.researchgate.net/* 33 | // @match https://www.sciencedirect.com/* 34 | // @match http://www.socolar.com/* 35 | // @match https://www.scinapse.io/* 36 | // @match https://www.science.org/* 37 | // @match https://www.tandfonline.com/* 38 | // @match https://www.webofscience.com/wos/* 39 | // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js 40 | // @require https://cdn.jsdelivr.net/gh/sizzlemctwizzle/GM_config@2207c5c1322ebb56e401f03c2e581719f909762a/gm_config.js 41 | // @grant GM_getValue 42 | // @grant GM_setValue 43 | // @grant GM_registerMenuCommand 44 | // @grant GM.xmlHttpRequest 45 | // ==/UserScript== 46 | 47 | // global variables 48 | const defaultBaseURL = "https://sci-hub.se"; 49 | let sciHubBaseURL; 50 | const doiRegex = new RegExp('(10\.\\d{4,}/[-._;()/:\\w]+)'); 51 | const completePrefix = ['http://dx.doi.org/', 'https://doi.org/', 'https://dx.doi.org/']; 52 | const partialPrefix = ['//dx.doi.org/']; 53 | 54 | // Initialize configuration page 55 | GM_config.init({ 56 | 'id': 'DOI2Sci-Hub', 57 | 'title': 'Settings', 58 | 'fields': { 59 | 'UserDefinedBaseURL': { 60 | 'label': 'Custom Sci-Hub URL', 61 | 'type': 'text', 62 | 'default': '' 63 | } 64 | } 65 | }); 66 | 67 | const callback = function(mutationsList, observer) { 68 | 69 | if (!$('.sci-hub-link').length) { 70 | // Web of Science New Interface 71 | convertPlainTextDOI('span#FullRTa-DOI'); 72 | 73 | // scinapse 74 | convertPlainTextDOI('span[class*="doiInPaperShow_doiContext"]'); 75 | 76 | // PsycNet 77 | // journal article info page 78 | convertPlainTextDOI('div.citation div a'); 79 | // search result page 80 | convertPlainTextDOI('a[tooltip="DOI link"]'); 81 | 82 | // General 83 | convertHrefDOI(completePrefix, true); 84 | convertHrefDOI(partialPrefix, false); 85 | } 86 | }; 87 | 88 | (function () { 89 | 'use strict'; 90 | GM_registerMenuCommand("Settings", openSettingsPanel, "s"); 91 | const userDefinedBaseURL = GM_config.get('UserDefinedBaseURL'); 92 | 93 | if (userDefinedBaseURL.length != 0) { 94 | console.log('Load user-defined base URL'); 95 | sciHubBaseURL = userDefinedBaseURL.trim(); 96 | sciHubBaseURL += sciHubBaseURL.endsWith("/") ? "" : "/"; 97 | redirectToSciHub(); 98 | return 99 | } 100 | 101 | console.log('Skip user-defined base URL'); 102 | GM.xmlHttpRequest({ 103 | method: "GET", 104 | url: "https://sci-hub.41610.org/", 105 | onload: function (response) { 106 | let data = response.responseText; 107 | sciHubBaseURL = $('li > a[href^="https://sci-hub"]', data).first().attr('href') ?? defaultBaseURL 108 | sciHubBaseURL += sciHubBaseURL.endsWith("/") ? "" : "/" 109 | redirectToSciHub() 110 | } 111 | }); 112 | })(); 113 | 114 | function redirectToSciHub() { 115 | 116 | // hyperlink 117 | 118 | convertHrefDOI(completePrefix, true); 119 | convertHrefDOI(partialPrefix, false); 120 | 121 | let observer = new MutationObserver(callback); 122 | const config = { childList: true, subtree: true }; 123 | observer.observe(document, config); 124 | 125 | // Plain text 126 | 127 | // Science 128 | convertPlainTextDOI('.meta-line:contains("DOI: 10.")'); 129 | 130 | // Web of Science 131 | convertPlainTextDOI('.FullRTa-DOI:contains("DOI:")'); 132 | 133 | // Baidu Scholar 134 | convertPlainTextDOI('.doi_wr > .kw_main'); 135 | 136 | // CNKI Scholar 137 | convertPlainTextDOI('.doc-doi > a'); 138 | 139 | // PubMed 140 | convertPlainTextDOI('span:contains("doi: 10")'); 141 | 142 | // ResearchGate 143 | // article detail page 144 | convertPlainTextDOI('div.research-detail-header-section__flex-container a.nova-legacy-e-link'); 145 | // search result 146 | convertPlainTextDOI('li.nova-legacy-e-list__item'); 147 | 148 | // AEA 149 | convertPlainTextDOI('#article-information cite span.doi'); 150 | 151 | } 152 | 153 | function convertPlainTextDOI(doiTextLineSelector) { 154 | if ($(doiTextLineSelector).length) { 155 | $(doiTextLineSelector).each(function () { 156 | let modified = $(this).html().replace(doiRegex, `$1'); 157 | $(this).html(modified); 158 | }); 159 | $('.sci-hub-link').css('background-color', '#FFFF00'); 160 | } 161 | } 162 | 163 | function convertHrefDOI(prefixArray, isComplete) { 164 | prefixArray.forEach((prefix) => { 165 | let elements = $(`a[href^="${prefix}"]`); 166 | if (elements.length) { 167 | let doi = ""; 168 | elements.each(function () { 169 | if (isComplete == false) { 170 | doi = $(this).text(); 171 | } else { 172 | doi = $(this).attr('href'); 173 | } 174 | $(this).attr('href', `${sciHubBaseURL}${doi}`); 175 | $(this).addClass('sci-hub-link'); 176 | $(this).css('background-color', '#FFFF00'); 177 | }); 178 | } 179 | }) 180 | } 181 | 182 | function openSettingsPanel() { 183 | GM_config.open(); 184 | } 185 | --------------------------------------------------------------------------------