archiveOrgAssistant

download books from archive.org

目前為 2023-02-23 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name archiveOrgAssistant
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.18
  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+')','i');
  18. let conf = [
  19. "Please don't change this file manually, it's important",
  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. conf.push(i.replace(/(logged-in-|-identifier)/i,'').replace('-'+bookid,''));
  28. }
  29. });
  30. if(!/\/details\/\w+/i.test(location.pathname)){
  31. alert("Working on book loan page only");
  32. return;
  33. }
  34. let img = document.querySelector('.BRpagecontainer .BRpageimage');
  35. if(!img){
  36. alert("Please fresh page and try again");
  37. return;
  38. }
  39. let url = new URL(img.src);
  40. let zipm = url.search.match(/=\/(\d+)\/items\//);
  41. if(url.search.indexOf('&server='+url.hostname) != -1){
  42. alert("Please borrow the book first!");
  43. return;
  44. }
  45. let title = document.title.split(/\s*:\s*/g)[0];
  46. proxy = prompt("Input proxy string like http://127.0.0.1:8899, if no proxy keep it empty");
  47. conf.push('title='+title);
  48. conf.push('authority='+url.hostname);
  49. conf.push('path='+location.pathname);
  50. conf.push('bookid='+bookid);
  51. conf.push('zipnum='+(zipm?zipm[1]:'29'));
  52. conf.push('proxy='+(proxy?proxy.replace(/[\r\n\t\s]+/g,''): ''));
  53. conf.push("=========================================================");
  54. conf.push("version: 0.1");
  55. conf.push("author : https://codernote.club");
  56. ele.style.display = 'none';
  57. ele.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(conf.join('\n')));
  58. ele.setAttribute('download', 'config.conf');
  59. document.body.appendChild(ele);
  60. ele.click();
  61. document.body.removeChild(ele);
  62. }
  63.  
  64. (function() {
  65. 'use strict';
  66. let bookid = location.pathname.split('/details/')[1].split('/')[0];
  67. GM_registerMenuCommand("get Configuration", function(evt, keybord){
  68. let cookie = document.cookie;
  69. if(/logged-in-sig=[^;]+/.test(cookie) && /logged-in-user=[^;]+/.test(cookie)){
  70. getConfig(bookid);
  71. }
  72. });
  73. GM_registerMenuCommand("get Downloader", function(evt, keybord){
  74. window.open('https://github.com/mooring/archive.org.book.downloader');
  75. });
  76. })();