archiveOrgAssistant

download books from archive.org

  1. // ==UserScript==
  2. // @name archiveOrgAssistant
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.23
  5. // @description download books from archive.org
  6. // @author mooring@codernote.club
  7. // @match https://archive.org/details/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=archive.org
  9. // @run-at document-idle
  10. // @grant GM_registerMenuCommand
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. function getConfig(bookid){
  15. let ele = document.createElement('a');
  16. let cookies = document.cookie.split('; ');
  17. let regxp =new RegExp('^(logged-in-user|donation-identifier|logged-in-sig|PHPSESSID|loan-'+bookid+'|br-resume-%40)','i');
  18. let conf = [
  19. "DON'T EDIT THIS FILE MANUALLY archive.org book downloader 0.22 by mooring@live.com",
  20. "get the downloader from https://github.com/mooring/archive.org.book.downloader",
  21. "then following the constructions",
  22. "============================================================================",
  23. ];
  24. let proxy = '';
  25. cookies.forEach(i=>{
  26. if(regxp.test(i)){
  27. if(i.indexOf('br-resume-')!=-1){
  28. i = 'br-resume='+i.split('=')[0]
  29. }
  30. conf.push(i.replace(/(logged-in-|-identifier)/i,'').replace('-'+bookid,''));
  31. }
  32. });
  33. if(!/\/details\/\w+/i.test(location.pathname)){
  34. alert("Working on book loan page only");
  35. return;
  36. }
  37. let img = document.querySelector('.BRpagecontainer .BRpageimage');
  38. if(!img){
  39. alert("Please fresh page and try again");
  40. return;
  41. }
  42. let url = new URL(img.src);
  43. let zipm = url.search.match(/=\/(\d+)\/items\//);
  44. if(url.search.indexOf('&server='+url.hostname) != -1){
  45. alert("Please borrow the book first!");
  46. return;
  47. }
  48. let title = document.title.split(/\s*:\s*/g).slice(0,-2).join(':').replace(/[\r\n]+/g,' ');
  49. let lproxy = localStorage.getItem('archiveAssistant_proxy');
  50. proxy = prompt("Input proxy string like http://127.0.0.1:8899, if no proxy keep it empty", lproxy || '');
  51. localStorage.setItem('archiveAssistant_proxy', proxy||'');
  52. conf.push('title='+title);
  53. conf.push('authority='+url.hostname);
  54. conf.push('path='+location.pathname);
  55. conf.push('bookid='+bookid);
  56. conf.push('zipnum='+(zipm?zipm[1]:'29'));
  57. conf.push('proxy='+(proxy?proxy.replace(/[\r\n\t\s]+/g,''): ''));
  58. conf.push("=========================================================");
  59. conf.push("version: 0.1");
  60. conf.push("author : https://codernote.club");
  61. ele.style.display = 'none';
  62. ele.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(conf.join('\n')));
  63. ele.setAttribute('download', 'config.conf');
  64. document.body.appendChild(ele);
  65. ele.click();
  66. document.body.removeChild(ele);
  67. }
  68.  
  69. (function() {
  70. 'use strict';
  71. let bookid = location.pathname.split('/details/')[1].split('/')[0];
  72. GM_registerMenuCommand("get Configuration", function(evt, keybord){
  73. let cookie = document.cookie;
  74. if(/logged-in-sig=[^;]+/.test(cookie) && /logged-in-user=[^;]+/.test(cookie)){
  75. getConfig(bookid);
  76. }
  77. });
  78. GM_registerMenuCommand("get Downloader", function(evt, keybord){
  79. window.open('https://github.com/mooring/archive.org.book.downloader');
  80. });
  81. })();

QingJ © 2025

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