Renta Papy Image Downloader

Download multiple whole chapters from Renta papy JP

  1. // ==UserScript==
  2. // @name Renta Papy Image Downloader
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Download multiple whole chapters from Renta papy JP
  6. // @source https://github.com/vsatyamesc/Renta_downloader
  7. // @match https://https://renta.papy.co.jp/*
  8. // @match https://dre-viewer.papy.co.jp/*
  9. // @grant none
  10. // @author vsatyamesc
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Create and style the download button
  18. const button = document.createElement('button');
  19. button.textContent = 'Download Images';
  20. Object.assign(button.style, {
  21. position: 'fixed',
  22. left: '20px',
  23. bottom: '20px',
  24. zIndex: 9999,
  25. padding: '8px 16px',
  26. backgroundColor: '#4CAF50',
  27. color: 'white',
  28. border: 'none',
  29. borderRadius: '4px',
  30. cursor: 'pointer',
  31. fontSize: '14px'
  32. });
  33.  
  34. // Add hover effect
  35. button.addEventListener('mouseover', () => {
  36. button.style.backgroundColor = '#45a049';
  37. });
  38. button.addEventListener('mouseout', () => {
  39. button.style.backgroundColor = '#4CAF50';
  40. });
  41.  
  42. // Add button to the page
  43. document.body.appendChild(button);
  44.  
  45. let isDownloading = false;
  46.  
  47. function save_image_to_device_vesc(base64image, index) {
  48. const a = document.createElement('a');
  49. a.href = base64image;
  50. a.download = `image_${index}.png`;
  51. document.body.appendChild(a);
  52. a.click();
  53. document.body.removeChild(a);
  54. }
  55.  
  56. function waitForCanvasUpdate(previousData, index, resolve) {
  57. const canvas = document.querySelector('#center .imgWrap canvas.canvas');
  58. const currentData = canvas.toDataURL('image/png', 1.0);
  59. if (currentData !== previousData) {
  60. resolve(currentData);
  61. } else {
  62. setTimeout(() => waitForCanvasUpdate(previousData, index, resolve), 100);
  63. }
  64. }
  65.  
  66. async function downloadImages() {
  67. if (isDownloading) return;
  68. isDownloading = true;
  69. button.textContent = 'Downloading...';
  70. button.style.backgroundColor = '#808080';
  71.  
  72. try {
  73. const image_max_1qa = document.getElementById('scrollBar');
  74. const start_img_1qa = Number(image_max_1qa.min);
  75. const end_img_1qa = Number(image_max_1qa.max);
  76.  
  77. let previousData = '';
  78. for (let i = start_img_1qa; i <= end_img_1qa; i++) {
  79. if (i === start_img_1qa) {
  80. const canvas = document.querySelector('#center .imgWrap canvas.canvas');
  81. previousData = canvas.toDataURL('image/png', 1.0);
  82. save_image_to_device_vesc(previousData, i);
  83. } else {
  84. jumpPage(i);
  85. const updatedImage = await new Promise(resolve =>
  86. waitForCanvasUpdate(previousData, i, resolve)
  87. );
  88. save_image_to_device_vesc(updatedImage, i);
  89. previousData = updatedImage;
  90. }
  91. }
  92. } catch (error) {
  93. console.error('Error during download:', error);
  94. alert('Download failed: ' + error.message);
  95. } finally {
  96. isDownloading = false;
  97. button.textContent = 'Download Images';
  98. button.style.backgroundColor = '#4CAF50';
  99. }
  100. }
  101.  
  102. button.addEventListener('click', downloadImages);
  103. })();