Button to download PDF from iframe's pdfpath parameter

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

目前为 2025-04-18 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Button to download PDF from iframe's pdfpath parameter
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Adds a button to download PDF from iframe's pdfpath parameter
  6. // @author aspen138
  7. // @match https://wk.askci.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Create a button element
  16. const button = document.createElement('button');
  17. button.textContent = 'Download PDF';
  18. button.style.position = 'fixed';
  19. button.style.top = '10px';
  20. button.style.right = '10px';
  21. button.style.zIndex = '9999';
  22. button.style.padding = '10px';
  23. button.style.backgroundColor = '#4CAF50';
  24. button.style.color = 'white';
  25. button.style.border = 'none';
  26. button.style.borderRadius = '5px';
  27. button.style.cursor = 'pointer';
  28.  
  29. // Append button to the page
  30. document.body.appendChild(button);
  31.  
  32. // Add click event listener to the button
  33. button.addEventListener('click', () => {
  34. // Find the iframe
  35. const iframe = document.querySelector('iframe');
  36. if (!iframe) {
  37. alert('No iframe found on the page.');
  38. return;
  39. }
  40.  
  41. // Get iframe src
  42. const src = iframe.src;
  43. if (!src) {
  44. alert('Iframe src is empty.');
  45. return;
  46. }
  47.  
  48. // Extract query parameters
  49. const queryString = src.substring(src.indexOf('?') + 1);
  50. if (!queryString) {
  51. alert('No query parameters found in iframe src.');
  52. return;
  53. }
  54.  
  55. // Parse query parameters
  56. const urlParams = new URLSearchParams(queryString);
  57. const downloadUrl = urlParams.get('pdfpath');
  58.  
  59. if (!downloadUrl) {
  60. alert('No pdfpath parameter found in iframe src.');
  61. return;
  62. }
  63.  
  64. // Open the download URL in a new tab
  65. window.open(downloadUrl, '_blank');
  66. });
  67. })();