Internet Archive Pdf Download Link

generate a button for borrowed Internet Archive books.

  1. // ==UserScript==
  2. // @name Internet Archive Pdf Download Link
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description generate a button for borrowed Internet Archive books.
  6. // @author BA
  7. // @match https://archive.org/details/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16.  
  17. window.addEventListener('load', () => {
  18. addButton('Download PDF', downloadAcsmFn)
  19. })
  20.  
  21. function addButton(text, onclick, cssObj) {
  22.  
  23. const button = document.createElement('button')
  24. const titleEl = document.getElementById("IABookReaderMessageWrapper");
  25. titleEl.appendChild(button)
  26. button.innerHTML = text;
  27. button.onclick = onclick;
  28. return button
  29. }
  30.  
  31. function downloadAcsmFn() {
  32.  
  33. const currentUrl = document.URL
  34. const urlPartRaw = [...currentUrl.match(/org\/details\/(.*)/)]
  35. if (urlPartRaw.length > 0) {
  36. const identifier = urlPartRaw[1].split("/")[0];
  37. const acsmUrl = "https://archive.org/services/loans/loan/?action=media_url&identifier=" + identifier + "&format=pdf&redirect=1";
  38. window.open(acsmUrl, '_blank');
  39. }
  40.  
  41. }
  42.  
  43.  
  44. })();