Button to download PDF from iframe's pdfpath parameter

Adds a button to download PDF from iframe's pdfpath parameter

目前為 2025-04-22 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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');
    });
})();