AIAA PDF Download Button

Add PDF download button based on AIAA DOI link

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name                AIAA PDF Download Button
// @name:zh-CN          AIAA PDF 下载按钮
// @namespace           https://greasyfork.org/zh-CN/users/1335433
// @version             0.4
// @description         Add PDF download button based on AIAA DOI link
// @description:zh-CN   根据 AIAA DOI 链接添加 PDF 下载按钮
// @author              wakewon
// @match               https://arc.aiaa.org/*
// @include             *://arc-aiaa-org-s.*
// @grant               none
// @license             MIT
// ==/UserScript==

(function() {
    'use strict';

    // Find the DOI link
    var doiLink = document.querySelector('.epub-section__doi__text');
    if (doiLink) {
        var doiURL = doiLink.getAttribute('href');
        var doi = doiURL.match(/https:\/\/doi.org\/(.*)/)[1];

        // Find the "Read Now" button
        var readNowButton = document.querySelector('a[aria-label=" Read Now"]');
        if (readNowButton) {
            // Create a new "Download Now" button next to the "Read Now" button
            var downloadNowButton = document.createElement('a');
            downloadNowButton.href = '/doi/pdf/' + doi + '?download=true';
            downloadNowButton.innerText = ' Download';
            downloadNowButton.className = 'ctrl--primary ctrl';

            // Add icon to the "Download Now" button
            var icon = document.createElement('i');
            icon.className = 'icon-download';
            downloadNowButton.insertBefore(icon, downloadNowButton.firstChild);

            // Insert the "Download Now" button after the "Read Now" button
            readNowButton.parentNode.insertBefore(downloadNowButton, readNowButton.nextSibling);
        }
    }
})();