Internet Archive Pdf Download Link

generate a button for borrowed Internet Archive books.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Internet Archive Pdf Download Link
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  generate a button for borrowed Internet Archive books.
// @author       BA
// @match        https://archive.org/details/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';


     window.addEventListener('load', () => {
    addButton('Download PDF', downloadAcsmFn)
    })

    function addButton(text, onclick, cssObj) {

        const button = document.createElement('button')
        const titleEl = document.getElementById("IABookReaderMessageWrapper");
        titleEl.appendChild(button)
        button.innerHTML = text;
        button.onclick = onclick;
        return button
    }

    function downloadAcsmFn() {

        const currentUrl = document.URL
        const urlPartRaw = [...currentUrl.match(/org\/details\/(.*)/)]
        if (urlPartRaw.length > 0) {
        const identifier = urlPartRaw[1].split("/")[0];
        const acsmUrl = "https://archive.org/services/loans/loan/?action=media_url&identifier=" + identifier + "&format=pdf&redirect=1";
        window.open(acsmUrl, '_blank');
        }

    }


})();