Greasy Fork镜像 支持简体中文。

penguinreaders下载pdf

免费下载penguinreaders的书pdf

  1. // ==UserScript==
  2. // @name penguinreaders下载pdf
  3. // @namespace https://gf.qytechs.cn
  4. // @match https://www.penguinreaders.co.uk/ladybird-books/*
  5. // @grant GM_setClipboard
  6. // @run-at document-start
  7. // @version 1.0
  8. // @author Gwen0x4c3
  9. // @description 免费下载penguinreaders的书pdf
  10. // @license GPL
  11. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14.  
  15. function sel(selector) {
  16. return document.querySelector(selector);
  17. }
  18.  
  19. function sels(selector) {
  20. return document.querySelectorAll(selector);
  21. }
  22.  
  23. async function getBookUrl(nonce, prod_id) {
  24. const formData = new FormData();
  25. formData.append('action', 'get_pdf_url');
  26. formData.append('nonce', nonce);
  27. formData.append('prod_id', prod_id);
  28. return await fetch(`https://www.penguinreaders.co.uk/wp-admin/admin-ajax.php`, {
  29. method: "POST",
  30. headers: {
  31. "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
  32. },
  33. body: new URLSearchParams(formData).toString()
  34. }).then(res => res.json());
  35. }
  36.  
  37. function hookRequest() {
  38. const originalOpen = XMLHttpRequest.prototype.open;
  39. XMLHttpRequest.prototype.open = function(method, url) {
  40. if (url.includes('generate_pdf_button')) {
  41. this.addEventListener('readystatechange', async function() {
  42. if (this.readyState == 4) {
  43. const nonceRegex = /nonce:\s*'([^']+)'/;
  44. const prodIdRegex = /prod_id:\s*(\d+)/;
  45.  
  46. const nonceMatch = this.responseText.match(nonceRegex);
  47. const prodIdMatch = this.responseText.match(prodIdRegex);
  48.  
  49. if (nonceMatch && nonceMatch[1] && prodIdMatch && prodIdMatch[1]) {
  50. const nonce = nonceMatch[1];
  51. const prodId = parseInt(prodIdMatch[1], 10);
  52.  
  53. const res = await getBookUrl(nonce, prodId);
  54. if (!res.result) {
  55. return;
  56. }
  57. const bookUrl = res.url;
  58. console.log(bookUrl)
  59.  
  60. const buttonRow = sel('.button-row');
  61. const button = document.createElement('button');
  62. button.className = 'link-button'
  63. button.textContent = 'DOWNLOAD BOOK';
  64. button.onclick = e => {
  65. // const a = document.createElement('a');
  66. // a.href = bookUrl;
  67. // a.download = sel('.section-hero-book .section-title').innerText;
  68. GM_setClipboard(sel('.section-hero-book .section-title').innerText, 'text/plain');
  69. // a.target = '_blank';
  70. // a.click();
  71. window.open(bookUrl + `&prod_id=${prodId}&label=View%20Book`);
  72. }
  73. buttonRow.prepend(button);
  74.  
  75. } else {
  76. console.error('未获取到呢');
  77. }
  78. }
  79. })
  80. }
  81. originalOpen.apply(this, arguments);
  82. }
  83. }
  84.  
  85. function remove() {
  86. if (!sel('.download-bar')) {
  87. return setTimeout(remove, 300);
  88. }
  89. const fades = sels('.download-bar-fade');
  90. for (const fade of fades) {
  91. fade.remove();
  92. }
  93. }
  94. remove();
  95. hookRequest();
  96. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址