ScienceDirect下载

避免跳转在线pdf,可直接下载ScienceDirect文献到本地,支持自定义文件名

  1. // ==UserScript==
  2. // @name ScienceDirect Download
  3. // @name:zh-CN ScienceDirect下载
  4. // @namespace tampermonkey.com
  5. // @icon https://gf.qytechs.cn/vite/assets/blacklogo96-e0c2c761.png
  6. // @version 3.2.7
  7. // @license MIT
  8. // @description Avoid jumping to online pdf,and directly download ScienceDirect literature to local,Support custom file names.
  9. // @description:zh-CN 避免跳转在线pdf,可直接下载ScienceDirect文献到本地,支持自定义文件名
  10. // @homepageURL https://gf.qytechs.cn/zh-CN/scripts/451690-sciencedirect-download
  11. // @supportURL https://gf.qytechs.cn/zh-CN/scripts/451690-sciencedirect-download/feedback
  12. // @match *://www.sciencedirect.com/*
  13. // @match *://pdf.sciencedirectassets.com/*
  14. // @match *://sci-hub.ee/*
  15. // @match *://scholar.cnki.net/*
  16. // @grant GM_setValue
  17. // @grant GM_getValue
  18. // @grant GM.xmlHttpRequest
  19. // @grant GM_registerMenuCommand
  20. // @connect sciencedirectassets.com
  21. // @connect bban.top
  22. // @run-at document-start
  23. // ==/UserScript==
  24.  
  25. // global variables
  26. var defaultBaseURL = 'https://sci-hub.ee';
  27.  
  28. // Initialize configuration page
  29.  
  30. function getBlob(url, cb) {
  31. GM.xmlHttpRequest({
  32. method: "GET",
  33. url: url,
  34. responseType: 'blob',
  35. headers: {
  36. 'Content-Type': 'application/pdf',
  37. 'User-Agent:': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0'
  38. },
  39. onload: function (response) {
  40. cb(response.response);
  41. }
  42. })
  43. }
  44.  
  45. function getHtml(url, cb) {
  46. GM.xmlHttpRequest({
  47. method: "GET",
  48. url: url,
  49. responseType: 'text/html',
  50. headers: {
  51. 'Content-Type': 'text/html',
  52. 'User-Agent:': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0'
  53. },
  54. onload: function (response) {
  55. cb(response.response);
  56. }
  57. })
  58. }
  59.  
  60. function saveAs(blob, filename) {
  61. if (window.navigator.msSaveOrOpenBlob) {
  62. navigator.msSaveBlob(blob, filename);
  63. } else {
  64. let link = document.createElement('a');
  65. let body = document.querySelector('body');
  66. let e404 = document.getElementsByClassName("e404");
  67. if (e404.length==0)
  68. {
  69. link.href = window.URL.createObjectURL(blob);
  70. link.download = filename;
  71. // fix Firefox
  72. link.style.display = 'none';
  73. body.appendChild(link);
  74. link.click();
  75. body.removeChild(link);
  76. window.URL.revokeObjectURL(link.href);
  77. }else{
  78. return;
  79. }
  80. };
  81. }
  82.  
  83. function checkBlob(blob) {
  84. const type = blob.type.split(';')[0].trim();
  85. return type === 'application/pdf';
  86. }
  87.  
  88. function checkCraft(link) {
  89. return link.includes('craft/capi/cfts/')
  90. }
  91.  
  92. function mainDownload(url, filename) {
  93. getBlob(url, function (blob) {
  94. if (checkBlob(blob)) {
  95. saveAs(blob, filename);
  96. } else {
  97. getHtml(url, function (html) {
  98. document.open();
  99. document.write(html);
  100. document.close();
  101. });
  102. }
  103. });
  104. }
  105.  
  106. function downloadScihub() {
  107. let doi = document.title.split(' | ')[document.title.split(' | ').length - 1]
  108. try { doi = doi.replace('(', '%2528').replace(')', '%2529') } catch (err) { }
  109. let title = document.title.split('Sci-Hub | ')[1].replace(' | ', ' _ ');
  110. let ret = prompt('Type your filename and click confirm to download!', title);
  111. let url = "https://sci.bban.top/pdf/" + doi + ".pdf?download=true"
  112. if (ret !== null && ret != '') {
  113. let filename = ret + '.pdf';
  114. mainDownload(url, filename);
  115. }
  116. }
  117.  
  118. function downloadScidirect() {
  119. let url = document.URL + '&download=true';
  120. console.log(url);
  121. let title = document.URL.split("/")[5].split("-")[2];
  122. try {
  123. var id = document.URL.split("/")[5].split("-")[2]
  124. title = GM_getValue(id)
  125. } catch (err) {
  126. console.log("err_message" + err.message);
  127. }
  128. // var html_url = "https://www.sciencedirect.com/science/article/pii/" + document.URL.split("/")[5].split("-")[2]
  129. let ret = prompt('Type your filename and click confirm to download!', title);
  130. if (ret !== null && ret != '') {
  131. let filename = ret + '.pdf';
  132. mainDownload(url, filename);
  133. }
  134. }
  135.  
  136.  
  137. (function () {
  138. 'use strict';
  139. if (GM_getValue('userDefinedBaseURL') == null) {
  140. GM_setValue('userDefinedBaseURL', defaultBaseURL)
  141. }
  142. var userDefinedBaseURL = GM_getValue('userDefinedBaseURL')
  143. GM_registerMenuCommand(`Customize your scihub address`, () => {
  144. userDefinedBaseURL = prompt("customize scihub address,e.g.>>" + defaultBaseURL, defaultBaseURL);
  145. if (userDefinedBaseURL) {
  146. GM_setValue('userDefinedBaseURL', userDefinedBaseURL);
  147. location.reload();
  148. }
  149. });
  150. var domain = document.domain;
  151.  
  152. if (domain == 'www.sciencedirect.com') {
  153. let access = null;
  154. document.addEventListener('DOMContentLoaded', (event) => {
  155. console.log('DOM加载完成.');
  156. let linkid = document.head.getElementsByTagName('meta')[0].content;
  157. let titile = document.title.replace(' - ScienceDirect', '');
  158. GM_setValue(linkid, titile);
  159. try {
  160. access = document.querySelector("#mathjax-container > div.accessbar-sticky > div:nth-child(2) > div > ul > li.RemoteAccess > a").href.split('ogin')[1];
  161. }
  162. catch(e){
  163. console.log("Congratruation!You have the access."); // re-throw the error unchanged
  164. }
  165. let doi = document.getElementsByClassName('anchor doi anchor-primary')[0].href.split('org')[1];
  166. GM_setValue('access', access);
  167. let types = 'download';
  168. let new_url = "https://www.sciencedirect.com/science/article/pii/" + linkid + "/pdfft?isDTMRedir=true"
  169. if (GM_getValue('access')) {
  170. console.log("Sorry!You haven't the access.")
  171. userDefinedBaseURL = GM_getValue('userDefinedBaseURL');
  172. new_url = userDefinedBaseURL + doi;
  173. types = 'scihub'
  174. }
  175. let Container = document.createElement('div');
  176. let s = window.screen.width / 1920;
  177. let left = "250px";
  178. let top = "20px";
  179. if (s < 0.5) {
  180. left = (100 * s).toString() + "px";
  181. top = (18 + 10 / s).toString() + "px";
  182. }
  183. console.log(left);
  184. Container.id = "sp-ac-container";
  185. Container.style.position = "fixed";
  186. Container.style.left = left;
  187. Container.style.top = top;
  188. Container.style['z-index'] = "2";
  189. Container.innerHTML = `<button title="Click to download" class="button1" onclick="window.open('${new_url}')">${types}</button>
  190. <style>
  191. .button1 {
  192. -webkit-transition-duration: 0.4s;
  193. transition-duration: 0.4s;
  194. padding: 1.5px 6px;
  195. text-align: center;
  196. background-color: #f5f5f5;
  197. color: rgb(243, 109, 33);
  198. border: 0.5px rgb(134, 218, 209);
  199. border-radius: 9px;
  200. font-family: NexusSans,Arial,Helvetica,Lucida Sans Unicode,Microsoft Sans Serif,Segoe UI Symbol,STIXGeneral,Cambria Math,Arial Unicode MS,sans-serif!important;
  201. }
  202. .button1:hover {
  203. background-color: rgb(134, 218, 209);;;
  204. color: red;
  205. }
  206. </style>`;
  207. document.body.appendChild(Container);
  208.  
  209. });
  210. }
  211. if (domain == 'scholar.cnki.net') {
  212. window.onload = function () {
  213. if (document.URL.includes('/Detail/index/')) {
  214. let doi2 = document.querySelector("#__next > div > div.detail_detail-main__11Hij > div.detail_content__3IojM > div.detail_content-left__2vUAX > div > div.detail_doc__20q8z > div:nth-child(1) > div.detail_doc-doi__VX6o2.detail_doc-item__2l-2B").textContent.replace('DOI: ', '')
  215. let new_url2 = userDefinedBaseURL + '/' + doi2
  216. console.log(userDefinedBaseURL)
  217. let Container2 = document.createElement('p');
  218. Container2.style.position = "fixed";
  219. Container2.id = "sp-ac-container";
  220. Container2.style.top = "120px";
  221. Container2.style['z-index'] = "2";
  222. Container2.innerHTML = `<button title="Click to download" class="button1" onclick="window.open('${new_url2}')">scihub</button>
  223. <style>
  224. .button1 {
  225. -webkit-transition-duration: 0.4s;
  226. -webkit-text-size-adjust: 100%;
  227. transition-duration: 0.4s;
  228. width:80px;
  229. height:50px;
  230. padding: 1.5px 6px;
  231. text-align: center;
  232. background-color: #506698;
  233. color: white;
  234. border: 0.5px rgb(134, 218, 209);
  235. border-radius: 8px;
  236. font-family: NexusSans,Arial,Helvetica,Lucida Sans Unicode,Microsoft Sans Serif,Segoe UI Symbol,STIXGeneral,Cambria Math,Arial Unicode MS,sans-serif!important;
  237. }
  238. .button1:hover {
  239. background-color: rgb(134, 218, 209);;;
  240. color: rgb(243, 109, 33);
  241. }
  242. </style>`;
  243. document.getElementsByClassName('detail_detail-main__11Hij')[0].append(Container2)
  244. }
  245. }
  246. }
  247. if (domain == 'pdf.sciencedirectassets.com') {
  248. let link = document.URL;
  249. if(checkCraft(link))
  250. {
  251. return;
  252. }else{
  253. downloadScidirect()
  254. };
  255. }
  256. if (domain == 'sci-hub.ee') {
  257. downloadScihub()
  258. }
  259. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址