Greasy Fork 支持简体中文。

Button to download PDF from iframe's pdfpath parameter

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

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