从iframe的pdfpath参数下载PDF的按钮

添加一个按钮,用于从iframe的pdfpath参数下载PDF

当前为 2025-04-22 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Button to download PDF from iframe's pdfpath parameter
// @description  Adds a button to download PDF from iframe's pdfpath parameter
// @name:zh-CN   从iframe的pdfpath参数下载PDF的按钮
// @description:zh-CN  添加一个按钮,用于从iframe的pdfpath参数下载PDF
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @author       aspen138
// @match        https://wk.askci.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Create a button element
    const button = document.createElement('button');
    button.textContent = 'Download PDF';
    button.style.position = 'fixed';
    button.style.top = '10px';
    button.style.right = '10px';
    button.style.zIndex = '9999';
    button.style.padding = '10px';
    button.style.backgroundColor = '#4CAF50';
    button.style.color = 'white';
    button.style.border = 'none';
    button.style.borderRadius = '5px';
    button.style.cursor = 'pointer';

    // Append button to the page
    document.body.appendChild(button);

    // Add click event listener to the button
    button.addEventListener('click', () => {
        // Find the iframe
        const iframe = document.querySelector('iframe');
        if (!iframe) {
            alert('No iframe found on the page.');
            return;
        }

        // Get iframe src
        const src = iframe.src;
        if (!src) {
            alert('Iframe src is empty.');
            return;
        }

        // Extract query parameters
        const queryString = src.substring(src.indexOf('?') + 1);
        if (!queryString) {
            alert('No query parameters found in iframe src.');
            return;
        }

        // Parse query parameters
        const urlParams = new URLSearchParams(queryString);
        const downloadUrl = urlParams.get('pdfpath');

        if (!downloadUrl) {
            alert('No pdfpath parameter found in iframe src.');
            return;
        }

        // Open the download URL in a new tab
        window.open(downloadUrl, '_blank');
    });
})();