Twitter/X Media Batch Downloader

Batch download all images and videos from a Twitter/X account, including withheld accounts, in original quality.

  1. // ==UserScript==
  2. // @name Twitter/X Media Batch Downloader
  3. // @description Batch download all images and videos from a Twitter/X account, including withheld accounts, in original quality.
  4. // @icon https://raw.githubusercontent.com/afkarxyz/Twitter-X-Media-Batch-Downloader/refs/heads/main/Archived/icon.svg
  5. // @version 4.3
  6. // @author afkarxyz
  7. // @namespace https://github.com/afkarxyz/userscripts/
  8. // @supportURL https://github.com/afkarxyz/userscripts/issues
  9. // @homepageURL https://www.patreon.com/exyezed
  10. // @antifeature Payment
  11. // @license MIT
  12. // @match https://twitter.com/*
  13. // @match https://x.com/*
  14. // @grant GM_xmlhttpRequest
  15. // @grant GM_setValue
  16. // @grant GM_getValue
  17. // @grant GM_download
  18. // @connect api.xbatch.online
  19. // @connect backup.xbatch.online
  20. // @connect pbs.twimg.com
  21. // @connect video.twimg.com
  22. // @require https://cdn.jsdelivr.net/npm/jszip@3.7.1/dist/jszip.min.js
  23. // ==/UserScript==
  24.  
  25. ;(() => {
  26. const JSZip = window.JSZip;
  27.  
  28. const API_URLS = {
  29. DEFAULT: "https://api.xbatch.online",
  30. BACKUP: "https://backup.xbatch.online"
  31. }
  32.  
  33. const ICONS = {
  34. PREV: `<svg style="width: 12px; height: 12px; margin-right: 6px; display: inline-block; vertical-align: middle;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512">
  35. <path fill="currentColor" d="M9.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l192 192c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L77.3 256 246.6 86.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-192 192z"/>
  36. </svg>`,
  37. NEXT: `<svg style="width: 12px; height: 12px; margin-left: 6px; display: inline-block; vertical-align: middle;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512">
  38. <path fill="currentColor" d="M310.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-192 192c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L242.7 256 73.4 86.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l192 192z"/>
  39. </svg>`,
  40. AUTO: `<svg style="width: 12px; height: 12px; margin-right: 6px; display: inline-block; vertical-align: middle;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
  41. <path fill="currentColor" d="M327.5 85.2c-4.5 1.7-7.5 6-7.5 10.8s3 9.1 7.5 10.8L384 128l21.2 56.5c1.7 4.5 6 7.5 10.8 7.5s9.1-3 10.8-7.5L448 128l56.5-21.2c4.5-1.7 7.5-6 7.5-10.8s-3-9.1-7.5-10.8L448 64 426.8 7.5C425.1 3 420.8 0 416 0s-9.1 3-10.8 7.5L384 64 327.5 85.2zM205.1 73.3c-2.6-5.7-8.3-9.3-14.5-9.3s-11.9 3.6-14.5 9.3L123.3 187.3 9.3 240C3.6 242.6 0 248.3 0 254.6s3.6 11.9 9.3 14.5l114.1 52.7L176 435.8c2.6 5.7 8.3 9.3 14.5 9.3s11.9-3.6 14.5-9.3l52.7-114.1 114.1-52.7c5.7-2.6 9.3-8.3 9.3-14.5s-3.6-11.9-9.3-14.5L257.8 187.4 205.1 73.3zM384 384l-56.5 21.2c-4.5 1.7-7.5 6-7.5 10.8s3 9.1 7.5 10.8L384 448l21.2 56.5c1.7 4.5 6 7.5 10.8 7.5s9.1-3 10.8-7.5L448 448l56.5-21.2c4.5-1.7 7.5-6 7.5-10.8s-3-9.1-7.5-10.8L448 384l-21.2-56.5c-1.7-4.5-6-7.5-10.8-7.5s-9.1 3-10.8 7.5L384 384z"/>
  42. </svg>`,
  43. STOP: `<svg style="width: 12px; height: 12px; margin-right: 6px; display: inline-block; vertical-align: middle;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512">
  44. <path fill="currentColor" d="M0 128C0 92.7 28.7 64 64 64H320c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128z"/>
  45. </svg>`,
  46. CLEAR: {
  47. PATH: "M135.2 17.7C140.6 6.8 151.7 0 163.8 0L284.2 0c12.1 0 23.2 6.8 28.6 17.7L320 32l96 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 96C14.3 96 0 81.7 0 64S14.3 32 32 32l96 0 7.2-14.3zM32 128l384 0 0 320c0 35.3-28.7 64-64 64L96 512c-35.3 0-64-28.7-64-64l0-320zm96 64c-8.8 0-16 7.2-16 16l0 224c0 8.8 7.2 16 16 16s16-7.2 16-16l0-224c0-8.8-7.2-16-16-16zm96 0c-8.8 0-16 7.2-16 16l0 224c0 8.8 7.2 16 16 16s16-7.2 16-16l0-224c0-8.8-7.2-16-16-16zm96 0c-8.8 0-16 7.2-16 16l0 224c0 8.8 7.2 16 16 16s16-7.2 16-16l0-224c0-8.8-7.2-16-16-16z",
  48. VIEWBOX: "0 0 448 512"
  49. },
  50. RESET: {
  51. PATH: "M463.5 224l8.5 0c13.3 0 24-10.7 24-24l0-128c0-9.7-5.8-18.5-14.8-22.2s-19.3-1.7-26.2 5.2L413.4 96.6c-87.6-86.5-228.7-86.2-315.8 1c-87.5 87.5-87.5 229.3 0 316.8s229.3 87.5 316.8 0c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0c-62.5 62.5-163.8 62.5-226.3 0s-62.5-163.8 0-226.3c62.2-62.2 162.7-62.5 225.3-1L327 183c-6.9 6.9-8.9 17.2-5.2 26.2s12.5 14.8 22.2 14.8l119.5 0z",
  52. VIEWBOX: "0 0 512 512"
  53. },
  54. PATREON: {
  55. PATH: "M489.7 153.8c-.1-65.4-51-119-110.7-138.3C304.8-8.5 207-5 136.1 28.4C50.3 68.9 23.3 157.7 22.3 246.2C21.5 319 28.7 510.6 136.9 512c80.3 1 92.3-102.5 129.5-152.3c26.4-35.5 60.5-45.5 102.4-55.9c72-17.8 121.1-74.7 121-150z",
  56. VIEWBOX: "0 0 512 512"
  57. },
  58. INFO: {
  59. PATH: "M256 48a208 208 0 1 1 0 416 208 208 0 1 1 0-416zm0 464A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336c-13.3 0-24 10.7-24 24s10.7 24 24 24l80 0c13.3 0 24-10.7 24-24s-10.7-24-24-24l-8 0 0-88c0-13.3-10.7-24-24-24l-48 0c-13.3 0-24 10.7-24 24s10.7 24 24 24l24 0 0 64-24 0zm40-144a32 32 0 1 0 0-64 32 32 0 1 0 0 64z",
  60. VIEWBOX: "0 0 512 512"
  61. },
  62. DOWNLOAD: {
  63. SECONDARY_PATH: "M0 256C0 397.4 114.6 512 256 512s256-114.6 256-256c0-17.7-14.3-32-32-32s-32 14.3-32 32c0 106-86 192-192 192S64 362 64 256c0-17.7-14.3-32-32-32s-32 14.3-32 32z",
  64. PRIMARY_PATH: "M390.6 185.4c12.5 12.5 12.5 32.8 0 45.3l-112 112c-12.5 12.5-32.8 12.5-45.3 0l-112-112c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L224 242.7 224 32c0-17.7 14.3-32 32-32s32 14.3 32 32l0 210.7 57.4-57.4c12.5-12.5 32.8-12.5 45.3 0z",
  65. VIEWBOX: "0 0 512 512"
  66. },
  67. FETCH: {
  68. PATH: "M374.6 214.6l-128 128c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L192 242.7 192 32c0-17.7 14.3-32 32-32s32 14.3 32 32l0 210.7 73.4-73.4c12.5-12.5 32.8-12.5 45.3 0s12.5 32.8 0 45.3zM64 352l0 64c0 17.7 14.3 32 32 32l256 0c17.7 0 32-14.3 32-32l0-64c0-17.7 14.3-32 32-32s32 14.3 32 32l0 64c0 53-43 96-96 96L96 512c-53 0-96-43-96-96l0-64c0-17.7 14.3-32 32-32s32 14.3 32 32z",
  69. VIEWBOX: "0 0 448 512"
  70. },
  71. ACCOUNT: {
  72. PATH: "M412.1 416.6C398.1 361.1 347.9 320 288 320l-64 0c-59.9 0-110.1 41.1-124.1 96.6C58 375.9 32 319 32 256C32 132.3 132.3 32 256 32s224 100.3 224 224c0 63-26 119.9-67.9 160.6zm-28.5 23.4C347.5 465.2 303.5 480 256 480s-91.5-14.8-127.7-39.9c4-49.3 45.3-88.1 95.7-88.1l64 0c50.4 0 91.6 38.8 95.7 88.1zM256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zm0-256a48 48 0 1 1 0-96 48 48 0 1 1 0 96zm-80-48a80 80 0 1 0 160 0 80 80 0 1 0 -160 0z",
  73. VIEWBOX: "0 0 512 512"
  74. },
  75. TOTAL: {
  76. PATH: "M320 464c8.8 0 16-7.2 16-16l0-288-80 0c-17.7 0-32-14.3-32-32l0-80L64 48c-8.8 0-16 7.2-16 16l0 384c0 8.8 7.2 16 16 16l256 0zM0 64C0 28.7 28.7 0 64 0L229.5 0c17 0 33.3 6.7 45.3 18.7l90.5 90.5c12 12 18.7 28.3 18.7 45.3L384 448c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 64z",
  77. VIEWBOX: "0 0 384 512"
  78. },
  79. BATCH: {
  80. PATH: "M48 272L48 64c0-8.8 7.2-16 16-16l160 0 0 80c0 17.7 14.3 32 32 32l80 0 0 112L48 272zm288 48l16 0 32 0 0-165.5c0-17-6.7-33.3-18.7-45.3L274.7 18.7C262.7 6.7 246.5 0 229.5 0L64 0C28.7 0 0 28.7 0 64L0 320l32 0 16 0 288 0zM0 352l0 64 48 0 0-64L0 352zM64 512l0-48c-8.8 0-16-7.2-16-16L0 448c0 35.3 28.7 64 64 64zm256-48l0 48c35.3 0 64-28.7 64-64l-48 0c0 8.8-7.2 16-16 16zm64-112l-48 0 0 64 48 0 0-64zM96 464l0 48 80 0 0-48-80 0zm112 0l0 48 80 0 0-48-80 0z",
  81. VIEWBOX: "0 0 384 512"
  82. },
  83. ZIP: {
  84. PATH: "M64 464c-8.8 0-16-7.2-16-16L48 64c0-8.8 7.2-16 16-16l48 0c0 8.8 7.2 16 16 16l32 0c8.8 0 16-7.2 16-16l48 0 0 80c0 17.7 14.3 32 32 32l80 0 0 288c0 8.8-7.2 16-16 16L64 464zM64 0C28.7 0 0 28.7 0 64L0 448c0 35.3 28.7 64 64 64l256 0c35.3 0 64-28.7 64-64l0-293.5c0-17-6.7-33.3-18.7-45.3L274.7 18.7C262.7 6.7 246.5 0 229.5 0L64 0zm48 112c0 8.8 7.2 16 16 16l32 0c8.8 0 16-7.2 16-16s-7.2-16-16-16l-32 0c-8.8 0-16 7.2-16 16zm0 64c0 8.8 7.2 16 16 16l32 0c8.8 0 16-7.2 16-16s-7.2-16-16-16l-32 0c-8.8 0-16 7.2-16 16zm-6.3 71.8L82.1 335.9c-1.4 5.4-2.1 10.9-2.1 16.4c0 35.2 28.8 63.7 64 63.7s64-28.5 64-63.7c0-5.5-.7-11.1-2.1-16.4l-23.5-88.2c-3.7-14-16.4-23.8-30.9-23.8l-14.8 0c-14.5 0-27.2 9.7-30.9 23.8zM128 336l32 0c8.8 0 16 7.2 16 16s-7.2 16-16 16l-32 0c-8.8 0-16-7.2-16-16s7.2-16 16-16z",
  85. VIEWBOX: "0 0 384 512"
  86. },
  87. MEDIA_TYPE: {
  88. ALL: {
  89. PATH: "M256 48c-8.8 0-16 7.2-16 16l0 224c0 8.7 6.9 15.8 15.6 16l69.1-94.2c4.5-6.2 11.7-9.8 19.4-9.8s14.8 3.6 19.4 9.8L380 232.4l56-85.6c4.4-6.8 12-10.9 20.1-10.9s15.7 4.1 20.1 10.9L578.7 303.8c7.6-1.3 13.3-7.9 13.3-15.8l0-224c0-8.8-7.2-16-16-16L256 48zM192 64c0-35.3 28.7-64 64-64L576 0c35.3 0 64 28.7 64 64l0 224c0 35.3-28.7 64-64 64l-320 0c-35.3 0-64-28.7-64-64l0-224zm-56 64l24 0 0 48 0 88 0 112 0 8 0 80 192 0 0-80 48 0 0 80 48 0c8.8 0 16-7.2 16-16l0-64 48 0 0 64c0 35.3-28.7 64-64 64l-48 0-24 0-24 0-192 0-24 0-24 0-48 0c-35.3 0-64-28.7-64-64L0 192c0-35.3 28.7-64 64-64l48 0 24 0zm-24 48l-48 0c-8.8 0-16 7.2-16 16l0 48 64 0 0-64zm0 288l0-64-64 0 0 48c0 8.8 7.2 16 16 16l48 0zM48 352l64 0 0-64-64 0 0 64zM304 80a32 32 0 1 1 0 64 32 32 0 1 1 0-64z",
  90. VIEWBOX: "0 0 640 512"
  91. },
  92. IMAGE: {
  93. PATH: "M448 80c8.8 0 16 7.2 16 16l0 319.8-5-6.5-136-176c-4.5-5.9-11.6-9.3-19-9.3s-14.4 3.4-19 9.3L202 340.7l-30.5-42.7C167 291.7 159.8 288 152 288s-15 3.7-19.5 10.1l-80 112L48 416.3l0-.3L48 96c0-8.8 7.2-16 16-16l384 0zM64 32C28.7 32 0 60.7 0 96L0 416c0 35.3 28.7 64 64 64l384 0c35.3 0 64-28.7 64-64l0-320c0-35.3-28.7-64-64-64L64 32zm80 192a48 48 0 1 0 0-96 48 48 0 1 0 0 96z",
  94. VIEWBOX: "0 0 512 512"
  95. },
  96. VIDEO: {
  97. PATH: "M352 432l-192 0 0-112 0-40 192 0 0 40 0 112zm0-200l-192 0 0-40 0-112 192 0 0 112 0 40zM64 80l48 0 0 88-64 0 0-72c0-8.8 7.2-16 16-16zM48 216l64 0 0 80-64 0 0-80zm64 216l-48 0c-8.8 0-16-7.2-16-16l0-72 64 0 0 88zM400 168l0-88 48 0c8.8 0 16 7.2 16 16l0 72-64 0zm0 48l64 0 0 80-64 0 0-80zm0 128l64 0 0 72c0 8.8-7.2 16-16 16l-48 0 0-88zM448 32L64 32C28.7 32 0 60.7 0 96L0 416c0 35.3 28.7 64 64 64l384 0c35.3 0 64-28.7 64-64l0-320c0-35.3-28.7-64-64-64z",
  98. VIEWBOX: "0 0 512 512"
  99. },
  100. GIF: {
  101. PATH: "M512 80c8.8 0 16 7.2 16 16l0 320c0 8.8-7.2 16-16 16L64 432c-8.8 0-16-7.2-16-16L48 96c0-8.8 7.2-16 16-16l448 0zM64 32C28.7 32 0 60.7 0 96L0 416c0 35.3 28.7 64 64 64l448 0c35.3 0 64-28.7 64-64l0-320c0-35.3-28.7-64-64-64L64 32zM296 160c-13.3 0-24 10.7-24 24l0 144c0 13.3 10.7 24 24 24s24-10.7 24-24l0-144c0-13.3-10.7-24-24-24zm56 24l0 80 0 64c0 13.3 10.7 24 24 24s24-10.7 24-24l0-40 40 0c13.3 0 24-10.7 24-24s-10.7-24-24-24l-40 0 0-32 64 0c13.3 0 24-10.7 24-24s-10.7-24-24-24l-88 0c-13.3 0-24 10.7-24 24zM128 256c0-26.5 21.5-48 48-48c8 0 15.4 1.9 22 5.3c11.8 6.1 26.3 1.5 32.3-10.3s1.5-26.3-10.3-32.3c-13.2-6.8-28.2-10.7-44-10.7c-53 0-96 43-96 96s43 96 96 96c19.6 0 37.5-6.1 52.8-15.8c7-4.4 11.2-12.1 11.2-20.3l0-51.9c0-13.3-10.7-24-24-24l-32 0c-13.3 0-24 10.7-24 24s10.7 24 24 24l8 0 0 13.1c-5.3 1.9-10.6 2.9-16 2.9c-26.5 0-48-21.5-48-48z",
  102. VIEWBOX: "0 0 576 512"
  103. },
  104. MEDIA: {
  105. PATH: "M160 80l352 0c8.8 0 16 7.2 16 16l0 224c0 8.8-7.2 16-16 16l-21.2 0L388.1 178.9c-4.4-6.8-12-10.9-20.1-10.9s-15.7 4.1-20.1 10.9l-52.2 79.8-12.4-16.9c-4.5-6.2-11.7-9.8-19.4-9.8s-14.8 3.6-19.4 9.8L175.6 336 160 336c-8.8 0-16-7.2-16-16l0-224c0-8.8 7.2-16 16-16zM96 96l0 224c0 35.3 28.7 64 64 64l352 0c35.3 0 64-28.7 64-64l0-224c0-35.3-28.7-64-64-64L160 32c-35.3 0-64 28.7-64 64zM48 120c0-13.3-10.7-24-24-24S0 106.7 0 120L0 344c0 75.1 60.9 136 136 136l320 0c13.3 0 24-10.7 24-24s-10.7-24-24-24l-320 0c-48.6 0-88-39.4-88-88l0-224zm208 24a32 32 0 1 0 -64 0 32 32 0 1 0 64 0z",
  106. VIEWBOX: "0 0 576 512"
  107. },
  108. POST: {
  109. PATH: "M168 80c-13.3 0-24 10.7-24 24l0 304c0 8.4-1.4 16.5-4.1 24L440 432c13.3 0 24-10.7 24-24l0-304c0-13.3-10.7-24-24-24L168 80zM72 480c-39.8 0-72-32.2-72-72L0 112C0 98.7 10.7 88 24 88s24 10.7 24 24l0 296c0 13.3 10.7 24 24 24s24-10.7 24-24l0-304c0-39.8 32.2-72 72-72l272 0c39.8 0 72 32.2 72 72l0 304c0 39.8-32.2 72-72 72L72 480zM176 136c0-13.3 10.7-24 24-24l96 0c13.3 0 24 10.7 24 24l0 80c0 13.3-10.7 24-24 24l-96 0c-13.3 0-24-10.7-24-24l0-80zm200-24l32 0c13.3 0 24 10.7 24 24s-10.7 24-24 24l-32 0c-13.3 0-24-10.7-24-24s10.7-24 24-24zm0 80l32 0c13.3 0 24 10.7 24 24s-10.7 24-24 24l-32 0c-13.3 0-24-10.7-24-24s10.7-24 24-24zM200 272l208 0c13.3 0 24 10.7 24 24s-10.7 24-24 24l-208 0c-13.3 0-24-10.7-24-24s10.7-24 24-24zm0 80l208 0c13.3 0 24 10.7 24 24s-10.7 24-24 24l-208 0c-13.3 0-24-10.7-24-24s10.7-24 24-24z",
  110. VIEWBOX: "0 0 512 512"
  111. },
  112. TWEETS: {
  113. PATH: "M88.2 309.1c9.8-18.3 6.8-40.8-7.5-55.8C59.4 230.9 48 204 48 176c0-63.5 63.8-128 160-128s160 64.5 160 128s-63.8 128-160 128c-13.1 0-25.8-1.3-37.8-3.6c-10.4-2-21.2-.6-30.7 4.2c-4.1 2.1-8.3 4.1-12.6 6c-16 7.2-32.9 13.5-49.9 18c2.8-4.6 5.4-9.1 7.9-13.6c1.1-1.9 2.2-3.9 3.2-5.9zM208 352c114.9 0 208-78.8 208-176S322.9 0 208 0S0 78.8 0 176c0 41.8 17.2 80.1 45.9 110.3c-.9 1.7-1.9 3.5-2.8 5.1c-10.3 18.4-22.3 36.5-36.6 52.1c-6.6 7-8.3 17.2-4.6 25.9C5.8 378.3 14.4 384 24 384c43 0 86.5-13.3 122.7-29.7c4.8-2.2 9.6-4.5 14.2-6.8c15.1 3 30.9 4.5 47.1 4.5zM432 480c16.2 0 31.9-1.6 47.1-4.5c4.6 2.3 9.4 4.6 14.2 6.8C529.5 498.7 573 512 616 512c9.6 0 18.2-5.7 22-14.5c3.8-8.8 2-19-4.6-25.9c-14.2-15.6-26.2-33.7-36.6-52.1c-.9-1.7-1.9-3.4-2.8-5.1C622.8 384.1 640 345.8 640 304c0-94.4-87.9-171.5-198.2-175.8c4.1 15.2 6.2 31.2 6.2 47.8l0 .6c87.2 6.7 144 67.5 144 127.4c0 28-11.4 54.9-32.7 77.2c-14.3 15-17.3 37.6-7.5 55.8c1.1 2 2.2 4 3.2 5.9c2.5 4.5 5.2 9 7.9 13.6c-17-4.5-33.9-10.7-49.9-18c-4.3-1.9-8.5-3.9-12.6-6c-9.5-4.8-20.3-6.2-30.7-4.2c-12.1 2.4-24.8 3.6-37.8 3.6c-61.7 0-110-26.5-136.8-62.3c-16 5.4-32.8 9.4-50 11.8C279 439.8 350 480 432 480z",
  114. VIEWBOX: "0 0 640 512"
  115. },
  116. REPLIES: {
  117. PATH: "M224 240l96 0c66.2 0 122 44.7 138.8 105.5c3.3-12.4 5.2-26.2 5.2-41.5c0-70.7-57.3-128-128-128l-112 0-24 0c-13.3 0-24-10.7-24-24l0-24 0-28.1L55.9 208 176 316.1l0-28.1 0-24c0-13.3 10.7-24 24-24l24 0zm0 48l0 48 0 16c0 12.6-7.4 24.1-19 29.2s-25 3-34.4-5.4l-160-144C3.9 225.7 0 217.1 0 208s3.9-17.7 10.6-23.8l160-144c9.4-8.5 22.9-10.6 34.4-5.4s19 16.6 19 29.2l0 16 0 48 48 0 64 0c97.2 0 176 78.8 176 176c0 78-38.6 126.2-68.7 152.1c-4.1 3.5-8.1 6.6-11.7 9.3c-3.2 2.4-6.2 4.4-8.9 6.2c-4.5 3-8.3 5.1-10.8 6.5c-2.5 1.4-5.3 1.9-8.1 1.9c-10.9 0-19.7-8.9-19.7-19.7c0-6.8 3.6-13.2 8.3-18.1c.5-.5 .9-.9 1.4-1.4c2.4-2.3 5.1-5.1 7.7-8.6c1.7-2.3 3.4-5 5-7.9c5.3-9.7 9.5-22.9 9.5-40.2c0-53-43-96-96-96l-48 0-48 0z",
  118. VIEWBOX: "0 0 512 512"
  119. }
  120. }
  121. }
  122.  
  123. const defaultSettings = {
  124. patreonAuth: "",
  125. authToken: "",
  126. batchEnabled: false,
  127. autoBatchEnabled: false,
  128. batchSize: 100,
  129. startingBatch: 0,
  130. timelineType: "media",
  131. mediaType: "all",
  132. concurrentDownloads: 50,
  133. cacheDuration: 360,
  134. apiServer: "default",
  135. darkTheme: false,
  136. }
  137. const batchSizes = [25, 50, 100, 200]
  138. const cacheDurations = [60, 120, 180, 240, 300, 360, 720, 1440]
  139.  
  140. function getSettings() {
  141. return {
  142. patreonAuth: GM_getValue("patreonAuth", defaultSettings.patreonAuth),
  143. authToken: GM_getValue("authToken", defaultSettings.authToken),
  144. batchEnabled: GM_getValue("batchEnabled", defaultSettings.batchEnabled),
  145. autoBatchEnabled: GM_getValue("autoBatchEnabled", defaultSettings.autoBatchEnabled),
  146. batchSize: GM_getValue("batchSize", defaultSettings.batchSize),
  147. startingBatch: GM_getValue("startingBatch", defaultSettings.startingBatch),
  148. timelineType: GM_getValue("timelineType", defaultSettings.timelineType),
  149. mediaType: GM_getValue("mediaType", defaultSettings.mediaType),
  150. concurrentDownloads: GM_getValue("concurrentDownloads", defaultSettings.concurrentDownloads),
  151. cacheDuration: GM_getValue("cacheDuration", defaultSettings.cacheDuration),
  152. apiServer: GM_getValue("apiServer", defaultSettings.apiServer),
  153. darkTheme: GM_getValue("darkTheme", defaultSettings.darkTheme),
  154. }
  155. }
  156.  
  157. function saveSettings(settings) {
  158. GM_setValue("patreonAuth", settings.patreonAuth)
  159. GM_setValue("authToken", settings.authToken)
  160. GM_setValue("batchEnabled", settings.batchEnabled)
  161. GM_setValue("autoBatchEnabled", settings.autoBatchEnabled)
  162. GM_setValue("batchSize", settings.batchSize)
  163. GM_setValue("startingBatch", settings.startingBatch)
  164. GM_setValue("timelineType", settings.timelineType)
  165. GM_setValue("mediaType", settings.mediaType)
  166. GM_setValue("concurrentDownloads", settings.concurrentDownloads)
  167. GM_setValue("cacheDuration", settings.cacheDuration)
  168. GM_setValue("apiServer", settings.apiServer)
  169. GM_setValue("darkTheme", settings.darkTheme)
  170. }
  171.  
  172. function getServiceBaseUrl() {
  173. const settings = getSettings()
  174. return settings.apiServer === "default"
  175. ? API_URLS.DEFAULT
  176. : API_URLS.BACKUP
  177. }
  178.  
  179. function formatNumber(num) {
  180. return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
  181. }
  182.  
  183. const cacheManager = {
  184. set: (key, data, success = true) => {
  185. if (!success) return;
  186.  
  187. const settings = getSettings()
  188. const cacheItem = {
  189. data: data,
  190. timestamp: Date.now(),
  191. expiry: Date.now() + settings.cacheDuration * 60 * 1000,
  192. }
  193. localStorage.setItem(`twitter_dl_${key}`, JSON.stringify(cacheItem))
  194. },
  195.  
  196. get: (key) => {
  197. const cacheItem = localStorage.getItem(`twitter_dl_${key}`)
  198. if (!cacheItem) return null
  199.  
  200. try {
  201. const parsed = JSON.parse(cacheItem)
  202. if (Date.now() > parsed.expiry) {
  203. localStorage.removeItem(`twitter_dl_${key}`)
  204. return null
  205. }
  206. return parsed.data
  207. } catch (e) {
  208. localStorage.removeItem(`twitter_dl_${key}`)
  209. return null
  210. }
  211. },
  212.  
  213. clear: () => {
  214. const keysToRemove = []
  215. for (let i = 0; i < localStorage.length; i++) {
  216. const key = localStorage.key(i)
  217. if (key.startsWith("twitter_dl_")) {
  218. keysToRemove.push(key)
  219. }
  220. }
  221.  
  222. keysToRemove.forEach((key) => localStorage.removeItem(key))
  223. },
  224. }
  225.  
  226. function createDownloadIcon() {
  227. const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg")
  228. svg.setAttribute("xmlns", "http://www.w3.org/2000/svg")
  229. svg.setAttribute("viewBox", ICONS.DOWNLOAD.VIEWBOX)
  230. svg.setAttribute("width", "18")
  231. svg.setAttribute("height", "18")
  232. svg.style.verticalAlign = "middle"
  233. svg.style.cursor = "pointer"
  234.  
  235. const defs = document.createElementNS("http://www.w3.org/2000/svg", "defs")
  236. const style = document.createElementNS("http://www.w3.org/2000/svg", "style")
  237. style.textContent = ".fa-secondary{opacity:.4}"
  238. defs.appendChild(style)
  239. svg.appendChild(defs)
  240.  
  241. const secondaryPath = document.createElementNS("http://www.w3.org/2000/svg", "path")
  242. secondaryPath.setAttribute("class", "fa-secondary")
  243. secondaryPath.setAttribute("fill", "currentColor")
  244. secondaryPath.setAttribute("d", ICONS.DOWNLOAD.SECONDARY_PATH)
  245. svg.appendChild(secondaryPath)
  246.  
  247. const primaryPath = document.createElementNS("http://www.w3.org/2000/svg", "path")
  248. primaryPath.setAttribute("class", "fa-primary")
  249. primaryPath.setAttribute("fill", "currentColor")
  250. primaryPath.setAttribute("d", ICONS.DOWNLOAD.PRIMARY_PATH)
  251. svg.appendChild(primaryPath)
  252.  
  253. return svg
  254. }
  255.  
  256. function createPatreonIcon() {
  257. const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg")
  258. svg.setAttribute("xmlns", "http://www.w3.org/2000/svg")
  259. svg.setAttribute("viewBox", ICONS.PATREON.VIEWBOX)
  260. svg.setAttribute("width", "18")
  261. svg.setAttribute("height", "18")
  262. svg.style.verticalAlign = "middle"
  263. svg.style.marginRight = "8px"
  264.  
  265. const path = document.createElementNS("http://www.w3.org/2000/svg", "path")
  266. path.setAttribute("fill", "currentColor")
  267. path.setAttribute("d", ICONS.PATREON.PATH)
  268. svg.appendChild(path)
  269.  
  270. return svg
  271. }
  272.  
  273. function createInfoIcon() {
  274. const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg")
  275. svg.setAttribute("xmlns", "http://www.w3.org/2000/svg")
  276. svg.setAttribute("viewBox", ICONS.INFO.VIEWBOX)
  277. svg.setAttribute("width", "16")
  278. svg.setAttribute("height", "16")
  279. svg.style.marginLeft = "8px"
  280. svg.style.cursor = "pointer"
  281. svg.style.color = "#64748b"
  282. svg.style.transition = "color 0.2s ease"
  283.  
  284. const path = document.createElementNS("http://www.w3.org/2000/svg", "path")
  285. path.setAttribute("fill", "currentColor")
  286. path.setAttribute("d", ICONS.INFO.PATH)
  287. svg.appendChild(path)
  288.  
  289. svg.addEventListener("mouseenter", () => {
  290. svg.style.color = "#0ea5e9"
  291. })
  292.  
  293. svg.addEventListener("mouseleave", () => {
  294. svg.style.color = "#64748b"
  295. })
  296.  
  297. return svg
  298. }
  299.  
  300. function createInfoTooltip(message) {
  301. let activeTooltip = null
  302.  
  303. function showTooltip(e) {
  304. if (activeTooltip) {
  305. document.body.removeChild(activeTooltip)
  306. }
  307.  
  308. const tooltip = document.createElement("div")
  309. tooltip.textContent = message
  310. tooltip.style.cssText = `
  311. position: fixed;
  312. background-color: #1f2937;
  313. color: white;
  314. padding: 8px 12px;
  315. border-radius: 6px;
  316. font-size: 12px;
  317. line-height: 1.4;
  318. max-width: 300px;
  319. z-index: 10003;
  320. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  321. pointer-events: none;
  322. white-space: normal;
  323. word-wrap: break-word;
  324. `
  325.  
  326. document.body.appendChild(tooltip)
  327. activeTooltip = tooltip
  328.  
  329. const rect = e.target.getBoundingClientRect()
  330. const tooltipRect = tooltip.getBoundingClientRect()
  331.  
  332. let top = rect.bottom + 8
  333. let left = rect.left + (rect.width / 2) - (tooltipRect.width / 2)
  334.  
  335. if (left < 8) left = 8
  336. if (left + tooltipRect.width > window.innerWidth - 8) {
  337. left = window.innerWidth - tooltipRect.width - 8
  338. }
  339. if (top + tooltipRect.height > window.innerHeight - 8) {
  340. top = rect.top - tooltipRect.height - 8
  341. }
  342.  
  343. tooltip.style.top = top + "px"
  344. tooltip.style.left = left + "px"
  345. }
  346.  
  347. function hideTooltip() {
  348. if (activeTooltip) {
  349. document.body.removeChild(activeTooltip)
  350. activeTooltip = null
  351. }
  352. }
  353.  
  354. return { showTooltip, hideTooltip }
  355. }
  356.  
  357. function createAccountIcon(isDarkTheme = false) {
  358. const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg")
  359. svg.setAttribute("xmlns", "http://www.w3.org/2000/svg")
  360. svg.setAttribute("viewBox", ICONS.ACCOUNT.VIEWBOX)
  361. svg.setAttribute("width", "12")
  362. svg.setAttribute("height", "12")
  363. svg.style.marginRight = "6px"
  364. svg.style.color = isDarkTheme ? "#ffffff" : "#64748b"
  365. svg.style.verticalAlign = "middle"
  366. svg.style.display = "inline-block"
  367.  
  368. const path = document.createElementNS("http://www.w3.org/2000/svg", "path")
  369. path.setAttribute("fill", "currentColor")
  370. path.setAttribute("d", ICONS.ACCOUNT.PATH)
  371. svg.appendChild(path)
  372.  
  373. return svg
  374. }
  375.  
  376. function createTotalItemsIcon(isDarkTheme = false) {
  377. const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg")
  378. svg.setAttribute("xmlns", "http://www.w3.org/2000/svg")
  379. svg.setAttribute("viewBox", ICONS.TOTAL.VIEWBOX)
  380. svg.setAttribute("width", "12")
  381. svg.setAttribute("height", "12")
  382. svg.style.marginRight = "6px"
  383. svg.style.color = isDarkTheme ? "#ffffff" : "#64748b"
  384. svg.style.verticalAlign = "middle"
  385. svg.style.display = "inline-block"
  386.  
  387. const path = document.createElementNS("http://www.w3.org/2000/svg", "path")
  388. path.setAttribute("fill", "currentColor")
  389. path.setAttribute("d", ICONS.TOTAL.PATH)
  390. svg.appendChild(path)
  391.  
  392. return svg
  393. }
  394.  
  395. function createCurrentBatchIcon(isDarkTheme = false) {
  396. const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg")
  397. svg.setAttribute("xmlns", "http://www.w3.org/2000/svg")
  398. svg.setAttribute("viewBox", ICONS.BATCH.VIEWBOX)
  399. svg.setAttribute("width", "12")
  400. svg.setAttribute("height", "12")
  401. svg.style.marginRight = "6px"
  402. svg.style.color = isDarkTheme ? "#ffffff" : "#64748b"
  403. svg.style.verticalAlign = "middle"
  404. svg.style.display = "inline-block"
  405.  
  406. const path = document.createElementNS("http://www.w3.org/2000/svg", "path")
  407. path.setAttribute("fill", "currentColor")
  408. path.setAttribute("d", ICONS.BATCH.PATH)
  409. svg.appendChild(path)
  410.  
  411. return svg
  412. }
  413.  
  414. function createTotalZipIcon(isDarkTheme = false) {
  415. const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg")
  416. svg.setAttribute("xmlns", "http://www.w3.org/2000/svg")
  417. svg.setAttribute("viewBox", ICONS.ZIP.VIEWBOX)
  418. svg.setAttribute("width", "12")
  419. svg.setAttribute("height", "12")
  420. svg.style.marginRight = "6px"
  421. svg.style.color = isDarkTheme ? "#ffffff" : "#64748b"
  422. svg.style.verticalAlign = "middle"
  423. svg.style.display = "inline-block"
  424.  
  425. const path = document.createElementNS("http://www.w3.org/2000/svg", "path")
  426. path.setAttribute("fill", "currentColor")
  427. path.setAttribute("d", ICONS.ZIP.PATH)
  428. svg.appendChild(path)
  429.  
  430. return svg
  431. }
  432.  
  433. function createMediaTypeIcon(mediaType, isDarkTheme = false) {
  434. let iconData
  435. switch (mediaType) {
  436. case 'image':
  437. iconData = ICONS.MEDIA_TYPE.IMAGE
  438. break
  439. case 'video':
  440. iconData = ICONS.MEDIA_TYPE.VIDEO
  441. break
  442. case 'gif':
  443. iconData = ICONS.MEDIA_TYPE.GIF
  444. break
  445. default:
  446. iconData = ICONS.MEDIA_TYPE.ALL
  447. }
  448.  
  449. const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg")
  450. svg.setAttribute("xmlns", "http://www.w3.org/2000/svg")
  451. svg.setAttribute("viewBox", iconData.VIEWBOX)
  452. svg.setAttribute("width", "12")
  453. svg.setAttribute("height", "12")
  454. svg.style.marginRight = "6px"
  455. svg.style.color = isDarkTheme ? "#ffffff" : "#64748b"
  456. svg.style.verticalAlign = "middle"
  457. svg.style.display = "inline-block"
  458.  
  459. const path = document.createElementNS("http://www.w3.org/2000/svg", "path")
  460. path.setAttribute("fill", "currentColor")
  461. path.setAttribute("d", iconData.PATH)
  462. svg.appendChild(path)
  463.  
  464. return svg
  465. }
  466.  
  467. function createTimelineTypeIcon(timelineType, isDarkTheme = false) {
  468. let iconData
  469. switch (timelineType) {
  470. case 'media':
  471. iconData = ICONS.MEDIA_TYPE.MEDIA
  472. break
  473. case 'timeline':
  474. iconData = ICONS.MEDIA_TYPE.POST
  475. break
  476. case 'tweets':
  477. iconData = ICONS.MEDIA_TYPE.TWEETS
  478. break
  479. case 'with_replies':
  480. iconData = ICONS.MEDIA_TYPE.REPLIES
  481. break
  482. default:
  483. iconData = ICONS.MEDIA_TYPE.MEDIA
  484. }
  485.  
  486. const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg")
  487. svg.setAttribute("xmlns", "http://www.w3.org/2000/svg")
  488. svg.setAttribute("viewBox", iconData.VIEWBOX)
  489. svg.setAttribute("width", "16")
  490. svg.setAttribute("height", "16")
  491. svg.style.marginRight = "6px"
  492. svg.style.color = isDarkTheme ? "#ffffff" : "#64748b"
  493. svg.style.verticalAlign = "middle"
  494. svg.style.display = "inline-block"
  495.  
  496. const path = document.createElementNS("http://www.w3.org/2000/svg", "path")
  497. path.setAttribute("fill", "currentColor")
  498. path.setAttribute("d", iconData.PATH)
  499. svg.appendChild(path)
  500.  
  501. return svg
  502. }
  503.  
  504. function createAuthTokenPopup() {
  505. const settings = getSettings()
  506. const overlay = document.createElement("div")
  507. overlay.style.cssText = `
  508. position: fixed;
  509. top: 0;
  510. left: 0;
  511. width: 100%;
  512. height: 100%;
  513. background-color: rgba(0, 0, 0, 0.35);
  514. backdrop-filter: blur(2.5px);
  515. display: flex;
  516. justify-content: center;
  517. align-items: center;
  518. z-index: 10001;
  519. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  520. `
  521.  
  522. const popup = document.createElement("div")
  523. popup.style.cssText = `
  524. background-color: ${settings.darkTheme ? "#1f2937" : "#ffffff"};
  525. color: ${settings.darkTheme ? "#f1f5f9" : "#0f172a"};
  526. border-radius: 16px;
  527. width: 300px;
  528. max-width: 90%;
  529. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  530. overflow: hidden;
  531. `
  532.  
  533. const header = document.createElement("div")
  534. header.style.cssText = `
  535. padding: 16px;
  536. border-bottom: 1px solid ${settings.darkTheme ? "#374151" : "#e2e8f0"};
  537. font-weight: bold;
  538. font-size: 16px;
  539. text-align: center;
  540. background-color: ${settings.darkTheme ? "#374151" : "#f8fafc"};
  541. `
  542. header.textContent = "Authentication Required"
  543.  
  544. const content = document.createElement("div")
  545. content.style.cssText = `
  546. padding: 16px;
  547. text-align: center;
  548. `
  549.  
  550. const authLink = document.createElement("a")
  551. authLink.href = "https://www.patreon.com/posts/127206894"
  552. authLink.target = "_blank"
  553. authLink.textContent = "How to Obtain Auth Token"
  554. authLink.style.cssText = `
  555. color: #0ea5e9;
  556. text-decoration: none;
  557. cursor: pointer;
  558. `
  559. content.appendChild(authLink)
  560.  
  561. const buttonContainer = document.createElement("div")
  562. buttonContainer.style.cssText = `
  563. padding: 16px;
  564. display: flex;
  565. justify-content: center;
  566. border-top: 1px solid ${settings.darkTheme ? "#374151" : "#e2e8f0"};
  567. `
  568.  
  569. const okButton = document.createElement("button")
  570. okButton.style.cssText = `
  571. background-color: #0ea5e9;
  572. color: white;
  573. border: none;
  574. border-radius: 6px;
  575. padding: 8px 24px;
  576. font-weight: bold;
  577. cursor: pointer;
  578. transition: background-color 0.2s;
  579. `
  580. okButton.textContent = "OK"
  581. okButton.addEventListener("mouseenter", () => {
  582. okButton.style.backgroundColor = "#0284c7"
  583. })
  584. okButton.addEventListener("mouseleave", () => {
  585. okButton.style.backgroundColor = "#0ea5e9"
  586. })
  587. okButton.onclick = () => {
  588. document.body.removeChild(overlay)
  589. }
  590.  
  591. buttonContainer.appendChild(okButton)
  592. popup.appendChild(header)
  593. popup.appendChild(content)
  594. popup.appendChild(buttonContainer)
  595. overlay.appendChild(popup)
  596. document.body.appendChild(overlay)
  597. return overlay
  598. }
  599.  
  600. function createPatreonAuthPopup() {
  601. const settings = getSettings()
  602. const overlay = document.createElement("div")
  603. overlay.style.cssText = `
  604. position: fixed;
  605. top: 0;
  606. left: 0;
  607. width: 100%;
  608. height: 100%;
  609. background-color: rgba(0, 0, 0, 0.35);
  610. backdrop-filter: blur(2.5px);
  611. display: flex;
  612. justify-content: center;
  613. align-items: center;
  614. z-index: 10001;
  615. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  616. `
  617.  
  618. const popup = document.createElement("div")
  619. popup.style.cssText = `
  620. background-color: ${settings.darkTheme ? "#1f2937" : "#ffffff"};
  621. color: ${settings.darkTheme ? "#f1f5f9" : "#0f172a"};
  622. border-radius: 16px;
  623. width: 320px;
  624. max-width: 90%;
  625. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  626. overflow: hidden;
  627. `
  628.  
  629. const header = document.createElement("div")
  630. header.style.cssText = `
  631. padding: 16px;
  632. border-bottom: 1px solid ${settings.darkTheme ? "#374151" : "#e2e8f0"};
  633. font-weight: bold;
  634. font-size: 16px;
  635. text-align: center;
  636. background-color: ${settings.darkTheme ? "#374151" : "#f8fafc"};
  637. `
  638. header.textContent = "Patreon Authentication Required"
  639.  
  640. const content = document.createElement("div")
  641. content.style.cssText = `
  642. padding: 16px;
  643. text-align: center;
  644. `
  645.  
  646. const message = document.createElement("p")
  647. message.style.cssText = `
  648. margin-bottom: 16px;
  649. line-height: 1.5;
  650. `
  651. message.textContent = "Please enter your Patreon authentication code. This feature requires a paid membership to access."
  652. content.appendChild(message)
  653.  
  654. const patreonButton = document.createElement("a")
  655. patreonButton.href = "https://www.patreon.com/exyezed"
  656. patreonButton.target = "_blank"
  657. patreonButton.style.cssText = `
  658. display: flex;
  659. align-items: center;
  660. justify-content: center;
  661. background-color: ${settings.darkTheme ? "#374151" : "#f1f5f9"};
  662. color: ${settings.darkTheme ? "#f1f5f9" : "#0f172a"};
  663. text-decoration: none;
  664. padding: 10px 16px;
  665. border-radius: 8px;
  666. margin-top: 8px;
  667. transition: background-color 0.2s;
  668. `
  669. patreonButton.innerHTML = createPatreonIcon().outerHTML + "Join Patreon Membership"
  670. patreonButton.addEventListener("mouseenter", () => {
  671. patreonButton.style.backgroundColor = settings.darkTheme ? "#4b5563" : "#e2e8f0"
  672. })
  673. patreonButton.addEventListener("mouseleave", () => {
  674. patreonButton.style.backgroundColor = settings.darkTheme ? "#374151" : "#f1f5f9"
  675. })
  676. content.appendChild(patreonButton)
  677.  
  678. const buttonContainer = document.createElement("div")
  679. buttonContainer.style.cssText = `
  680. padding: 16px;
  681. display: flex;
  682. justify-content: center;
  683. border-top: 1px solid ${settings.darkTheme ? "#374151" : "#e2e8f0"};
  684. `
  685.  
  686. const okButton = document.createElement("button")
  687. okButton.style.cssText = `
  688. background-color: #0ea5e9;
  689. color: white;
  690. border: none;
  691. border-radius: 6px;
  692. padding: 8px 24px;
  693. font-weight: bold;
  694. cursor: pointer;
  695. transition: background-color 0.2s;
  696. `
  697. okButton.textContent = "OK"
  698. okButton.addEventListener("mouseenter", () => {
  699. okButton.style.backgroundColor = "#0284c7"
  700. })
  701. okButton.addEventListener("mouseleave", () => {
  702. okButton.style.backgroundColor = "#0ea5e9"
  703. })
  704. okButton.onclick = () => {
  705. document.body.removeChild(overlay)
  706. }
  707.  
  708. buttonContainer.appendChild(okButton)
  709. popup.appendChild(header)
  710. popup.appendChild(content)
  711. popup.appendChild(buttonContainer)
  712. overlay.appendChild(popup)
  713.  
  714. document.body.appendChild(overlay)
  715. return overlay }
  716.  
  717. function createInfoDialog(message, title = "Information") {
  718. const settings = getSettings()
  719. const overlay = document.createElement("div")
  720. overlay.style.cssText = `
  721. position: fixed;
  722. top: 0;
  723. left: 0;
  724. width: 100%;
  725. height: 100%;
  726. background-color: rgba(0, 0, 0, 0.35);
  727. backdrop-filter: blur(2.5px);
  728. display: flex;
  729. justify-content: center;
  730. align-items: center;
  731. z-index: 10001;
  732. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  733. `
  734.  
  735. const dialog = document.createElement("div")
  736. dialog.style.cssText = `
  737. background-color: ${settings.darkTheme ? "#1f2937" : "#ffffff"};
  738. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  739. border-radius: 16px;
  740. width: 300px;
  741. max-width: 90%;
  742. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  743. overflow: hidden;
  744. `
  745.  
  746. const header = document.createElement("div")
  747. header.style.cssText = `
  748. padding: 16px;
  749. border-bottom: 1px solid ${settings.darkTheme ? "#374151" : "#e2e8f0"};
  750. font-weight: bold;
  751. font-size: 16px;
  752. text-align: center;
  753. background-color: ${settings.darkTheme ? "#374151" : "#f8fafc"};
  754. `
  755. header.textContent = title
  756.  
  757. const content = document.createElement("div")
  758. content.style.cssText = `
  759. padding: 20px 16px;
  760. text-align: center;
  761. line-height: 1.5;
  762. `
  763. content.textContent = message
  764.  
  765. const buttonContainer = document.createElement("div")
  766. buttonContainer.style.cssText = `
  767. padding: 16px;
  768. display: flex;
  769. justify-content: center;
  770. border-top: 1px solid ${settings.darkTheme ? "#374151" : "#e2e8f0"};
  771. `
  772.  
  773. const okButton = document.createElement("button")
  774. okButton.style.cssText = `
  775. background-color: #22c55e;
  776. color: white;
  777. border: none;
  778. border-radius: 6px;
  779. padding: 8px 24px;
  780. font-weight: bold;
  781. cursor: pointer;
  782. transition: background-color 0.2s;
  783. `
  784. okButton.textContent = "OK"
  785. okButton.addEventListener("mouseenter", () => {
  786. okButton.style.backgroundColor = "#16a34a"
  787. })
  788. okButton.addEventListener("mouseleave", () => {
  789. okButton.style.backgroundColor = "#22c55e"
  790. })
  791. okButton.onclick = () => {
  792. document.body.removeChild(overlay)
  793. }
  794.  
  795. buttonContainer.appendChild(okButton)
  796. dialog.appendChild(header)
  797. dialog.appendChild(content)
  798. dialog.appendChild(buttonContainer)
  799. overlay.appendChild(dialog)
  800.  
  801. document.body.appendChild(overlay)
  802. return overlay
  803. }
  804.  
  805. function createConfirmDialog(message, onConfirm, onCancel) {
  806. const settings = getSettings()
  807. const overlay = document.createElement("div")
  808. overlay.style.cssText = `
  809. position: fixed;
  810. top: 0;
  811. left: 0;
  812. width: 100%;
  813. height: 100%;
  814. background-color: rgba(0, 0, 0, 0.35);
  815. backdrop-filter: blur(2.5px);
  816. display: flex;
  817. justify-content: center;
  818. align-items: center;
  819. z-index: 10001;
  820. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  821. `
  822.  
  823. const dialog = document.createElement("div")
  824. dialog.style.cssText = `
  825. background-color: ${settings.darkTheme ? "#1f2937" : "#ffffff"};
  826. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  827. border-radius: 16px;
  828. width: 300px;
  829. max-width: 90%;
  830. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  831. overflow: hidden;
  832. `
  833.  
  834. const header = document.createElement("div")
  835. header.style.cssText = `
  836. padding: 16px;
  837. border-bottom: 1px solid ${settings.darkTheme ? "#374151" : "#e2e8f0"};
  838. font-weight: bold;
  839. font-size: 16px;
  840. text-align: center;
  841. background-color: ${settings.darkTheme ? "#374151" : "#f8fafc"};
  842. `
  843. header.textContent = "Confirmation"
  844.  
  845. const content = document.createElement("div")
  846. content.style.cssText = `
  847. padding: 16px;
  848. text-align: center;
  849. `
  850. content.textContent = message
  851.  
  852. const buttons = document.createElement("div")
  853. buttons.style.cssText = `
  854. display: flex;
  855. padding: 16px;
  856. border-top: 1px solid ${settings.darkTheme ? "#374151" : "#e2e8f0"};
  857. `
  858.  
  859. const cancelButton = document.createElement("button")
  860. cancelButton.style.cssText = `
  861. flex: 1;
  862. background-color: ${settings.darkTheme ? "#374151" : "#94a3b8"};
  863. color: white;
  864. border: none;
  865. border-radius: 6px;
  866. padding: 8px 16px;
  867. margin-right: 8px;
  868. font-weight: bold;
  869. cursor: pointer;
  870. text-align: center;
  871. transition: background-color 0.2s;
  872. `
  873. cancelButton.textContent = "No"
  874. cancelButton.addEventListener("mouseenter", () => {
  875. cancelButton.style.backgroundColor = settings.darkTheme ? "#4b5563" : "#64748b"
  876. })
  877. cancelButton.addEventListener("mouseleave", () => {
  878. cancelButton.style.backgroundColor = settings.darkTheme ? "#374151" : "#94a3b8"
  879. })
  880. cancelButton.onclick = () => {
  881. document.body.removeChild(overlay)
  882. if (onCancel) onCancel()
  883. }
  884.  
  885. const confirmButton = document.createElement("button")
  886. confirmButton.style.cssText = `
  887. flex: 1;
  888. background-color: #ef4444;
  889. color: white;
  890. border: none;
  891. border-radius: 6px;
  892. padding: 8px 16px;
  893. font-weight: bold;
  894. cursor: pointer;
  895. text-align: center;
  896. transition: background-color 0.2s;
  897. `
  898. confirmButton.textContent = "Yes"
  899. confirmButton.addEventListener("mouseenter", () => {
  900. confirmButton.style.backgroundColor = "#dc2626"
  901. })
  902. confirmButton.addEventListener("mouseleave", () => {
  903. confirmButton.style.backgroundColor = "#ef4444"
  904. })
  905. confirmButton.onclick = () => {
  906. document.body.removeChild(overlay)
  907. if (onConfirm) onConfirm()
  908. }
  909.  
  910. buttons.appendChild(cancelButton)
  911. buttons.appendChild(confirmButton)
  912.  
  913. dialog.appendChild(header)
  914. dialog.appendChild(content)
  915. dialog.appendChild(buttons)
  916. overlay.appendChild(dialog)
  917.  
  918. document.body.appendChild(overlay)
  919. }
  920.  
  921. function formatDate(dateString) {
  922. const date = new Date(dateString)
  923. const year = date.getFullYear()
  924. const month = String(date.getMonth() + 1).padStart(2, "0")
  925. const day = String(date.getDate()).padStart(2, "0")
  926. const hours = String(date.getHours()).padStart(2, "0")
  927. const minutes = String(date.getMinutes()).padStart(2, "0")
  928. const seconds = String(date.getSeconds()).padStart(2, "0")
  929.  
  930. return `${year}${month}${day}_${hours}${minutes}${seconds}`
  931. }
  932.  
  933. function getCurrentTimestamp() {
  934. const now = new Date()
  935. const year = now.getFullYear()
  936. const month = String(now.getMonth() + 1).padStart(2, "0")
  937. const day = String(now.getDate()).padStart(2, "0")
  938. const hours = String(now.getHours()).padStart(2, "0")
  939. const minutes = String(now.getMinutes()).padStart(2, "0")
  940. const seconds = String(now.getSeconds()).padStart(2, "0")
  941.  
  942. return `${year}${month}${day}_${hours}${minutes}${seconds}`
  943. }
  944.  
  945. function fetchData(url) {
  946. return new Promise((resolve, reject) => {
  947. GM_xmlhttpRequest({
  948. method: "GET",
  949. url: url,
  950. responseType: "json",
  951. onload: (response) => {
  952. if (response.status >= 200 && response.status < 300) {
  953. resolve(response.response)
  954. } else {
  955. reject(new Error(`Request failed with status ${response.status}`))
  956. }
  957. },
  958. onerror: (error) => {
  959. reject(new Error(`Network error: ${error?.message || "Unknown error"}`))
  960. },
  961. ontimeout: () => {
  962. reject(new Error("Request timed out"))
  963. }
  964. })
  965. })
  966. }
  967.  
  968. function fetchBinary(url) {
  969. return new Promise((resolve, reject) => {
  970. GM_xmlhttpRequest({
  971. method: "GET",
  972. url: url,
  973. responseType: "blob",
  974. onload: (response) => {
  975. if (response.status >= 200 && response.status < 300) {
  976. resolve(response.response)
  977. } else {
  978. reject(new Error(`Request failed with status ${response.status}`))
  979. }
  980. },
  981. onerror: () => {
  982. reject(new Error("Network error"))
  983. },
  984. })
  985. })
  986. }
  987.  
  988. function getMediaTypeLabel(mediaType) {
  989. switch (mediaType) {
  990. case "image":
  991. return "Image"
  992. case "video":
  993. return "Video"
  994. case "gif":
  995. return "GIF"
  996. default:
  997. return "Media"
  998. }
  999. }
  1000.  
  1001. function createToggleSwitch(options, selectedValue, onChange) {
  1002. const settings = getSettings()
  1003. const toggleWrapper = document.createElement("div")
  1004. toggleWrapper.style.cssText = `
  1005. position: relative;
  1006. height: 40px;
  1007. background-color: ${settings.darkTheme ? "#374151" : "#f1f5f9"};
  1008. border-radius: 8px;
  1009. padding: 0;
  1010. cursor: pointer;
  1011. width: 100%;
  1012. margin-bottom: 16px;
  1013. overflow: hidden;
  1014. `
  1015.  
  1016. const toggleSlider = document.createElement("div")
  1017. toggleSlider.style.cssText = `
  1018. position: absolute;
  1019. height: 100%;
  1020. background-color: #0ea5e9;
  1021. border-radius: 8px;
  1022. transition: transform 0.3s ease, width 0.3s ease;
  1023. z-index: 1;
  1024. `
  1025.  
  1026. const optionsContainer = document.createElement("div")
  1027. optionsContainer.style.cssText = `
  1028. position: relative;
  1029. display: flex;
  1030. height: 100%;
  1031. z-index: 2;
  1032. width: 100%;
  1033. `
  1034.  
  1035. const selectedIndex = options.findIndex((option) => option.value === selectedValue)
  1036. const optionWidth = 100 / options.length;
  1037. toggleSlider.style.width = `${optionWidth}%`;
  1038. toggleSlider.style.transform = `translateX(${selectedIndex * 100}%)`;options.forEach((option, index) => {
  1039. const optionElement = document.createElement("div");
  1040. optionElement.style.cssText = `
  1041. flex: 1;
  1042. display: flex;
  1043. align-items: center;
  1044. justify-content: center;
  1045. font-size: 14px;
  1046. transition: color 0.3s ease;
  1047. color: ${option.value === selectedValue ? "white" : "#64748b"};
  1048. cursor: pointer;
  1049. user-select: none;
  1050. text-align: center;
  1051. height: 100%;
  1052. padding: 0 4px;
  1053. `;
  1054.  
  1055. if (option.icon) {
  1056. const iconContainer = document.createElement("span")
  1057. iconContainer.style.cssText = `
  1058. display: flex;
  1059. align-items: center;
  1060. justify-content: center;
  1061. margin-right: 6px;
  1062. `
  1063.  
  1064. const iconClone = option.icon.cloneNode(true)
  1065.  
  1066. const paths = iconClone.querySelectorAll("path")
  1067. paths.forEach((path) => {
  1068. path.setAttribute("fill", option.value === selectedValue ? "white" : "#64748b")
  1069. })
  1070.  
  1071. iconContainer.appendChild(iconClone)
  1072. optionElement.appendChild(iconContainer)
  1073. }
  1074.  
  1075. const text = document.createElement("span")
  1076. text.textContent = option.label
  1077. text.style.cssText = `
  1078. display: inline-block;
  1079. text-align: center;
  1080. `
  1081. optionElement.appendChild(text)
  1082.  
  1083. optionElement.addEventListener("click", (e) => {
  1084. e.stopPropagation()
  1085. onChange(option.value)
  1086.  
  1087. toggleSlider.style.transform = `translateX(${index * 100}%)`
  1088.  
  1089. optionsContainer.querySelectorAll("div").forEach((opt, i) => {
  1090. opt.style.color = i === index ? "white" : "#64748b"
  1091.  
  1092. const optIcon = opt.querySelector("svg")
  1093. if (optIcon) {
  1094. const optPaths = optIcon.querySelectorAll("path")
  1095. optPaths.forEach((path) => {
  1096. path.setAttribute("fill", i === index ? "white" : "#64748b")
  1097. })
  1098. }
  1099. })
  1100. })
  1101.  
  1102. optionsContainer.appendChild(optionElement)
  1103. })
  1104.  
  1105. toggleWrapper.appendChild(toggleSlider)
  1106. toggleWrapper.appendChild(optionsContainer)
  1107.  
  1108. return toggleWrapper
  1109. }
  1110.  
  1111. function createMediaTypeIcons() {
  1112. const allIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg")
  1113. allIcon.setAttribute("xmlns", "http://www.w3.org/2000/svg")
  1114. allIcon.setAttribute("viewBox", ICONS.MEDIA_TYPE.ALL.VIEWBOX)
  1115. allIcon.setAttribute("width", "16")
  1116. allIcon.setAttribute("height", "16")
  1117. allIcon.style.verticalAlign = "middle"
  1118.  
  1119. const allPath = document.createElementNS("http://www.w3.org/2000/svg", "path")
  1120. allPath.setAttribute("fill", "#64748b")
  1121. allPath.setAttribute("d", ICONS.MEDIA_TYPE.ALL.PATH)
  1122. allIcon.appendChild(allPath)
  1123.  
  1124. const imageIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg")
  1125. imageIcon.setAttribute("xmlns", "http://www.w3.org/2000/svg")
  1126. imageIcon.setAttribute("viewBox", ICONS.MEDIA_TYPE.IMAGE.VIEWBOX)
  1127. imageIcon.setAttribute("width", "16")
  1128. imageIcon.setAttribute("height", "16")
  1129. imageIcon.style.verticalAlign = "middle"
  1130.  
  1131. const imagePath = document.createElementNS("http://www.w3.org/2000/svg", "path")
  1132. imagePath.setAttribute("fill", "#64748b")
  1133. imagePath.setAttribute("d", ICONS.MEDIA_TYPE.IMAGE.PATH)
  1134. imageIcon.appendChild(imagePath)
  1135.  
  1136. const videoIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg")
  1137. videoIcon.setAttribute("xmlns", "http://www.w3.org/2000/svg")
  1138. videoIcon.setAttribute("viewBox", ICONS.MEDIA_TYPE.VIDEO.VIEWBOX)
  1139. videoIcon.setAttribute("width", "16")
  1140. videoIcon.setAttribute("height", "16")
  1141. videoIcon.style.verticalAlign = "middle"
  1142.  
  1143. const videoPath = document.createElementNS("http://www.w3.org/2000/svg", "path")
  1144. videoPath.setAttribute("fill", "#64748b")
  1145. videoPath.setAttribute("d", ICONS.MEDIA_TYPE.VIDEO.PATH)
  1146. videoIcon.appendChild(videoPath)
  1147.  
  1148. const gifIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg")
  1149. gifIcon.setAttribute("xmlns", "http://www.w3.org/2000/svg")
  1150. gifIcon.setAttribute("viewBox", ICONS.MEDIA_TYPE.GIF.VIEWBOX)
  1151. gifIcon.setAttribute("width", "16")
  1152. gifIcon.setAttribute("height", "16")
  1153. gifIcon.style.verticalAlign = "middle"
  1154.  
  1155. const gifPath = document.createElementNS("http://www.w3.org/2000/svg", "path")
  1156. gifPath.setAttribute("fill", "#64748b")
  1157. gifPath.setAttribute("d", ICONS.MEDIA_TYPE.GIF.PATH)
  1158. gifIcon.appendChild(gifPath)
  1159.  
  1160. return {
  1161. all: allIcon,
  1162. image: imageIcon,
  1163. video: videoIcon,
  1164. gif: gifIcon
  1165. }
  1166. }
  1167.  
  1168. function createSlider(options, selectedValue, onChange) {
  1169. const toggleOptions = options.map((option) => {
  1170. let label = option.toString()
  1171. if (typeof option === "number" && option >= 60 && option % 60 === 0) {
  1172. label = `${option / 60}h`
  1173. }
  1174. return { value: option, label: label }
  1175. })
  1176.  
  1177. return createToggleSwitch(toggleOptions, selectedValue, onChange)
  1178. }
  1179.  
  1180. function createModal(username) {
  1181. let autoBatchStarted = false
  1182. let autoBatchCancelled = false
  1183. const existingModal = document.getElementById("media-downloader-modal")
  1184. if (existingModal) {
  1185. existingModal.remove()
  1186. }
  1187.  
  1188. const settings = getSettings()
  1189.  
  1190. const modal = document.createElement("div")
  1191. modal.id = "media-downloader-modal"
  1192. modal.style.cssText = `
  1193. position: fixed;
  1194. top: 0;
  1195. left: 0;
  1196. width: 100%;
  1197. height: 100%;
  1198. background-color: rgba(0, 0, 0, 0.35);
  1199. backdrop-filter: blur(2.5px);
  1200. display: flex;
  1201. justify-content: center;
  1202. align-items: center;
  1203. z-index: 10000;
  1204. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  1205. `
  1206.  
  1207. const modalContent = document.createElement("div")
  1208. modalContent.style.cssText = `
  1209. background-color: ${settings.darkTheme ? "#1f2937" : "#ffffff"};
  1210. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  1211. border-radius: 16px;
  1212. width: 500px;
  1213. max-width: 90%;
  1214. max-height: 90vh;
  1215. overflow-y: auto;
  1216. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  1217. `
  1218.  
  1219. const header = document.createElement("div")
  1220. header.style.cssText = `
  1221. display: flex;
  1222. justify-content: space-between;
  1223. align-items: center;
  1224. padding: 16px;
  1225. border-bottom: 1px solid ${settings.darkTheme ? "#374151" : "#e2e8f0"};
  1226. `
  1227.  
  1228. const title = document.createElement("h2")
  1229. title.innerHTML = `Download ${getMediaTypeLabel(settings.mediaType)}: <span style="color: #0ea5e9">${username}</span>`
  1230. title.style.cssText = `
  1231. margin: 0;
  1232. font-size: 18px;
  1233. font-weight: bold;
  1234. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  1235. `
  1236.  
  1237. const closeButton = document.createElement("button")
  1238. closeButton.innerHTML = "&times;"
  1239. closeButton.style.cssText = `
  1240. background: none;
  1241. border: none;
  1242. color: ${settings.darkTheme ? "#f1f5f9" : "#0f172a"};
  1243. font-size: 24px;
  1244. cursor: pointer;
  1245. padding: 0;
  1246. line-height: 1;
  1247. transition: color 0.2s;
  1248. `
  1249. closeButton.addEventListener("mouseenter", () => {
  1250. closeButton.style.color = "#0ea5e9"
  1251. })
  1252. closeButton.addEventListener("mouseleave", () => {
  1253. closeButton.style.color = settings.darkTheme ? "#f1f5f9" : "#0f172a"
  1254. })
  1255. closeButton.onclick = () => modal.remove()
  1256.  
  1257. header.appendChild(title)
  1258. header.appendChild(closeButton)
  1259.  
  1260. const tabs = document.createElement("div")
  1261. tabs.style.cssText = `
  1262. display: flex;
  1263. border-bottom: 1px solid ${settings.darkTheme ? "#374151" : "#e2e8f0"};
  1264. `
  1265.  
  1266. const mainTab = document.createElement("div")
  1267. mainTab.textContent = "Main"
  1268. mainTab.className = "active-tab"
  1269. mainTab.style.cssText = `
  1270. padding: 12px 16px;
  1271. cursor: pointer;
  1272. flex: 1;
  1273. text-align: center;
  1274. border-bottom: 2px solid #0ea5e9;
  1275. color: ${settings.darkTheme ? "#f1f5f9" : "#0f172a"};
  1276. `
  1277.  
  1278. const settingsTab = document.createElement("div")
  1279. settingsTab.textContent = "Settings"
  1280. settingsTab.style.cssText = `
  1281. padding: 12px 16px;
  1282. cursor: pointer;
  1283. flex: 1;
  1284. text-align: center;
  1285. color: #64748b;
  1286. `
  1287.  
  1288. tabs.appendChild(mainTab)
  1289. tabs.appendChild(settingsTab)
  1290.  
  1291. const mainContent = document.createElement("div")
  1292. mainContent.style.cssText = `
  1293. padding: 16px;
  1294. `;
  1295. const settingsContent = document.createElement("div");
  1296. settingsContent.style.cssText = `
  1297. padding: 16px;
  1298. display: none;
  1299. `;
  1300.  
  1301. const fetchButton = document.createElement("button");
  1302. const mediaTypeLabelText = getMediaTypeLabel(settings.mediaType).toLowerCase();
  1303. const fetchIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
  1304. fetchIcon.setAttribute("xmlns", "http://www.w3.org/2000/svg");
  1305. fetchIcon.setAttribute("viewBox", ICONS.FETCH.VIEWBOX);
  1306. fetchIcon.setAttribute("width", "16");
  1307. fetchIcon.setAttribute("height", "16");
  1308. fetchIcon.style.marginRight = "8px";
  1309.  
  1310. const fetchPath = document.createElementNS("http://www.w3.org/2000/svg", "path");
  1311. fetchPath.setAttribute("fill", "currentColor");
  1312. fetchPath.setAttribute("d", ICONS.FETCH.PATH);
  1313. fetchIcon.appendChild(fetchPath);
  1314.  
  1315. const fetchButtonText = document.createElement("span");
  1316. fetchButtonText.textContent =
  1317. settings.autoBatchEnabled
  1318. ? "Auto Fetch"
  1319. : settings.mediaType === "all"
  1320. ? "Fetch Media"
  1321. : `Fetch ${mediaTypeLabelText === "gif" ? "GIF" : mediaTypeLabelText.charAt(0).toUpperCase() + mediaTypeLabelText.slice(1)}`;
  1322.  
  1323. fetchButton.innerHTML = "";
  1324. fetchButton.appendChild(fetchIcon);
  1325. fetchButton.appendChild(fetchButtonText);
  1326. fetchButton.style.cssText = `
  1327. background-color: #22c55e;
  1328. color: white;
  1329. border: none;
  1330. border-radius: 6px;
  1331. padding: 8px 16px;
  1332. font-weight: bold;
  1333. cursor: pointer;
  1334. margin: 0;
  1335. width: 48%;
  1336. display: flex;
  1337. justify-content: center;
  1338. align-items: center;
  1339. text-align: center;
  1340. transition: background-color 0.2s;
  1341. `;
  1342. fetchButton.addEventListener("mouseenter", () => {
  1343. fetchButton.style.backgroundColor = "#16a34a";
  1344. });
  1345.  
  1346. fetchButton.addEventListener("mouseleave", () => {
  1347. fetchButton.style.backgroundColor = "#22c55e";
  1348. });const infoContainer = document.createElement("div");
  1349. infoContainer.style.cssText = `
  1350. background-color: ${settings.darkTheme ? "#374151" : "#f1f5f9"};
  1351. border-radius: 8px;
  1352. padding: 12px;
  1353. margin-bottom: 16px;
  1354. display: none;
  1355. `;
  1356.  
  1357. const buttonContainer = document.createElement("div");
  1358. buttonContainer.style.cssText = `
  1359. display: none;
  1360. gap: 8px;
  1361. margin-bottom: 16px;
  1362. `;const batchNavContainer = document.createElement("div");
  1363. batchNavContainer.style.cssText = `
  1364. display: none;
  1365. flex-direction: column;
  1366. gap: 8px;
  1367. margin-bottom: 16px;
  1368. `;
  1369.  
  1370. const prevBatchButton = document.createElement("button");
  1371. prevBatchButton.innerHTML = `<span style="display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;">${ICONS.PREV}<span>Prev Batch</span></span>`;
  1372. prevBatchButton.style.cssText = `
  1373. background-color: #6366f1;
  1374. color: white;
  1375. border: none;
  1376. border-radius: 6px;
  1377. padding: 8px 16px;
  1378. font-weight: bold;
  1379. cursor: pointer;
  1380. width: 40%;
  1381. display: flex;
  1382. align-items: center;
  1383. justify-content: center;
  1384. text-align: center;
  1385. transition: background-color 0.2s;
  1386. `;
  1387.  
  1388. prevBatchButton.addEventListener("mouseenter", () => {
  1389. prevBatchButton.style.backgroundColor = "#4f46e5";
  1390. });
  1391. prevBatchButton.addEventListener("mouseleave", () => {
  1392. prevBatchButton.style.backgroundColor = "#6366f1";
  1393. });
  1394.  
  1395. const nextBatchButton = document.createElement("button");
  1396. nextBatchButton.innerHTML = `<span style="display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;"><span>Next Batch</span>${ICONS.NEXT}</span>`;
  1397. nextBatchButton.style.cssText = `
  1398. background-color: #6366f1;
  1399. color: white;
  1400. border: none;
  1401. border-radius: 6px;
  1402. padding: 8px 16px;
  1403. font-weight: bold;
  1404. cursor: pointer;
  1405. width: 40%;
  1406. display: flex;
  1407. align-items: center;
  1408. justify-content: center;
  1409. text-align: center;
  1410. transition: background-color 0.2s;
  1411. `;
  1412.  
  1413. nextBatchButton.addEventListener("mouseenter", () => {
  1414. nextBatchButton.style.backgroundColor = "#4f46e5";
  1415. });
  1416. nextBatchButton.addEventListener("mouseleave", () => {
  1417. nextBatchButton.style.backgroundColor = "#6366f1";
  1418. });
  1419.  
  1420. const buttonWrapper = document.createElement("div");
  1421. buttonWrapper.style.cssText = `
  1422. display: flex;
  1423. gap: 8px;
  1424. justify-content: center;
  1425. width: 100%;
  1426. `;
  1427.  
  1428. buttonWrapper.appendChild(prevBatchButton);
  1429. buttonWrapper.appendChild(nextBatchButton);
  1430. batchNavContainer.appendChild(buttonWrapper);
  1431.  
  1432. const stopFetchButton = document.createElement("button");
  1433. stopFetchButton.innerHTML = `<span style="display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;">${ICONS.STOP}<span>Stop Fetch</span></span>`;
  1434.  
  1435. stopFetchButton.style.cssText = `
  1436. background-color: #ef4444;
  1437. color: white;
  1438. border: none;
  1439. border-radius: 6px;
  1440. padding: 8px 16px;
  1441. font-weight: bold;
  1442. cursor: pointer;
  1443. width: 140px; /* Fixed width instead of percentage */
  1444. display: none;
  1445. align-items: center;
  1446. justify-content: center;
  1447. text-align: center;
  1448. transition: background-color 0.2s;
  1449. `;
  1450.  
  1451. stopFetchButton.addEventListener("mouseenter", () => { stopFetchButton.style.backgroundColor = "#dc2626"; });
  1452. stopFetchButton.addEventListener("mouseleave", () => { stopFetchButton.style.backgroundColor = "#ef4444"; });
  1453. stopFetchButton.addEventListener("click", () => {
  1454. autoBatchCancelled = true;
  1455. autoBatchStarted = false;
  1456. batchNavContainer.style.display = "flex";
  1457. prevBatchButton.style.display = mediaData.currentPage > getSettings().startingBatch ? "block" : "none";
  1458. nextBatchButton.style.display = mediaData.hasMore ? "block" : "none";
  1459. stopFetchButton.style.display = "none";
  1460. batchInfoContainer.style.display = "flex";
  1461. infoContainer.style.display = "block";
  1462. fetchButtonText.textContent = "Auto Fetch";
  1463. });
  1464.  
  1465. const stopFetchWrapper = document.createElement("div");
  1466. stopFetchWrapper.style.cssText = `
  1467. display: flex;
  1468. justify-content: center;
  1469. width: 100%;
  1470. margin-top: 8px; /* Add spacing between button rows */
  1471. `;
  1472. stopFetchWrapper.appendChild(stopFetchButton);
  1473. batchNavContainer.appendChild(stopFetchWrapper);
  1474.  
  1475. const batchInfoContainer = document.createElement("div");
  1476. batchInfoContainer.style.cssText = `
  1477. display: none;
  1478. flex-direction: column;
  1479. gap: 8px;
  1480. margin-bottom: 16px;
  1481. padding: 12px;
  1482. background-color: ${settings.darkTheme ? "#374151" : "#f8fafc"};
  1483. border-radius: 8px;
  1484. border: 1px solid ${settings.darkTheme ? "#4b5563" : "#e2e8f0"};
  1485. `
  1486.  
  1487. const batchStatsRow = document.createElement("div")
  1488. batchStatsRow.style.cssText = `
  1489. display: flex;
  1490. justify-content: space-between;
  1491. align-items: center;
  1492. `
  1493.  
  1494. const currentBatchLabel = document.createElement("div")
  1495. currentBatchLabel.style.cssText = `
  1496. font-size: 14px;
  1497. color: ${settings.darkTheme ? "#ffffff" : "#475569"};
  1498. `
  1499.  
  1500. const totalBatchLabel = document.createElement("div")
  1501. totalBatchLabel.style.cssText = `
  1502. font-size: 14px;
  1503. color: ${settings.darkTheme ? "#ffffff" : "#475569"};
  1504. `
  1505.  
  1506. batchStatsRow.appendChild(currentBatchLabel)
  1507. batchStatsRow.appendChild(totalBatchLabel)
  1508.  
  1509. const downloadButtonsRow = document.createElement("div")
  1510. downloadButtonsRow.style.cssText = `
  1511. display: flex;
  1512. gap: 8px;
  1513. justify-content: center;
  1514. `
  1515.  
  1516. const downloadCurrentButton = document.createElement("button")
  1517. downloadCurrentButton.innerHTML = ""
  1518. const currentIcon = createDownloadIcon()
  1519. currentIcon.style.width = "12px"
  1520. currentIcon.style.height = "12px"
  1521. currentIcon.style.marginRight = "4px"
  1522. const currentText = document.createElement("span")
  1523. currentText.textContent = "Download Current"
  1524. downloadCurrentButton.appendChild(currentIcon)
  1525. downloadCurrentButton.appendChild(currentText)
  1526. downloadCurrentButton.style.cssText = `
  1527. background-color: #0ea5e9;
  1528. color: white;
  1529. border: none;
  1530. border-radius: 6px;
  1531. padding: 6px 12px;
  1532. font-weight: bold;
  1533. cursor: pointer;
  1534. font-size: 12px;
  1535. transition: background-color 0.2s;
  1536. flex: 1;
  1537. display: flex;
  1538. align-items: center;
  1539. justify-content: center;
  1540. `
  1541. downloadCurrentButton.addEventListener("mouseenter", () => {
  1542. downloadCurrentButton.style.backgroundColor = "#0284c7"
  1543. })
  1544. downloadCurrentButton.addEventListener("mouseleave", () => {
  1545. downloadCurrentButton.style.backgroundColor = "#0ea5e9"
  1546. })
  1547.  
  1548. const downloadAllButton = document.createElement("button")
  1549. downloadAllButton.innerHTML = ""
  1550. const allIcon = createDownloadIcon()
  1551. allIcon.style.width = "12px"
  1552. allIcon.style.height = "12px"
  1553. allIcon.style.marginRight = "4px"
  1554. const allText = document.createElement("span")
  1555. allText.textContent = "Download All"
  1556. downloadAllButton.appendChild(allIcon)
  1557. downloadAllButton.appendChild(allText)
  1558. downloadAllButton.style.cssText = `
  1559. background-color: #0ea5e9;
  1560. color: white;
  1561. border: none;
  1562. border-radius: 6px;
  1563. padding: 6px 12px;
  1564. font-weight: bold;
  1565. cursor: pointer;
  1566. font-size: 12px;
  1567. transition: background-color 0.2s;
  1568. flex: 1;
  1569. display: flex;
  1570. align-items: center;
  1571. justify-content: center;
  1572. `;
  1573. downloadAllButton.addEventListener("mouseenter", () => {
  1574. downloadAllButton.style.backgroundColor = "#0284c7";
  1575. });
  1576. downloadAllButton.addEventListener("mouseleave", () => {
  1577. downloadAllButton.style.backgroundColor = "#0ea5e9";
  1578. });
  1579.  
  1580. downloadButtonsRow.appendChild(downloadCurrentButton);
  1581. downloadButtonsRow.appendChild(downloadAllButton);
  1582.  
  1583. batchInfoContainer.appendChild(batchStatsRow);
  1584. batchInfoContainer.appendChild(downloadButtonsRow);
  1585.  
  1586. const downloadButton = document.createElement("button");
  1587. const downloadIcon = createDownloadIcon();
  1588. downloadIcon.style.width = "16px";
  1589. downloadIcon.style.height = "16px";
  1590. downloadIcon.style.marginRight = "8px";
  1591.  
  1592. downloadButton.innerHTML = "";
  1593. downloadButton.appendChild(downloadIcon);
  1594. downloadButton.appendChild(document.createTextNode("Download"));
  1595. downloadButton.style.cssText = `
  1596. background-color: #0ea5e9;
  1597. color: white;
  1598. border: none;
  1599. border-radius: 6px;
  1600. padding: 8px 16px;
  1601. font-weight: bold;
  1602. cursor: pointer;
  1603. width: 50%;
  1604. margin-left: auto;
  1605. margin-right: auto;
  1606. display: flex;
  1607. align-items: center;
  1608. justify-content: center;
  1609. text-align: center;
  1610. transition: background-color 0.2s;
  1611. `
  1612. downloadButton.addEventListener("mouseenter", () => {
  1613. downloadButton.style.backgroundColor = "#0284c7"
  1614. })
  1615. downloadButton.addEventListener("mouseleave", () => {
  1616. downloadButton.style.backgroundColor = "#0ea5e9"
  1617. })
  1618. downloadButton.onclick = () => downloadMedia(false)
  1619.  
  1620. if (settings.batchEnabled) {
  1621. buttonContainer.style.display = "none"
  1622. } else {
  1623. buttonContainer.appendChild(downloadButton)
  1624. }
  1625. const batchButtonsContainer = document.createElement("div");
  1626. batchButtonsContainer.style.cssText = `
  1627. display: none;
  1628. gap: 8px;
  1629. margin-bottom: 16px;
  1630. `;
  1631.  
  1632. const progressContainer = document.createElement("div");
  1633. progressContainer.style.cssText = `
  1634. margin-top: 16px;
  1635. display: none;
  1636. `;
  1637.  
  1638. const progressText = document.createElement("div");
  1639. progressText.style.cssText = `
  1640. margin-bottom: 8px;
  1641. font-size: 14px;
  1642. text-align: center;
  1643. `;
  1644. progressText.textContent = "Downloading...";
  1645.  
  1646. const progressBar = document.createElement("div");
  1647. progressBar.style.cssText = `
  1648. width: 100%;
  1649. height: 8px;
  1650. background-color: ${settings.darkTheme ? "#374151" : "#f1f5f9"};
  1651. border-radius: 4px;
  1652. overflow: hidden;
  1653. `;
  1654. const progressFill = document.createElement("div");
  1655. progressFill.style.cssText = `
  1656. height: 100%;
  1657. width: 0%;
  1658. background-color: #0ea5e9;
  1659. transition: width 0.3s ease-in-out;
  1660. will-change: width;
  1661. `;
  1662.  
  1663. progressBar.appendChild(progressFill);
  1664. progressContainer.appendChild(progressText)
  1665. progressContainer.appendChild(progressBar)
  1666. const convertGifButton = document.createElement("button");
  1667. const convertGifIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
  1668. convertGifIcon.setAttribute("xmlns", "http://www.w3.org/2000/svg");
  1669. convertGifIcon.setAttribute("viewBox", ICONS.MEDIA_TYPE.GIF.VIEWBOX);
  1670. convertGifIcon.setAttribute("width", "16");
  1671. convertGifIcon.setAttribute("height", "16");
  1672. convertGifIcon.style.marginRight = "8px";
  1673.  
  1674. const convertGifPath = document.createElementNS("http://www.w3.org/2000/svg", "path");
  1675. convertGifPath.setAttribute("fill", "currentColor");
  1676. convertGifPath.setAttribute("d", ICONS.MEDIA_TYPE.GIF.PATH);
  1677. convertGifIcon.appendChild(convertGifPath);
  1678.  
  1679. const convertGifButtonText = document.createElement("span");
  1680. convertGifButtonText.textContent = "Convert GIF";
  1681.  
  1682. convertGifButton.innerHTML = "";
  1683. convertGifButton.appendChild(convertGifIcon);
  1684. convertGifButton.appendChild(convertGifButtonText);
  1685. convertGifButton.style.cssText = `
  1686. background-color: #3b82f6;
  1687. color: white;
  1688. border: none;
  1689. border-radius: 6px;
  1690. padding: 8px 16px;
  1691. font-weight: bold;
  1692. cursor: pointer;
  1693. margin: 0;
  1694. width: 48%;
  1695. display: flex;
  1696. justify-content: center;
  1697. align-items: center;
  1698. text-align: center;
  1699. transition: background-color 0.2s;
  1700. `;
  1701.  
  1702. convertGifButton.addEventListener("mouseenter", () => {
  1703. convertGifButton.style.backgroundColor = "#2563eb";
  1704. });
  1705.  
  1706. convertGifButton.addEventListener("mouseleave", () => {
  1707. convertGifButton.style.backgroundColor = "#3b82f6";
  1708. });
  1709. convertGifButton.addEventListener("click", () => {
  1710. const convertUrl = `https://convert.xbatch.online/${username}`;
  1711. window.open(convertUrl, '_blank');
  1712. });
  1713.  
  1714. const mainButtonsContainer = document.createElement("div");
  1715. mainButtonsContainer.style.cssText = `
  1716. display: flex;
  1717. gap: 4%;
  1718. margin: 16px 0;
  1719. width: 100%;
  1720. `;
  1721. mainButtonsContainer.appendChild(fetchButton);
  1722. mainButtonsContainer.appendChild(convertGifButton);
  1723.  
  1724. mainContent.appendChild(mainButtonsContainer)
  1725. mainContent.appendChild(infoContainer)
  1726. mainContent.appendChild(batchInfoContainer)
  1727. mainContent.appendChild(batchNavContainer)
  1728. mainContent.appendChild(buttonContainer)
  1729. mainContent.appendChild(batchButtonsContainer)
  1730. mainContent.appendChild(progressContainer);
  1731.  
  1732. const settingsTabs = document.createElement("div")
  1733. settingsTabs.style.cssText = `
  1734. display: flex;
  1735. border-bottom: 1px solid ${settings.darkTheme ? "#374151" : "#e2e8f0"};
  1736. margin-bottom: 16px;
  1737. width: 100%;
  1738. `
  1739.  
  1740. const fetchTab = document.createElement("button")
  1741. fetchTab.textContent = "Fetch"
  1742. fetchTab.style.cssText = `
  1743. background: none;
  1744. border: none;
  1745. padding: 12px 16px;
  1746. cursor: pointer;
  1747. color: ${settings.darkTheme ? "#f1f5f9" : "#0f172a"};
  1748. border-bottom: 2px solid #0ea5e9;
  1749. font-weight: bold;
  1750. font-size: 14px;
  1751. flex: 1;
  1752. text-align: center;
  1753. `
  1754.  
  1755. const authTab = document.createElement("button")
  1756. authTab.textContent = "Auth"
  1757. authTab.style.cssText = `
  1758. background: none;
  1759. border: none;
  1760. padding: 12px 16px;
  1761. cursor: pointer;
  1762. color: #64748b;
  1763. border-bottom: none;
  1764. font-weight: bold;
  1765. font-size: 14px;
  1766. flex: 1;
  1767. text-align: center;
  1768. `
  1769.  
  1770. const advancedTab = document.createElement("button")
  1771. advancedTab.textContent = "Advanced"
  1772. advancedTab.style.cssText = `
  1773. background: none;
  1774. border: none;
  1775. padding: 12px 16px;
  1776. cursor: pointer;
  1777. color: #64748b;
  1778. border-bottom: none;
  1779. font-weight: bold;
  1780. font-size: 14px;
  1781. flex: 1;
  1782. text-align: center;
  1783. `;
  1784. settingsTabs.appendChild(fetchTab);
  1785. settingsTabs.appendChild(authTab);
  1786. settingsTabs.appendChild(advancedTab);
  1787. const fetchTabContent = document.createElement("div")
  1788. fetchTabContent.style.cssText = `
  1789. display: flex;
  1790. flex-direction: column;
  1791. gap: ${settings.batchEnabled ? "16px" : "8px"};
  1792. `
  1793.  
  1794. const downloadTabContent = document.createElement("div")
  1795. downloadTabContent.style.cssText = `
  1796. display: none;
  1797. flex-direction: column;
  1798. gap: 16px;
  1799. `
  1800.  
  1801. const authTabContent = document.createElement("div")
  1802. authTabContent.style.cssText = `
  1803. display: none;
  1804. flex-direction: column;
  1805. gap: 16px;
  1806. `
  1807.  
  1808. const advancedTabContent = document.createElement("div")
  1809. advancedTabContent.style.cssText = `
  1810. display: none;
  1811. flex-direction: column;
  1812. gap: 0px;
  1813. `
  1814.  
  1815. const patreonAuthGroup = document.createElement("div")
  1816. patreonAuthGroup.style.cssText = `
  1817. display: flex;
  1818. flex-direction: column;
  1819. gap: 8px;
  1820. `
  1821.  
  1822. const patreonAuthLabel = document.createElement("label")
  1823. patreonAuthLabel.textContent = "Patreon Auth:"
  1824. patreonAuthLabel.style.cssText = `
  1825. font-size: 14px;
  1826. font-weight: bold;
  1827. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  1828. `
  1829.  
  1830. const patreonAuthInputContainer = document.createElement("div")
  1831. patreonAuthInputContainer.style.cssText = `
  1832. position: relative;
  1833. display: flex;
  1834. align-items: center;
  1835. `
  1836.  
  1837. const patreonAuthInput = document.createElement("input")
  1838. patreonAuthInput.type = "text"
  1839. patreonAuthInput.value = settings.patreonAuth
  1840. patreonAuthInput.style.cssText = `
  1841. background-color: ${settings.darkTheme ? "#374151" : "#f1f5f9"};
  1842. border: 1px solid transparent;
  1843. border-radius: 4px;
  1844. padding: 8px 12px;
  1845. color: ${settings.darkTheme ? "#cbd5e1" : "#64748b"};
  1846. width: 100%;
  1847. box-sizing: border-box;
  1848. transition: all 0.2s ease;
  1849. `
  1850.  
  1851. patreonAuthInput.addEventListener("focus", () => {
  1852. patreonAuthInput.style.border = "1px solid #0ea5e9"
  1853. patreonAuthInput.style.outline = "none"
  1854. })
  1855. patreonAuthInput.addEventListener("blur", () => {
  1856. patreonAuthInput.style.border = "1px solid transparent"
  1857. })
  1858.  
  1859. patreonAuthInput.addEventListener("input", () => {
  1860. const newSettings = getSettings()
  1861. newSettings.patreonAuth = patreonAuthInput.value
  1862. saveSettings(newSettings)
  1863. patreonAuthClearButton.style.display = patreonAuthInput.value ? "block" : "none"
  1864. })
  1865.  
  1866. const patreonAuthClearButton = document.createElement("button")
  1867. patreonAuthClearButton.innerHTML = "&times;"
  1868. patreonAuthClearButton.style.cssText = `
  1869. position: absolute;
  1870. right: 8px;
  1871. background: none;
  1872. border: none;
  1873. color: #64748b;
  1874. font-size: 18px;
  1875. cursor: pointer;
  1876. padding: 0;
  1877. display: ${settings.patreonAuth ? "block" : "none"};
  1878. `
  1879. patreonAuthClearButton.addEventListener("click", () => {
  1880. patreonAuthInput.value = ""
  1881. const newSettings = getSettings()
  1882. newSettings.patreonAuth = ""
  1883. saveSettings(newSettings)
  1884. patreonAuthClearButton.style.display = "none"
  1885. })
  1886.  
  1887. patreonAuthInputContainer.appendChild(patreonAuthInput)
  1888. patreonAuthInputContainer.appendChild(patreonAuthClearButton)
  1889. patreonAuthGroup.appendChild(patreonAuthLabel)
  1890. patreonAuthGroup.appendChild(patreonAuthInputContainer)
  1891.  
  1892. const tokenGroup = document.createElement("div")
  1893. tokenGroup.style.cssText = `
  1894. display: flex;
  1895. flex-direction: column;
  1896. gap: 8px;
  1897. `
  1898.  
  1899. const tokenLabel = document.createElement("label")
  1900. tokenLabel.textContent = "Auth Token:"
  1901. tokenLabel.style.cssText = `
  1902. font-size: 14px;
  1903. font-weight: bold;
  1904. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  1905. `
  1906.  
  1907. const tokenInputContainer = document.createElement("div")
  1908. tokenInputContainer.style.cssText = `
  1909. position: relative;
  1910. display: flex;
  1911. align-items: center;
  1912. `
  1913.  
  1914. const tokenInput = document.createElement("input")
  1915. tokenInput.type = "text"
  1916. tokenInput.value = settings.authToken
  1917. tokenInput.style.cssText = `
  1918. background-color: ${settings.darkTheme ? "#374151" : "#f1f5f9"};
  1919. border: 1px solid transparent;
  1920. border-radius: 4px;
  1921. padding: 8px 12px;
  1922. color: ${settings.darkTheme ? "#cbd5e1" : "#64748b"};
  1923. width: 100%;
  1924. box-sizing: border-box;
  1925. transition: all 0.2s ease;
  1926. `
  1927. tokenInput.addEventListener("focus", () => {
  1928. tokenInput.style.border = "1px solid #0ea5e9"
  1929. tokenInput.style.outline = "none"
  1930. })
  1931. tokenInput.addEventListener("blur", () => {
  1932. tokenInput.style.border = "1px solid transparent"
  1933. })
  1934.  
  1935. tokenInput.addEventListener("input", () => {
  1936. const newSettings = getSettings()
  1937. newSettings.authToken = tokenInput.value
  1938. saveSettings(newSettings)
  1939. tokenClearButton.style.display = tokenInput.value ? "block" : "none"
  1940. })
  1941.  
  1942. const tokenClearButton = document.createElement("button")
  1943. tokenClearButton.innerHTML = "&times;"
  1944. tokenClearButton.style.cssText = `
  1945. position: absolute;
  1946. right: 8px;
  1947. background: none;
  1948. border: none;
  1949. color: #64748b;
  1950. font-size: 18px;
  1951. cursor: pointer;
  1952. padding: 0;
  1953. display: ${settings.authToken ? "block" : "none"};
  1954. `
  1955. tokenClearButton.addEventListener("click", () => {
  1956. tokenInput.value = ""
  1957. const newSettings = getSettings()
  1958. newSettings.authToken = ""
  1959. saveSettings(newSettings)
  1960. tokenClearButton.style.display = "none"
  1961. })
  1962.  
  1963. tokenInputContainer.appendChild(tokenInput)
  1964. tokenInputContainer.appendChild(tokenClearButton)
  1965. tokenGroup.appendChild(tokenLabel)
  1966. tokenGroup.appendChild(tokenInputContainer)
  1967.  
  1968. const apiServerGroup = document.createElement("div")
  1969. apiServerGroup.style.cssText = `
  1970. display: flex;
  1971. flex-direction: column;
  1972. gap: 8px;
  1973. `
  1974.  
  1975. const apiServerLabel = document.createElement("label")
  1976. apiServerLabel.textContent = "Service:"
  1977. apiServerLabel.style.cssText = `
  1978. font-size: 14px;
  1979. font-weight: bold;
  1980. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  1981. `
  1982.  
  1983. const apiServerOptions = [
  1984. { value: "default", label: "Default" },
  1985. { value: "backup", label: "Backup" }
  1986. ]
  1987.  
  1988. const apiServerToggle = createToggleSwitch(apiServerOptions, settings.apiServer, (value) => {
  1989. const newSettings = getSettings()
  1990. newSettings.apiServer = value
  1991. saveSettings(newSettings)
  1992. settings.apiServer = value
  1993. })
  1994.  
  1995. apiServerGroup.appendChild(apiServerLabel)
  1996. apiServerGroup.appendChild(apiServerToggle)
  1997.  
  1998. const batchGroup = document.createElement("div")
  1999. batchGroup.style.cssText = `
  2000. display: flex;
  2001. align-items: center;
  2002. gap: 8px;
  2003. `
  2004. const batchLabel = document.createElement("label")
  2005. batchLabel.style.cssText = `
  2006. font-size: 14px;
  2007. font-weight: bold;
  2008. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  2009. flex: 1;
  2010. display: flex;
  2011. align-items: center;
  2012. `
  2013. const batchLabelText = document.createElement("span")
  2014. batchLabelText.textContent = "Batch:"
  2015. batchLabel.appendChild(batchLabelText)
  2016.  
  2017. const batchInfoIcon = createInfoIcon()
  2018. const batchTooltip = createInfoTooltip("When enabled, the media fetching process is performed in batches")
  2019. batchInfoIcon.addEventListener("mouseenter", batchTooltip.showTooltip)
  2020. batchInfoIcon.addEventListener("mouseleave", batchTooltip.hideTooltip)
  2021. batchLabel.appendChild(batchInfoIcon)
  2022.  
  2023. const batchToggle = document.createElement("div")
  2024. batchToggle.style.cssText = `
  2025. position: relative;
  2026. width: 50px;
  2027. height: 24px;
  2028. background-color: ${settings.batchEnabled ? "#22c55e" : "#cbd5e1"};
  2029. border-radius: 12px;
  2030. cursor: pointer;
  2031. transition: background-color 0.3s;
  2032. `
  2033.  
  2034. const batchToggleHandle = document.createElement("div")
  2035. batchToggleHandle.style.cssText = `
  2036. position: absolute;
  2037. top: 2px;
  2038. left: ${settings.batchEnabled ? "28px" : "2px"};
  2039. width: 20px;
  2040. height: 20px;
  2041. background-color: white;
  2042. border-radius: 50%;
  2043. transition: left 0.3s;
  2044. `
  2045.  
  2046. batchToggle.appendChild(batchToggleHandle)
  2047. batchToggle.addEventListener("click", () => {
  2048. const newSettings = getSettings()
  2049. newSettings.batchEnabled = !newSettings.batchEnabled
  2050. saveSettings(newSettings)
  2051. batchToggle.style.backgroundColor = newSettings.batchEnabled ? "#22c55e" : "#cbd5e1"
  2052. batchToggleHandle.style.left = newSettings.batchEnabled ? "28px" : "2px"
  2053. autoBatchGroup.style.display = newSettings.batchEnabled ? "flex" : "none"
  2054. batchSizeGroup.style.display = newSettings.batchEnabled ? "flex" : "none"
  2055. startingBatchGroup.style.display = newSettings.batchEnabled ? "flex" : "none"
  2056. if (!newSettings.batchEnabled) {
  2057. fetchTabContent.style.gap = "8px"
  2058. newSettings.autoBatchEnabled = false
  2059. saveSettings(newSettings)
  2060. autoBatchToggle.style.backgroundColor = "#cbd5e1"
  2061. autoBatchHandle.style.left = "2px"
  2062. const mt = getSettings().mediaType
  2063. const mtLabel = getMediaTypeLabel(mt).toLowerCase()
  2064. const labelText = mt === "all" ? "Fetch Media" : `Fetch ${mtLabel === "gif" ? "GIF" : mtLabel.charAt(0).toUpperCase() + mtLabel.slice(1)}`
  2065.  
  2066. fetchButtonText.textContent = labelText
  2067. fetchButton.innerHTML = ""
  2068. let updatedFetchIcon = fetchIcon.cloneNode(true)
  2069. fetchButton.appendChild(updatedFetchIcon)
  2070. fetchButton.appendChild(fetchButtonText)
  2071. if (typeof stopFetchButton !== 'undefined') stopFetchButton.style.display = "none"
  2072. if (typeof prevBatchButton !== 'undefined') prevBatchButton.style.display = "block"
  2073. if (typeof nextBatchButton !== 'undefined') nextBatchButton.style.display = "block"
  2074. } else {
  2075. fetchTabContent.style.gap = "16px"
  2076. }
  2077. })
  2078.  
  2079. batchGroup.appendChild(batchLabel)
  2080. batchGroup.appendChild(batchToggle)
  2081.  
  2082. const autoBatchGroup = document.createElement("div")
  2083. autoBatchGroup.style.cssText = `
  2084. display: ${settings.batchEnabled ? "flex" : "none"};
  2085. align-items: center;
  2086. gap: 8px;
  2087. `
  2088. const autoBatchLabel = document.createElement("label")
  2089. autoBatchLabel.style.cssText = `
  2090. font-size: 14px;
  2091. font-weight: bold;
  2092. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  2093. flex: 1;
  2094. display: flex;
  2095. align-items: center;
  2096. `
  2097. autoBatchLabel.textContent = "Auto Fetch"
  2098. const autoBatchToggle = document.createElement("div")
  2099. autoBatchToggle.style.cssText = `
  2100. position: relative;
  2101. width: 50px;
  2102. height: 24px;
  2103. background-color: ${settings.autoBatchEnabled ? "#22c55e" : "#cbd5e1"};
  2104. border-radius: 12px;
  2105. cursor: pointer;
  2106. transition: background-color 0.3s;
  2107. `
  2108. const autoBatchHandle = document.createElement("div")
  2109. autoBatchHandle.style.cssText = `
  2110. position: absolute;
  2111. top: 2px;
  2112. left: ${settings.autoBatchEnabled ? "28px" : "2px"};
  2113. width: 20px;
  2114. height: 20px;
  2115. background-color: white;
  2116. border-radius: 50%;
  2117. transition: left 0.3s;
  2118. `
  2119. autoBatchToggle.appendChild(autoBatchHandle)
  2120. autoBatchToggle.addEventListener("click", () => {
  2121. const newSettings = getSettings()
  2122. const willEnable = !newSettings.autoBatchEnabled
  2123. newSettings.autoBatchEnabled = willEnable
  2124. saveSettings(newSettings)
  2125. autoBatchCancelled = false
  2126. autoBatchStarted = false
  2127. autoBatchToggle.style.backgroundColor = willEnable ? "#22c55e" : "#cbd5e1"
  2128. autoBatchHandle.style.left = willEnable ? "28px" : "2px"
  2129. const label = willEnable
  2130. ? "Auto Fetch"
  2131. : (newSettings.mediaType === "all"
  2132. ? "Fetch Media"
  2133. : newSettings.mediaType === "image"
  2134. ? "Fetch Photos"
  2135. : "Fetch Videos")
  2136. fetchButtonText.textContent = label
  2137.  
  2138. if (willEnable) {
  2139. const keyPrefix = `twitter_dl_${newSettings.timelineType}_${newSettings.mediaType}_${username}_`
  2140. const keySuffix = `_${newSettings.batchSize}_batch_true`
  2141. for (let i = 0; i < localStorage.length; i++) {
  2142. const key = localStorage.key(i)
  2143. if (key.startsWith(keyPrefix) && key.endsWith(keySuffix)) {
  2144. const pageNum = parseInt(key.slice(keyPrefix.length, key.length - keySuffix.length), 10)
  2145. if (!isNaN(pageNum)) {
  2146. const cachedData = cacheManager.get(key)
  2147. if (cachedData && cachedData.timeline) {
  2148. mediaData.batchData[pageNum] = cachedData.timeline
  2149. }
  2150. }
  2151. }
  2152. }
  2153. const batchNums = Object.keys(mediaData.batchData).map(Number)
  2154. mediaData.currentPage = batchNums.length > 0 ? Math.max(...batchNums) + 1 : 0
  2155. fetchButtonText.textContent = "Auto Fetch"
  2156. } else {
  2157. const mt = newSettings.mediaType
  2158. const label = mt === "all" ? "Fetch Media" : `Fetch ${getMediaTypeLabel(mt).toUpperCase()}`
  2159. fetchButtonText.textContent = label
  2160. }
  2161. })
  2162. autoBatchGroup.appendChild(autoBatchLabel)
  2163. autoBatchGroup.appendChild(autoBatchToggle)
  2164.  
  2165. const batchSizeGroup = document.createElement("div")
  2166. batchSizeGroup.style.cssText = `
  2167. display: ${settings.batchEnabled ? "flex" : "none"};
  2168. flex-direction: column;
  2169. gap: 8px;
  2170. `
  2171.  
  2172. const batchSizeLabel = document.createElement("label")
  2173. batchSizeLabel.style.cssText = `
  2174. font-size: 14px;
  2175. font-weight: bold;
  2176. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  2177. display: flex;
  2178. align-items: center;
  2179. `
  2180. const batchSizeLabelText = document.createElement("span")
  2181. batchSizeLabelText.textContent = "Batch Size:"
  2182. batchSizeLabel.appendChild(batchSizeLabelText)
  2183.  
  2184. const batchSizeInfoIcon = createInfoIcon()
  2185. const batchSizeTooltip = createInfoTooltip("Number of media items fetched in a single request")
  2186. batchSizeInfoIcon.addEventListener("mouseenter", batchSizeTooltip.showTooltip)
  2187. batchSizeInfoIcon.addEventListener("mouseleave", batchSizeTooltip.hideTooltip)
  2188. batchSizeLabel.appendChild(batchSizeInfoIcon)
  2189.  
  2190. const batchSizeToggle = createSlider(batchSizes, settings.batchSize, (value) => {
  2191. const newSettings = getSettings()
  2192. newSettings.batchSize = value
  2193. saveSettings(newSettings)
  2194. settings.batchSize = value
  2195. })
  2196.  
  2197. batchSizeGroup.appendChild(batchSizeLabel)
  2198. batchSizeGroup.appendChild(batchSizeToggle)
  2199.  
  2200. const startingBatchGroup = document.createElement("div")
  2201. startingBatchGroup.style.cssText = `
  2202. display: ${settings.batchEnabled ? "flex" : "none"};
  2203. flex-direction: column;
  2204. gap: 8px;
  2205. `
  2206.  
  2207. const startingBatchLabel = document.createElement("label")
  2208. startingBatchLabel.style.cssText = `
  2209. font-size: 14px;
  2210. font-weight: bold;
  2211. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  2212. display: flex;
  2213. align-items: center;
  2214. `
  2215. const startingBatchLabelText = document.createElement("span")
  2216. startingBatchLabelText.textContent = "Starting Batch:"
  2217. startingBatchLabel.appendChild(startingBatchLabelText)
  2218.  
  2219. const startingBatchInfoIcon = createInfoIcon()
  2220. const startingBatchTooltip = createInfoTooltip("Determines which batch number to start fetching from")
  2221. startingBatchInfoIcon.addEventListener("mouseenter", startingBatchTooltip.showTooltip)
  2222. startingBatchInfoIcon.addEventListener("mouseleave", startingBatchTooltip.hideTooltip)
  2223. startingBatchLabel.appendChild(startingBatchInfoIcon)
  2224.  
  2225. const startingBatchInput = document.createElement("input")
  2226. startingBatchInput.type = "number"
  2227. startingBatchInput.value = settings.startingBatch
  2228. startingBatchInput.min = "0"
  2229. startingBatchInput.style.cssText = `
  2230. background-color: ${settings.darkTheme ? "#374151" : "#f1f5f9"};
  2231. border: 1px solid transparent;
  2232. border-radius: 4px;
  2233. padding: 8px 12px;
  2234. color: ${settings.darkTheme ? "#cbd5e1" : "#64748b"};
  2235. width: 100%;
  2236. box-sizing: border-box;
  2237. transition: all 0.2s ease;
  2238. `
  2239. startingBatchInput.addEventListener("focus", () => {
  2240. startingBatchInput.style.border = "1px solid #0ea5e9"
  2241. startingBatchInput.style.outline = "none"
  2242. })
  2243. startingBatchInput.addEventListener("blur", () => {
  2244. startingBatchInput.style.border = "1px solid transparent"
  2245. })
  2246.  
  2247. startingBatchInput.addEventListener("input", () => {
  2248. const newSettings = getSettings()
  2249. newSettings.startingBatch = parseInt(startingBatchInput.value) || 0
  2250. saveSettings(newSettings)
  2251. settings.startingBatch = newSettings.startingBatch
  2252. })
  2253.  
  2254. startingBatchGroup.appendChild(startingBatchLabel)
  2255. startingBatchGroup.appendChild(startingBatchInput)
  2256.  
  2257. const timelineTypeGroup = document.createElement("div")
  2258. timelineTypeGroup.style.cssText = `
  2259. display: flex;
  2260. flex-direction: column;
  2261. gap: 8px;
  2262. `
  2263.  
  2264. const timelineTypeLabel = document.createElement("label")
  2265. timelineTypeLabel.textContent = "Timeline Type:"
  2266. timelineTypeLabel.style.cssText = `
  2267. font-size: 14px;
  2268. font-weight: bold;
  2269. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  2270. `
  2271.  
  2272. const timelineTypeOptions = [
  2273. { value: "media", label: "Media", icon: createTimelineTypeIcon("media") },
  2274. { value: "timeline", label: "Post", icon: createTimelineTypeIcon("timeline") },
  2275. { value: "tweets", label: "Tweets", icon: createTimelineTypeIcon("tweets") },
  2276. { value: "with_replies", label: "Replies", icon: createTimelineTypeIcon("with_replies") },
  2277. ]
  2278.  
  2279. const timelineTypeToggle = createToggleSwitch(timelineTypeOptions, settings.timelineType, (value) => {
  2280. const newSettings = getSettings()
  2281. newSettings.timelineType = value
  2282. saveSettings(newSettings)
  2283. settings.timelineType = value
  2284. })
  2285.  
  2286. timelineTypeGroup.appendChild(timelineTypeLabel)
  2287. timelineTypeGroup.appendChild(timelineTypeToggle)
  2288.  
  2289. const mediaTypeGroup = document.createElement("div")
  2290. mediaTypeGroup.style.cssText = `
  2291. display: flex;
  2292. flex-direction: column;
  2293. gap: 8px;
  2294. `
  2295.  
  2296. const mediaTypeLabel = document.createElement("label")
  2297. mediaTypeLabel.textContent = "Media Type:"
  2298. mediaTypeLabel.style.cssText = `
  2299. font-size: 14px;
  2300. font-weight: bold;
  2301. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  2302. `
  2303.  
  2304. const mediaTypeIcons = createMediaTypeIcons()
  2305. const mediaTypeOptions = [
  2306. { value: "all", label: "All", icon: mediaTypeIcons.all },
  2307. { value: "image", label: "Image", icon: mediaTypeIcons.image },
  2308. { value: "video", label: "Video", icon: mediaTypeIcons.video },
  2309. { value: "gif", label: "GIF", icon: mediaTypeIcons.gif },
  2310. ]
  2311.  
  2312. const mediaTypeToggle = createToggleSwitch(mediaTypeOptions, settings.mediaType, (value) => {
  2313. const newSettings = getSettings()
  2314. newSettings.mediaType = value
  2315. saveSettings(newSettings)
  2316. settings.mediaType = value
  2317.  
  2318. const newMediaTypeLabel = getMediaTypeLabel(value).toLowerCase()
  2319. const newFetchButtonText =
  2320. value === "all"
  2321. ? "Fetch Media"
  2322. : `Fetch ${newMediaTypeLabel === "gif" ? "GIF" : newMediaTypeLabel.charAt(0).toUpperCase() + newMediaTypeLabel.slice(1)}`
  2323.  
  2324. fetchButton.innerHTML = ""
  2325. const newFetchIcon = fetchIcon.cloneNode(true)
  2326. fetchButton.appendChild(newFetchIcon)
  2327. fetchButton.appendChild(document.createTextNode(newFetchButtonText))
  2328.  
  2329. title.innerHTML = `Download ${getMediaTypeLabel(value)}: <span style="color: #0ea5e9">${username}</span>`
  2330. })
  2331.  
  2332. mediaTypeGroup.appendChild(mediaTypeLabel)
  2333. mediaTypeGroup.appendChild(mediaTypeToggle)
  2334.  
  2335. const concurrentGroup = document.createElement("div")
  2336. concurrentGroup.style.cssText = `
  2337. display: flex;
  2338. flex-direction: column;
  2339. gap: 8px;
  2340. `
  2341.  
  2342. const concurrentLabel = document.createElement("label")
  2343. concurrentLabel.style.cssText = `
  2344. font-size: 14px;
  2345. font-weight: bold;
  2346. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  2347. display: flex;
  2348. align-items: center;
  2349. `
  2350.  
  2351. const concurrentLabelText = document.createElement("span")
  2352. concurrentLabelText.textContent = "Batch Download Items:"
  2353. concurrentLabel.appendChild(concurrentLabelText)
  2354.  
  2355. const concurrentInfoIcon = createInfoIcon()
  2356. const concurrentTooltip = createInfoTooltip("Total item that are downloaded in a single request")
  2357. concurrentInfoIcon.addEventListener("mouseenter", concurrentTooltip.showTooltip)
  2358. concurrentInfoIcon.addEventListener("mouseleave", concurrentTooltip.hideTooltip)
  2359. concurrentLabel.appendChild(concurrentInfoIcon)
  2360. const concurrentToggle = document.createElement("div")
  2361. concurrentToggle.textContent = "Fixed to 50 concurrent downloads"
  2362. concurrentToggle.style.cssText = `
  2363. padding: 10px;
  2364. background-color: ${settings.darkTheme ? "#374151" : "#f1f5f9"};
  2365. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  2366. border-radius: 8px;
  2367. text-align: center;
  2368. `
  2369.  
  2370. concurrentGroup.appendChild(concurrentLabel)
  2371. concurrentGroup.appendChild(concurrentToggle)
  2372.  
  2373. const cacheDurationGroup = document.createElement("div")
  2374. cacheDurationGroup.style.cssText = `
  2375. display: flex;
  2376. flex-direction: column;
  2377. gap: 8px;
  2378. `
  2379.  
  2380. const cacheDurationLabel = document.createElement("label")
  2381. cacheDurationLabel.textContent = "Cache Duration:"
  2382. cacheDurationLabel.style.cssText = `
  2383. font-size: 14px;
  2384. font-weight: bold;
  2385. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  2386. `
  2387.  
  2388. const cacheDurationOptions = cacheDurations.map((duration) => {
  2389. let label = duration.toString() + "m"
  2390. if (duration >= 60 && duration % 60 === 0) {
  2391. label = `${duration / 60}h`
  2392. }
  2393. return { value: duration, label: label }
  2394. })
  2395.  
  2396. const cacheDurationToggle = createToggleSwitch(cacheDurationOptions, settings.cacheDuration, (value) => {
  2397. const newSettings = getSettings()
  2398. newSettings.cacheDuration = value
  2399. saveSettings(newSettings)
  2400. settings.cacheDuration = value
  2401. });
  2402. cacheDurationGroup.appendChild(cacheDurationLabel)
  2403. cacheDurationGroup.appendChild(cacheDurationToggle)
  2404.  
  2405. const darkThemeGroup = document.createElement("div")
  2406. darkThemeGroup.style.cssText = `
  2407. display: flex;
  2408. align-items: center;
  2409. gap: 8px;
  2410. `
  2411. const darkThemeLabel = document.createElement("label")
  2412. darkThemeLabel.style.cssText = `
  2413. font-size: 14px;
  2414. font-weight: bold;
  2415. color: ${settings.darkTheme ? "#f1f5f9" : "#334155"};
  2416. flex: 1;
  2417. display: flex;
  2418. align-items: center;
  2419. `
  2420. const darkThemeLabelText = document.createElement("span")
  2421. darkThemeLabelText.textContent = "Dark Theme:"
  2422. darkThemeLabel.appendChild(darkThemeLabelText)
  2423.  
  2424. const darkThemeToggle = document.createElement("div")
  2425. darkThemeToggle.style.cssText = `
  2426. position: relative;
  2427. width: 50px;
  2428. height: 24px;
  2429. background-color: ${settings.darkTheme ? "#22c55e" : "#cbd5e1"};
  2430. border-radius: 12px;
  2431. cursor: pointer;
  2432. transition: background-color 0.3s;
  2433. `
  2434.  
  2435. const darkThemeToggleHandle = document.createElement("div")
  2436. darkThemeToggleHandle.style.cssText = `
  2437. position: absolute;
  2438. top: 2px;
  2439. left: ${settings.darkTheme ? "28px" : "2px"};
  2440. width: 20px;
  2441. height: 20px;
  2442. background-color: white;
  2443. border-radius: 50%;
  2444. transition: left 0.3s;
  2445. `
  2446.  
  2447. darkThemeToggle.appendChild(darkThemeToggleHandle)
  2448. darkThemeToggle.addEventListener("click", () => {
  2449. const newSettings = getSettings()
  2450. newSettings.darkTheme = !newSettings.darkTheme
  2451. saveSettings(newSettings)
  2452. settings.darkTheme = newSettings.darkTheme
  2453. darkThemeToggle.style.backgroundColor = newSettings.darkTheme ? "#22c55e" : "#cbd5e1"
  2454. darkThemeToggleHandle.style.left = newSettings.darkTheme ? "28px" : "2px"
  2455. updateTheme()
  2456. })
  2457.  
  2458. darkThemeGroup.appendChild(darkThemeLabel)
  2459. darkThemeGroup.appendChild(darkThemeToggle)
  2460.  
  2461. const buttonsContainer = document.createElement("div")
  2462. buttonsContainer.style.cssText = `
  2463. display: flex;
  2464. gap: 16px;
  2465. margin-top: 16px;
  2466. width: 100%;
  2467. justify-content: center;
  2468. align-items: center;
  2469. `
  2470.  
  2471. const clearCacheButton = document.createElement("button")
  2472. const trashIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg")
  2473. trashIcon.setAttribute("xmlns", "http://www.w3.org/2000/svg")
  2474. trashIcon.setAttribute("viewBox", ICONS.CLEAR.VIEWBOX)
  2475. trashIcon.setAttribute("width", "16")
  2476. trashIcon.setAttribute("height", "16")
  2477. trashIcon.style.marginRight = "8px"
  2478.  
  2479. const trashPath = document.createElementNS("http://www.w3.org/2000/svg", "path")
  2480. trashPath.setAttribute("fill", "currentColor")
  2481. trashPath.setAttribute("d", ICONS.CLEAR.PATH)
  2482. trashIcon.appendChild(trashPath)
  2483. clearCacheButton.appendChild(trashIcon)
  2484. clearCacheButton.appendChild(document.createTextNode("Clear Cache"))
  2485. clearCacheButton.style.cssText = `
  2486. background-color: #ef4444;
  2487. color: white;
  2488. border: none;
  2489. border-radius: 6px;
  2490. padding: 8px 16px;
  2491. font-weight: bold;
  2492. cursor: pointer;
  2493. flex: 1;
  2494. display: flex;
  2495. align-items: center;
  2496. justify-content: center;
  2497. text-align: center;
  2498. transition: background-color 0.2s;
  2499. `
  2500.  
  2501. const resetDefaultButton = document.createElement("button")
  2502. const resetIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg")
  2503. resetIcon.setAttribute("xmlns", "http://www.w3.org/2000/svg")
  2504. resetIcon.setAttribute("viewBox", ICONS.RESET.VIEWBOX)
  2505. resetIcon.setAttribute("width", "16")
  2506. resetIcon.setAttribute("height", "16")
  2507. resetIcon.style.marginRight = "8px"
  2508.  
  2509. const resetPath = document.createElementNS("http://www.w3.org/2000/svg", "path")
  2510. resetPath.setAttribute("fill", "currentColor")
  2511. resetPath.setAttribute("d", ICONS.RESET.PATH)
  2512. resetIcon.appendChild(resetPath)
  2513.  
  2514. resetDefaultButton.appendChild(resetIcon)
  2515. resetDefaultButton.appendChild(document.createTextNode("Reset Default"))
  2516. resetDefaultButton.style.cssText = `
  2517. background-color: #6366f1;
  2518. color: white;
  2519. border: none;
  2520. border-radius: 6px;
  2521. padding: 8px 16px;
  2522. font-weight: bold;
  2523. cursor: pointer;
  2524. flex: 1;
  2525. display: flex;
  2526. align-items: center;
  2527. justify-content: center;
  2528. text-align: center;
  2529. transition: background-color 0.2s;
  2530. `
  2531. buttonsContainer.appendChild(clearCacheButton)
  2532. buttonsContainer.appendChild(resetDefaultButton)
  2533.  
  2534. clearCacheButton.addEventListener("mouseenter", () => {
  2535. clearCacheButton.style.backgroundColor = "#dc2626"
  2536. })
  2537. clearCacheButton.addEventListener("mouseleave", () => {
  2538. clearCacheButton.style.backgroundColor = "#ef4444"
  2539. })
  2540.  
  2541. resetDefaultButton.addEventListener("mouseenter", () => {
  2542. resetDefaultButton.style.backgroundColor = "#5b56f4"
  2543. })
  2544. resetDefaultButton.addEventListener("mouseleave", () => {
  2545. resetDefaultButton.style.backgroundColor = "#6366f1"
  2546. })
  2547. clearCacheButton.addEventListener("click", () => {
  2548. createConfirmDialog("Are you sure about clearing the cache?", () => {
  2549. cacheManager.clear()
  2550.  
  2551. createInfoDialog("Cache has been successfully cleared.", "Clear Successful");
  2552. });
  2553. });;
  2554.  
  2555. resetDefaultButton.addEventListener("click", () => {
  2556. createConfirmDialog("Are you sure you want to reset all settings to default values?", () => {
  2557. const currentSettings = getSettings()
  2558. const preservedPatreonAuth = currentSettings.patreonAuth
  2559. const preservedAuthToken = currentSettings.authToken
  2560.  
  2561. const resetSettings = { ...defaultSettings }
  2562. resetSettings.patreonAuth = preservedPatreonAuth
  2563. resetSettings.authToken = preservedAuthToken
  2564. saveSettings(resetSettings);
  2565.  
  2566. startingBatchInput.value = defaultSettings.startingBatch;
  2567.  
  2568. batchToggle.style.backgroundColor = defaultSettings.batchEnabled ? "#22c55e" : "#cbd5e1";
  2569. batchToggleHandle.style.left = defaultSettings.batchEnabled ? "28px" : "2px";
  2570.  
  2571. batchSizeGroup.style.display = defaultSettings.batchEnabled ? "flex" : "none";
  2572. startingBatchGroup.style.display = defaultSettings.batchEnabled ? "flex" : "none";
  2573. autoBatchGroup.style.display = defaultSettings.batchEnabled ? "flex" : "none";
  2574.  
  2575. patreonAuthClearButton.style.display = preservedPatreonAuth ? "block" : "none";
  2576. tokenClearButton.style.display = preservedAuthToken ? "block" : "none";
  2577.  
  2578. const timelineTypeOptions = ["media", "timeline", "tweets", "with_replies"];
  2579. const timelineTypeIndex = timelineTypeOptions.indexOf(defaultSettings.timelineType);
  2580. const timelineTypeSlider = timelineTypeToggle.querySelector("div:first-child");
  2581. const timelineTypeContainer = timelineTypeToggle.querySelector("div:last-child");
  2582.  
  2583. if (timelineTypeSlider && timelineTypeContainer && timelineTypeIndex !== -1) {
  2584. timelineTypeSlider.style.transform = `translateX(${timelineTypeIndex * 100}%)`;
  2585. timelineTypeContainer.querySelectorAll("div").forEach((opt, i) => {
  2586. opt.style.color = i === timelineTypeIndex ? "white" : "#64748b";
  2587. const optIcon = opt.querySelector("svg");
  2588. if (optIcon) {
  2589. const optPaths = optIcon.querySelectorAll("path");
  2590. optPaths.forEach((path) => {
  2591. path.setAttribute("fill", i === timelineTypeIndex ? "white" : "#64748b");
  2592. });
  2593. }
  2594. });
  2595. }
  2596.  
  2597. const mediaTypeOptions = ["all", "image", "video", "gif"];
  2598. const mediaTypeIndex = mediaTypeOptions.indexOf(defaultSettings.mediaType);
  2599. const mediaTypeSlider = mediaTypeToggle.querySelector("div:first-child");
  2600. const mediaTypeContainer = mediaTypeToggle.querySelector("div:last-child");
  2601.  
  2602. if (mediaTypeSlider && mediaTypeContainer && mediaTypeIndex !== -1) {
  2603. mediaTypeSlider.style.transform = `translateX(${mediaTypeIndex * 100}%)`;
  2604. mediaTypeContainer.querySelectorAll("div").forEach((opt, i) => {
  2605. opt.style.color = i === mediaTypeIndex ? "white" : "#64748b";
  2606. const optIcon = opt.querySelector("svg");
  2607. if (optIcon) {
  2608. const optPaths = optIcon.querySelectorAll("path");
  2609. optPaths.forEach((path) => {
  2610. path.setAttribute("fill", i === mediaTypeIndex ? "white" : "#64748b");
  2611. });
  2612. }
  2613. });
  2614. }
  2615.  
  2616. const batchSizeIndex = batchSizes.indexOf(defaultSettings.batchSize);
  2617. const batchSizeSlider = batchSizeToggle.querySelector("div:first-child");
  2618. const batchSizeContainer = batchSizeToggle.querySelector("div:last-child");
  2619.  
  2620. if (batchSizeSlider && batchSizeContainer && batchSizeIndex !== -1) {
  2621. batchSizeSlider.style.transform = `translateX(${batchSizeIndex * 100}%)`;
  2622. batchSizeContainer.querySelectorAll("div").forEach((opt, i) => {
  2623. opt.style.color = i === batchSizeIndex ? "white" : "#64748b";
  2624. const optIcon = opt.querySelector("svg");
  2625. if (optIcon) {
  2626. const optPaths = optIcon.querySelectorAll("path");
  2627. optPaths.forEach((path) => {
  2628. path.setAttribute("fill", i === batchSizeIndex ? "white" : "#64748b");
  2629. });
  2630. }
  2631. });
  2632. }
  2633.  
  2634. const cacheDurationIndex = cacheDurations.indexOf(defaultSettings.cacheDuration);
  2635. const cacheDurationSlider = cacheDurationToggle.querySelector("div:first-child");
  2636. const cacheDurationContainer = cacheDurationToggle.querySelector("div:last-child");
  2637.  
  2638. if (cacheDurationSlider && cacheDurationContainer && cacheDurationIndex !== -1) {
  2639. cacheDurationSlider.style.transform = `translateX(${cacheDurationIndex * 100}%)`;
  2640. cacheDurationContainer.querySelectorAll("div").forEach((opt, i) => {
  2641. opt.style.color = i === cacheDurationIndex ? "white" : "#64748b";
  2642. const optIcon = opt.querySelector("svg");
  2643. if (optIcon) {
  2644. const optPaths = optIcon.querySelectorAll("path");
  2645. optPaths.forEach((path) => {
  2646. path.setAttribute("fill", i === cacheDurationIndex ? "white" : "#64748b");
  2647. });
  2648. }
  2649. });
  2650. }
  2651. const apiServerOptions = ["default", "backup"];
  2652. const apiServerIndex = apiServerOptions.indexOf(defaultSettings.apiServer);
  2653. const apiServerSlider = apiServerToggle.querySelector("div:first-child");
  2654. const apiServerContainer = apiServerToggle.querySelector("div:last-child");
  2655.  
  2656. if (apiServerSlider && apiServerContainer && apiServerIndex !== -1) {
  2657. apiServerSlider.style.transform = `translateX(${apiServerIndex * 100}%)`;
  2658. apiServerContainer.querySelectorAll("div").forEach((opt, i) => {
  2659. opt.style.color = i === apiServerIndex ? "white" : "#64748b";
  2660. const optIcon = opt.querySelector("svg");
  2661. if (optIcon) {
  2662. const optPaths = optIcon.querySelectorAll("path");
  2663. optPaths.forEach((path) => {
  2664. path.setAttribute("fill", i === apiServerIndex ? "white" : "#64748b");
  2665. });
  2666. }
  2667. });
  2668. }
  2669.  
  2670. darkThemeToggle.style.backgroundColor = defaultSettings.darkTheme ? "#22c55e" : "#cbd5e1";
  2671. darkThemeToggleHandle.style.left = defaultSettings.darkTheme ? "28px" : "2px";
  2672. settings.darkTheme = defaultSettings.darkTheme;
  2673. updateTheme();
  2674.  
  2675. const newMediaTypeLabel = getMediaTypeLabel(defaultSettings.mediaType).toLowerCase();
  2676. const newFetchButtonText = defaultSettings.mediaType === "all"
  2677. ? "Fetch Media"
  2678. : `Fetch ${newMediaTypeLabel === "gif" ? "GIF" : newMediaTypeLabel.charAt(0).toUpperCase() + newMediaTypeLabel.slice(1)}`;
  2679. fetchButton.innerHTML = "";
  2680. const newFetchIcon = fetchIcon.cloneNode(true)
  2681. fetchButton.appendChild(newFetchIcon)
  2682. fetchButton.appendChild(document.createTextNode(newFetchButtonText))
  2683. title.innerHTML = `Download ${getMediaTypeLabel(defaultSettings.mediaType)}: <span style="color: #0ea5e9">${username}</span>`;
  2684.  
  2685. setTimeout(() => {
  2686. createInfoDialog("Settings have been successfully reset to default values.", "Reset Successful");
  2687. }, 100);
  2688. })
  2689. })
  2690.  
  2691. const patreonLink = document.createElement("a")
  2692. patreonLink.href = "https://www.patreon.com/exyezed"
  2693. patreonLink.target = "_blank";
  2694. patreonLink.style.cssText = `
  2695. display: flex;
  2696. align-items: center;
  2697. justify-content: center;
  2698. color: #64748b;
  2699. text-decoration: none;
  2700. margin-top: 16px;
  2701. padding: 8px;
  2702. border-radius: 8px;
  2703. transition: background-color 0.2s, color 0.2s;
  2704. `;
  2705. patreonLink.innerHTML = createPatreonIcon().outerHTML + "Patreon Authentication";
  2706. patreonLink.addEventListener("mouseenter", () => {
  2707. patreonLink.style.backgroundColor = settings.darkTheme ? "#374151" : "#f1f5f9";
  2708. patreonLink.style.color = "#0ea5e9";
  2709. });
  2710. patreonLink.addEventListener("mouseleave", () => {
  2711. patreonLink.style.backgroundColor = "transparent";
  2712. patreonLink.style.color = "#64748b";
  2713. });
  2714. const batchSizeStartingContainer = document.createElement("div")
  2715. batchSizeStartingContainer.style.cssText = `
  2716. display: flex;
  2717. flex-direction: column;
  2718. gap: 0px;
  2719. `
  2720. batchSizeStartingContainer.appendChild(batchSizeGroup)
  2721. batchSizeStartingContainer.appendChild(startingBatchGroup)
  2722. const mediaTimelineContainer = document.createElement("div")
  2723. mediaTimelineContainer.style.cssText = `
  2724. display: flex;
  2725. flex-direction: column;
  2726. gap: 0px;
  2727. `
  2728. mediaTimelineContainer.appendChild(mediaTypeGroup)
  2729. mediaTimelineContainer.appendChild(timelineTypeGroup)
  2730. fetchTabContent.appendChild(batchGroup);
  2731. fetchTabContent.appendChild(autoBatchGroup);
  2732. fetchTabContent.appendChild(batchSizeStartingContainer);
  2733. fetchTabContent.appendChild(mediaTimelineContainer);
  2734.  
  2735. authTabContent.appendChild(patreonAuthGroup);
  2736. authTabContent.appendChild(tokenGroup);
  2737. authTabContent.appendChild(patreonLink);
  2738.  
  2739. advancedTabContent.appendChild(darkThemeGroup);
  2740. apiServerGroup.style.marginTop = '16px';
  2741. advancedTabContent.appendChild(apiServerGroup);
  2742. cacheDurationGroup.style.marginTop = '0px';
  2743. advancedTabContent.appendChild(cacheDurationGroup);
  2744. buttonsContainer.style.marginTop = '16px';
  2745. advancedTabContent.appendChild(buttonsContainer);
  2746. function switchTab(activeTab, activeContent) {
  2747. const allTabs = [fetchTab, authTab, advancedTab];
  2748. const allContents = [fetchTabContent, authTabContent, advancedTabContent];
  2749.  
  2750. allTabs.forEach(tab => {
  2751. if (tab && tab.style) {
  2752. tab.style.color = "#64748b";
  2753. tab.style.borderBottom = "none";
  2754. }
  2755. });
  2756.  
  2757. allContents.forEach(content => {
  2758. if (content && content.style) {
  2759. content.style.display = "none";
  2760. }
  2761. });
  2762.  
  2763. if (activeTab && activeTab.style) {
  2764. activeTab.style.color = settings.darkTheme ? "#f1f5f9" : "#0f172a";
  2765. activeTab.style.borderBottom = "2px solid #0ea5e9";
  2766. }
  2767. if (activeContent && activeContent.style) {
  2768. activeContent.style.display = "flex";
  2769. }
  2770. }
  2771. fetchTab.addEventListener("click", function() {
  2772. switchTab(fetchTab, fetchTabContent);
  2773. });
  2774. authTab.addEventListener("click", function() {
  2775. switchTab(authTab, authTabContent);
  2776. });
  2777. advancedTab.addEventListener("click", function() {
  2778. switchTab(advancedTab, advancedTabContent);
  2779. });
  2780.  
  2781. const settingsForm = document.createElement("div");
  2782. settingsForm.style.cssText = `
  2783. display: flex;
  2784. flex-direction: column;
  2785. `;
  2786. settingsForm.appendChild(settingsTabs);
  2787. settingsForm.appendChild(fetchTabContent);
  2788. settingsForm.appendChild(authTabContent);
  2789. settingsForm.appendChild(advancedTabContent);
  2790.  
  2791. settingsContent.appendChild(settingsForm);
  2792.  
  2793. mainTab.addEventListener("click", function() {
  2794. mainTab.style.borderBottom = "2px solid #0ea5e9"
  2795. mainTab.style.color = settings.darkTheme ? "#f1f5f9" : "#0f172a"
  2796. settingsTab.style.borderBottom = "none"
  2797. settingsTab.style.color = "#64748b"
  2798. mainContent.style.display = "block"
  2799. settingsContent.style.display = "none"
  2800. });
  2801.  
  2802. settingsTab.addEventListener("click", function() {
  2803. settingsTab.style.borderBottom = "2px solid #0ea5e9"
  2804. settingsTab.style.color = settings.darkTheme ? "#f1f5f9" : "#0f172a"
  2805. mainTab.style.borderBottom = "none"
  2806. mainTab.style.color = "#64748b"
  2807. settingsContent.style.display = "block"
  2808. mainContent.style.display = "none"
  2809.  
  2810. switchTab(fetchTab, fetchTabContent);
  2811. });
  2812.  
  2813. modalContent.appendChild(header)
  2814. modalContent.appendChild(tabs)
  2815. modalContent.appendChild(mainContent)
  2816. modalContent.appendChild(settingsContent)
  2817. modal.appendChild(modalContent);
  2818.  
  2819. const mediaData = {
  2820. username: username,
  2821. currentPage: getSettings().startingBatch,
  2822. mediaItems: [],
  2823. allMediaItems: [],
  2824. batchData: {},
  2825. hasMore: false,
  2826. downloading: false,
  2827. totalDownloaded: 0,
  2828. totalToDownload: 0,
  2829. totalItems: 0,
  2830. nextBatchClicked: false,
  2831. }
  2832.  
  2833. function refreshInfoDisplays() {
  2834. const isDark = getSettings().darkTheme
  2835.  
  2836. if (infoContainer.innerHTML && mediaData.totalItems > 0) {
  2837. const settings = getSettings()
  2838. const mediaTypeLabel = getMediaTypeLabel(settings.mediaType)
  2839.  
  2840. if (settings.batchEnabled && mediaData.mediaItems && mediaData.mediaItems.length > 0) {
  2841. const accountIconHtml = createAccountIcon(isDark).outerHTML
  2842. const mediaIconHtml = createMediaTypeIcon(settings.mediaType, isDark).outerHTML
  2843. const totalItemsIconHtml = createTotalItemsIcon(isDark).outerHTML
  2844.  
  2845. infoContainer.innerHTML = `
  2846. <div style="margin-bottom: 8px; display: flex; align-items: center;">${accountIconHtml}<strong style="margin-right: 6px;">Account:</strong><span>${mediaData.username}</span></div>
  2847. <div style="margin-bottom: 8px; display: flex; align-items: center;">${mediaIconHtml}<strong style="margin-right: 6px;">${mediaTypeLabel} Found:</strong><span>${formatNumber(mediaData.totalItems)}</span></div>
  2848. <div style="margin-bottom: 8px; display: flex; align-items: center;">${totalItemsIconHtml}<strong style="margin-right: 6px;">Total Items:</strong><span>${formatNumber(mediaData.allMediaItems.length)}</span></div>
  2849. `
  2850. } else if (mediaData.allMediaItems && mediaData.allMediaItems.length > 0) {
  2851. const accountIconHtml = createAccountIcon(isDark).outerHTML
  2852. const mediaIconHtml = createMediaTypeIcon(settings.mediaType, isDark).outerHTML
  2853. const totalZipIconHtml = createTotalZipIcon(isDark).outerHTML
  2854. const currentPart = Math.floor(mediaData.allMediaItems.length / 500) + 1
  2855.  
  2856. infoContainer.innerHTML = `
  2857. <div style="margin-bottom: 8px; display: flex; align-items: center;">${accountIconHtml}<strong style="margin-right: 6px;">Account:</strong><span>${mediaData.username}</span></div>
  2858. <div style="margin-bottom: 8px; display: flex; align-items: center;">${mediaIconHtml}<strong style="margin-right: 6px;">${mediaTypeLabel} Found:</strong><span>${formatNumber(mediaData.totalItems)}</span></div>
  2859. <div style="margin-top: 8px; display: flex; align-items: center;">${totalZipIconHtml}<strong style="margin-right: 6px;">Total ZIP ${currentPart === 1 ? 'File' : 'Files'}:</strong><span>${currentPart}</span></div>
  2860. `
  2861. }
  2862. }
  2863.  
  2864. if (infoContainer.innerHTML) {
  2865. const accountIcons = infoContainer.querySelectorAll('svg[viewBox="0 0 24 24"]')
  2866. accountIcons.forEach(icon => {
  2867. icon.style.color = isDark ? "#ffffff" : "#64748b"
  2868. })
  2869.  
  2870. const mediaIcons = infoContainer.querySelectorAll('svg[viewBox="0 0 576 512"], svg[viewBox="0 0 512 512"], svg[viewBox="0 0 640 512"]')
  2871. mediaIcons.forEach(icon => {
  2872. icon.style.color = isDark ? "#ffffff" : "#64748b"
  2873. })
  2874.  
  2875. const totalIcons = infoContainer.querySelectorAll('svg[viewBox="0 0 448 512"]')
  2876. totalIcons.forEach(icon => {
  2877. icon.style.color = isDark ? "#ffffff" : "#64748b"
  2878. })
  2879. }
  2880. }
  2881.  
  2882. function updateBatchLabels() {
  2883. const isDark = getSettings().darkTheme
  2884. const settings = getSettings()
  2885.  
  2886. if (currentBatchLabel && currentBatchLabel.innerHTML) {
  2887. const currentBatchIconHtml = createCurrentBatchIcon(isDark).outerHTML
  2888. currentBatchLabel.innerHTML = `<div style="display: flex; align-items: center;">${currentBatchIconHtml}<strong style="margin-right: 6px; color: ${settings.darkTheme ? '#ffffff' : '#475569'};">Current Batch:</strong><span style="color: ${settings.darkTheme ? '#ffffff' : '#475569'};">${mediaData.currentPage + 1}</span></div>`
  2889. }
  2890.  
  2891. if (totalBatchLabel && totalBatchLabel.innerHTML && mediaData.totalItems > 0) {
  2892. const totalBatches = Math.ceil(mediaData.totalItems / settings.batchSize)
  2893. const totalZipIconHtml = createTotalZipIcon(isDark).outerHTML
  2894. totalBatchLabel.innerHTML = `<div style="display: flex; align-items: center;">${totalZipIconHtml}<strong style="margin-right: 6px; color: ${settings.darkTheme ? '#ffffff' : '#475569'};">Total ZIP ${totalBatches === 1 ? 'File' : 'Files'}:</strong><span style="color: ${settings.darkTheme ? '#ffffff' : '#475569'};">${totalBatches}</span></div>`
  2895. }
  2896.  
  2897. if (currentBatchLabel && currentBatchLabel.innerHTML) {
  2898. const batchIcons = currentBatchLabel.querySelectorAll('svg')
  2899. batchIcons.forEach(icon => {
  2900. icon.style.color = isDark ? "#ffffff" : "#64748b"
  2901. })
  2902. }
  2903.  
  2904. if (totalBatchLabel && totalBatchLabel.innerHTML) {
  2905. const zipIcons = totalBatchLabel.querySelectorAll('svg')
  2906. zipIcons.forEach(icon => {
  2907. icon.style.color = isDark ? "#ffffff" : "#64748b"
  2908. })
  2909. }
  2910. }
  2911.  
  2912. function updateTheme() {
  2913. const isDark = getSettings().darkTheme
  2914. modalContent.style.backgroundColor = isDark ? "#1f2937" : "#ffffff"
  2915. modalContent.style.color = isDark ? "#f1f5f9" : "#334155"
  2916. header.style.borderBottom = `1px solid ${isDark ? "#374151" : "#e2e8f0"}`
  2917. title.style.color = isDark ? "#f1f5f9" : "#334155"
  2918. closeButton.style.color = isDark ? "#f1f5f9" : "#0f172a"
  2919. tabs.style.borderBottom = `1px solid ${isDark ? "#374151" : "#e2e8f0"}`
  2920. mainTab.style.color = mainContent.style.display === "block" ? (isDark ? "#f1f5f9" : "#0f172a") : "#64748b"
  2921. settingsTab.style.color = settingsContent.style.display === "block" ? (isDark ? "#f1f5f9" : "#0f172a") : "#64748b"
  2922. infoContainer.style.backgroundColor = isDark ? "#374151" : "#f1f5f9"
  2923. batchInfoContainer.style.backgroundColor = isDark ? "#374151" : "#f8fafc"
  2924. batchInfoContainer.style.border = `1px solid ${isDark ? "#4b5563" : "#e2e8f0"}`
  2925. settingsTabs.style.borderBottom = `1px solid ${isDark ? "#374151" : "#e2e8f0"}`
  2926.  
  2927. const allSettingTabs = [fetchTab, authTab, advancedTab]
  2928. allSettingTabs.forEach(tab => {
  2929. if (tab.style.borderBottom.includes("solid")) {
  2930. tab.style.color = isDark ? "#f1f5f9" : "#0f172a"
  2931. }
  2932. })
  2933. patreonAuthLabel.style.color = isDark ? "#f1f5f9" : "#334155"
  2934. patreonAuthInput.style.backgroundColor = isDark ? "#374151" : "#f1f5f9"
  2935. autoBatchLabel.style.color = isDark ? "#f1f5f9" : "#334155"
  2936. patreonAuthInput.style.color = isDark ? "#cbd5e1" : "#64748b"
  2937. tokenLabel.style.color = isDark ? "#f1f5f9" : "#334155"
  2938. tokenInput.style.backgroundColor = isDark ? "#374151" : "#f1f5f9"
  2939. tokenInput.style.color = isDark ? "#cbd5e1" : "#64748b"
  2940. apiServerLabel.style.color = isDark ? "#f1f5f9" : "#334155"
  2941. batchLabel.style.color = isDark ? "#f1f5f9" : "#334155"
  2942. batchSizeLabel.style.color = isDark ? "#f1f5f9" : "#334155"
  2943. startingBatchLabel.style.color = isDark ? "#f1f5f9" : "#334155"
  2944. startingBatchInput.style.backgroundColor = isDark ? "#374151" : "#f1f5f9"
  2945. startingBatchInput.style.color = isDark ? "#cbd5e1" : "#64748b"
  2946. timelineTypeLabel.style.color = isDark ? "#f1f5f9" : "#334155"
  2947. mediaTypeLabel.style.color = isDark ? "#f1f5f9" : "#334155"
  2948. concurrentLabel.style.color = isDark ? "#f1f5f9" : "#334155"
  2949. cacheDurationLabel.style.color = isDark ? "#f1f5f9" : "#334155"
  2950. darkThemeLabel.style.color = isDark ? "#f1f5f9" : "#334155"
  2951. const toggleSwitches = [timelineTypeToggle, mediaTypeToggle, batchSizeToggle, concurrentToggle, cacheDurationToggle, apiServerToggle]
  2952. toggleSwitches.forEach(toggle => {
  2953. if (toggle) {
  2954. toggle.style.backgroundColor = isDark ? "#374151" : "#f1f5f9"
  2955. }
  2956. })
  2957.  
  2958. if (progressBar) {
  2959. progressBar.style.backgroundColor = isDark ? "#374151" : "#f1f5f9"
  2960. }
  2961.  
  2962. if (currentBatchLabel) {
  2963. currentBatchLabel.style.color = isDark ? "#ffffff" : "#475569"
  2964. }
  2965. if (totalBatchLabel) {
  2966. totalBatchLabel.style.color = isDark ? "#ffffff" : "#475569"
  2967. }
  2968.  
  2969. refreshInfoDisplays()
  2970.  
  2971. updateBatchLabels()
  2972. }
  2973.  
  2974. fetchButton.addEventListener("click", async () => {
  2975. const settings = getSettings()
  2976. if (!settings.authToken) {
  2977. createAuthTokenPopup()
  2978. return
  2979. }
  2980. if (!settings.patreonAuth) {
  2981. createPatreonAuthPopup()
  2982. return
  2983. }
  2984. if (settings.autoBatchEnabled && !autoBatchStarted) {
  2985. autoBatchCancelled = false
  2986. autoBatchStarted = true
  2987. const batchNums = Object.keys(mediaData.batchData).map(Number)
  2988. mediaData.currentPage = batchNums.length > 0 ? Math.max(...batchNums) + 1 : 0
  2989. }
  2990. if (!settings.autoBatchEnabled || (settings.autoBatchEnabled && !autoBatchStarted && Object.keys(mediaData.batchData).length === 0)) {
  2991. infoContainer.style.display = "none"
  2992. buttonContainer.style.display = "none"
  2993. nextBatchButton.style.display = "none"
  2994. prevBatchButton.style.display = "none"
  2995. progressContainer.style.display = "none"
  2996. if (settings.autoBatchEnabled) {
  2997. autoBatchStarted = true
  2998. mediaData.currentPage = 0
  2999. }
  3000. }
  3001. fetchButton.disabled = true
  3002. fetchButton.innerHTML = ""
  3003. fetchButton.appendChild(document.createTextNode("Fetching..."))
  3004.  
  3005. try {
  3006. const cacheKey = `${settings.timelineType}_${settings.mediaType}_${username}_${mediaData.currentPage}_${settings.batchSize}_batch_${settings.batchEnabled}`
  3007. let data = cacheManager.get(cacheKey)
  3008.  
  3009. if (!data) {
  3010. let url
  3011. if (settings.batchEnabled) {
  3012. url = `${getServiceBaseUrl()}/metadata/${settings.timelineType}/${settings.batchSize}/${mediaData.currentPage}/${settings.mediaType}/${username}/${settings.authToken}/${settings.patreonAuth || ""}`
  3013. } else {
  3014. url = `${getServiceBaseUrl()}/metadata/${settings.timelineType}/${settings.mediaType}/${username}/${settings.authToken}/${settings.patreonAuth || ""}`
  3015. }
  3016.  
  3017. data = await fetchData(url)
  3018. if (data && data.timeline && data.timeline.length > 0) {
  3019. cacheManager.set(cacheKey, data, true)
  3020. }
  3021. }
  3022. if (data.timeline && data.timeline.length > 0) {
  3023. mediaData.mediaItems = data.timeline
  3024. mediaData.hasMore = data.metadata.has_more
  3025. mediaData.totalItems = data.total_urls
  3026.  
  3027. mediaData.batchData[mediaData.currentPage] = [...data.timeline]
  3028.  
  3029. const currentBatchKeys = Object.keys(mediaData.batchData).map(Number)
  3030. for (const batchNum of currentBatchKeys) {
  3031. if (batchNum > mediaData.currentPage) {
  3032. delete mediaData.batchData[batchNum]
  3033. }
  3034. }
  3035. mediaData.allMediaItems = []
  3036. const maxBatch = Math.max(...Object.keys(mediaData.batchData).map(Number))
  3037. for (let i = 0; i <= maxBatch; i++) {
  3038. if (mediaData.batchData[i]) {
  3039. mediaData.allMediaItems = [...mediaData.allMediaItems, ...mediaData.batchData[i]]
  3040. }
  3041. }
  3042.  
  3043. const mediaTypeLabel = getMediaTypeLabel(settings.mediaType)
  3044.  
  3045. if (settings.batchEnabled) {
  3046. const accountIconHtml = createAccountIcon(settings.darkTheme).outerHTML
  3047. const mediaIconHtml = createMediaTypeIcon(settings.mediaType, settings.darkTheme).outerHTML
  3048. const totalItemsIconHtml = createTotalItemsIcon(settings.darkTheme).outerHTML
  3049. infoContainer.innerHTML = `
  3050. <div style="margin-bottom: 8px; display: flex; align-items: center;">${accountIconHtml}<strong style="margin-right: 6px;">Account:</strong><span>${data.account_info.name}</span></div>
  3051. <div style="margin-bottom: 8px; display: flex; align-items: center;">${mediaIconHtml}<strong style="margin-right: 6px;">${mediaTypeLabel} Found:</strong><span>${formatNumber(data.total_urls)}</span></div>
  3052. <div style="margin-bottom: 8px; display: flex; align-items: center;">${totalItemsIconHtml}<strong style="margin-right: 6px;">Total Items:</strong><span>${formatNumber(mediaData.allMediaItems.length)}</span></div>
  3053. `
  3054. const currentBatchIconHtml = createCurrentBatchIcon(settings.darkTheme).outerHTML
  3055. currentBatchLabel.innerHTML = `<div style="display: flex; align-items: center;">${currentBatchIconHtml}<strong style="margin-right: 6px; color: ${settings.darkTheme ? '#ffffff' : '#475569'};">Current Batch:</strong><span style="color: ${settings.darkTheme ? '#ffffff' : '#475569'};">${mediaData.currentPage + 1}</span></div>`
  3056.  
  3057. const totalBatches = Math.ceil(data.total_urls / settings.batchSize)
  3058. const totalZipIconHtml = createTotalZipIcon(settings.darkTheme).outerHTML
  3059. totalBatchLabel.innerHTML = `<div style="display: flex; align-items: center;">${totalZipIconHtml}<strong style="margin-right: 6px; color: ${settings.darkTheme ? '#ffffff' : '#475569'};">Total ZIP ${totalBatches === 1 ? 'File' : 'Files'}:</strong><span style="color: ${settings.darkTheme ? '#ffffff' : '#475569'};">${totalBatches}</span></div>`
  3060. batchInfoContainer.style.display = "flex"
  3061. batchNavContainer.style.display = "flex"
  3062. } else {
  3063. const currentPart = Math.floor(mediaData.allMediaItems.length / 500) + 1
  3064. const accountIconHtml = createAccountIcon(settings.darkTheme).outerHTML
  3065. const mediaIconHtml = createMediaTypeIcon(settings.mediaType, settings.darkTheme).outerHTML
  3066. const totalZipIconHtml = createTotalZipIcon(settings.darkTheme).outerHTML
  3067. infoContainer.innerHTML = `
  3068. <div style="margin-bottom: 8px; display: flex; align-items: center;">${accountIconHtml}<strong style="margin-right: 6px;">Account:</strong><span>${data.account_info.name}</span></div>
  3069. <div style="margin-bottom: 8px; display: flex; align-items: center;">${mediaIconHtml}<strong style="margin-right: 6px;">${mediaTypeLabel} Found:</strong><span>${formatNumber(data.total_urls)}</span></div>
  3070. <div style="margin-top: 8px; display: flex; align-items: center;">${totalZipIconHtml}<strong style="margin-right: 6px;">Total ZIP ${currentPart === 1 ? 'File' : 'Files'}:</strong><span>${currentPart}</span></div>
  3071. `
  3072.  
  3073. batchInfoContainer.style.display = "none"
  3074. batchNavContainer.style.display = "none"
  3075. }
  3076.  
  3077. infoContainer.style.display = "block"
  3078.  
  3079. if (settings.batchEnabled) {
  3080. buttonContainer.style.display = "none"
  3081. } else {
  3082. buttonContainer.innerHTML = ""
  3083. buttonContainer.appendChild(downloadButton)
  3084. buttonContainer.style.display = "block"
  3085. }
  3086. if (settings.batchEnabled && mediaData.hasMore) {
  3087. nextBatchButton.style.display = "block"
  3088. }
  3089. if (settings.batchEnabled && mediaData.currentPage > getSettings().startingBatch) {
  3090. prevBatchButton.style.display = "block"
  3091. }
  3092.  
  3093. reassignDownloadHandlers()
  3094.  
  3095. fetchButton.disabled = false
  3096. const currentMediaTypeLabel = getMediaTypeLabel(settings.mediaType).toLowerCase()
  3097.  
  3098. const updatedFetchButtonText =
  3099. settings.autoBatchEnabled
  3100. ? "Auto Fetch"
  3101. : (settings.mediaType === "all"
  3102. ? "Fetch Media"
  3103. : `Fetch ${currentMediaTypeLabel === "gif" ? "GIF" : currentMediaTypeLabel.charAt(0).toUpperCase() + currentMediaTypeLabel.slice(1)}`)
  3104.  
  3105. fetchButton.innerHTML = ""
  3106. let updatedFetchIcon1 = fetchIcon.cloneNode(true)
  3107. fetchButton.appendChild(updatedFetchIcon1)
  3108. fetchButton.appendChild(document.createTextNode(updatedFetchButtonText))
  3109.  
  3110. console.log('Fetch success - Next Batch Debug:', {
  3111. hasMore: mediaData.hasMore,
  3112. nextBatchClicked: mediaData.nextBatchClicked,
  3113. shouldShowPopup: !mediaData.hasMore && mediaData.nextBatchClicked,
  3114. autoBatchEnabled: settings.autoBatchEnabled
  3115. });
  3116.  
  3117. if (!mediaData.hasMore && mediaData.nextBatchClicked && !settings.autoBatchEnabled) {
  3118. console.log('Showing next batch completion popup after successful fetch');
  3119. createInfoDialog("Next batch has completed! All available batches have been fetched.");
  3120. }
  3121.  
  3122. if (mediaData.nextBatchClicked) {
  3123. console.log('Resetting nextBatchClicked flag after successful fetch');
  3124. mediaData.nextBatchClicked = false;
  3125. }
  3126.  
  3127. if (settings.autoBatchEnabled && !autoBatchCancelled) {
  3128. prevBatchButton.style.display = "none"
  3129. nextBatchButton.style.display = "none"
  3130. stopFetchButton.style.display = "block"
  3131. if (mediaData.hasMore) {
  3132. setTimeout(() => {
  3133. if (settings.autoBatchEnabled && !autoBatchCancelled) {
  3134. mediaData.currentPage++
  3135. fetchButton.click()
  3136. }
  3137. }, 1000)
  3138. } else {
  3139. stopFetchButton.style.display = "none"
  3140. prevBatchButton.style.display = mediaData.currentPage > 0 ? "block" : "none"
  3141. nextBatchButton.style.display = "none"
  3142. autoBatchStarted = false
  3143.  
  3144. createInfoDialog("Auto fetch has completed! All available batches have been fetched.")
  3145. }
  3146. }
  3147. } else {
  3148. console.log('No media found branch:', {
  3149. nextBatchClicked: mediaData.nextBatchClicked
  3150. });
  3151.  
  3152. if (mediaData.nextBatchClicked) {
  3153. console.log('Showing next batch completion popup from no media found branch');
  3154. createInfoDialog("Next batch has completed! All available batches have been fetched.");
  3155. mediaData.nextBatchClicked = false;
  3156. }
  3157.  
  3158. infoContainer.innerHTML = '<div style="color: #ef4444;">No media found, invalid token, or invalid Patreon authentication.</div>'
  3159. infoContainer.style.display = "block"
  3160. fetchButton.disabled = false
  3161. const currentMediaTypeLabel = getMediaTypeLabel(settings.mediaType).toLowerCase()
  3162. const updatedFetchButtonText =
  3163. settings.mediaType === "all"
  3164. ? "Fetch Media"
  3165. : `Fetch ${currentMediaTypeLabel === "gif" ? "GIF" : currentMediaTypeLabel.charAt(0).toUpperCase() + currentMediaTypeLabel.slice(1)}`
  3166.  
  3167. fetchButton.innerHTML = ""
  3168. let updatedFetchIcon2 = fetchIcon.cloneNode(true)
  3169. fetchButton.appendChild(updatedFetchIcon2)
  3170. fetchButton.appendChild(document.createTextNode(updatedFetchButtonText))
  3171. }
  3172. } catch (error) {
  3173. infoContainer.innerHTML = `<div style="color: #ef4444;">Error: ${error.message}</div>`
  3174. infoContainer.style.display = "block"
  3175. fetchButton.disabled = false
  3176.  
  3177. if (mediaData.currentPage > getSettings().startingBatch) {
  3178. prevBatchButton.style.display = "block"
  3179. }
  3180.  
  3181. const currentMediaTypeLabel = getMediaTypeLabel(settings.mediaType).toLowerCase()
  3182.  
  3183. const updatedFetchButtonText =
  3184. settings.mediaType === "all"
  3185. ? "Fetch Media"
  3186. : `Fetch ${currentMediaTypeLabel === "gif" ? "GIF" : currentMediaTypeLabel.charAt(0).toUpperCase() + currentMediaTypeLabel.slice(1)}`
  3187.  
  3188. fetchButton.innerHTML = ""
  3189. let updatedFetchIcon3 = fetchIcon.cloneNode(true)
  3190. fetchButton.appendChild(updatedFetchIcon3)
  3191. fetchButton.appendChild(document.createTextNode(updatedFetchButtonText))
  3192. }
  3193. });
  3194.  
  3195. nextBatchButton.addEventListener("click", () => {
  3196. console.log('Next Batch Button clicked, setting flag to true');
  3197. mediaData.nextBatchClicked = true;
  3198. mediaData.currentPage++
  3199.  
  3200. autoBatchCancelled = true
  3201. autoBatchStarted = false
  3202.  
  3203. const settings = getSettings()
  3204. const cacheKey = `${settings.timelineType}_${settings.mediaType}_${username}_${mediaData.currentPage}_${settings.batchSize}_batch_${settings.batchEnabled}`
  3205. const cachedData = cacheManager.get(cacheKey)
  3206.  
  3207. if (cachedData && cachedData.timeline && cachedData.timeline.length > 0) {
  3208. mediaData.mediaItems = cachedData.timeline
  3209. mediaData.hasMore = cachedData.metadata.has_more
  3210. mediaData.totalItems = cachedData.total_urls
  3211.  
  3212. mediaData.batchData[mediaData.currentPage] = [...cachedData.timeline]
  3213.  
  3214. mediaData.allMediaItems = []
  3215. const maxBatch = Math.max(...Object.keys(mediaData.batchData).map(Number))
  3216. for (let i = 0; i <= maxBatch; i++) {
  3217. if (mediaData.batchData[i]) {
  3218. mediaData.allMediaItems = [...mediaData.allMediaItems, ...mediaData.batchData[i]]
  3219. }
  3220. }
  3221.  
  3222. refreshInfoDisplays()
  3223.  
  3224. if (settings.batchEnabled) {
  3225. prevBatchButton.style.display = mediaData.currentPage > 0 ? "block" : "none"
  3226. nextBatchButton.style.display = mediaData.hasMore ? "block" : "none"
  3227. infoContainer.style.display = "block"
  3228. buttonContainer.style.display = "none"
  3229. batchInfoContainer.style.display = "flex"
  3230. batchNavContainer.style.display = "flex"
  3231. }
  3232.  
  3233. const currentBatchIconHtml = createCurrentBatchIcon(settings.darkTheme).outerHTML
  3234. currentBatchLabel.innerHTML = `<div style="display: flex; align-items: center;">${currentBatchIconHtml}<strong style="margin-right: 6px; color: ${settings.darkTheme ? '#ffffff' : '#475569'};">Current Batch:</strong><span style="color: ${settings.darkTheme ? '#ffffff' : '#475569'};">${mediaData.currentPage + 1}</span></div>`
  3235. const totalBatches = Math.ceil(cachedData.total_urls / settings.batchSize)
  3236. const totalZipIconHtml = createTotalZipIcon(settings.darkTheme).outerHTML
  3237. totalBatchLabel.innerHTML = `<div style="display: flex; align-items: center;">${totalZipIconHtml}<strong style="margin-right: 6px; color: ${settings.darkTheme ? '#ffffff' : '#475569'};">Total ZIP ${totalBatches === 1 ? 'File' : 'Files'}:</strong><span style="color: ${settings.darkTheme ? '#ffffff' : '#475569'};">${totalBatches}</span></div>`
  3238. console.log('Next Batch Debug:', {
  3239. hasMore: mediaData.hasMore,
  3240. nextBatchClicked: mediaData.nextBatchClicked,
  3241. shouldShowPopup: !mediaData.hasMore && mediaData.nextBatchClicked
  3242. });
  3243.  
  3244. if (!mediaData.hasMore && mediaData.nextBatchClicked) {
  3245. console.log('Showing next batch completion popup');
  3246. createInfoDialog("Next batch has completed! All available batches have been fetched.");
  3247. }
  3248. console.log('Resetting nextBatchClicked flag to false');
  3249. mediaData.nextBatchClicked = false;
  3250.  
  3251. reassignDownloadHandlers()
  3252. } else {
  3253. const wasAutoBatchEnabled = getSettings().autoBatchEnabled;
  3254.  
  3255. if (wasAutoBatchEnabled) {
  3256. const newSettings = getSettings();
  3257. newSettings.autoBatchEnabled = false;
  3258. saveSettings(newSettings);
  3259. }
  3260.  
  3261. fetchButton.click();
  3262.  
  3263. if (wasAutoBatchEnabled) {
  3264. setTimeout(() => {
  3265. const newSettings = getSettings();
  3266. newSettings.autoBatchEnabled = true;
  3267. saveSettings(newSettings);
  3268.  
  3269. autoBatchCancelled = true;
  3270. autoBatchStarted = false;
  3271. }, 100);
  3272. }
  3273. }
  3274. })
  3275.  
  3276. prevBatchButton.addEventListener("click", () => {
  3277. if (mediaData.currentPage > 0) {
  3278. mediaData.currentPage--
  3279.  
  3280. autoBatchCancelled = true
  3281. autoBatchStarted = false
  3282.  
  3283. const settings = getSettings()
  3284. const cacheKey = `${settings.timelineType}_${settings.mediaType}_${username}_${mediaData.currentPage}_${settings.batchSize}_batch_${settings.batchEnabled}`
  3285. let data = cacheManager.get(cacheKey)
  3286.  
  3287. if (data && data.timeline && data.timeline.length > 0) {
  3288. mediaData.mediaItems = data.timeline
  3289. mediaData.hasMore = data.metadata.has_more
  3290. mediaData.totalItems = data.total_urls
  3291.  
  3292. mediaData.batchData[mediaData.currentPage] = [...data.timeline]
  3293.  
  3294. const currentBatchKeys = Object.keys(mediaData.batchData).map(Number)
  3295. for (const batchNum of currentBatchKeys) {
  3296. if (batchNum > mediaData.currentPage) {
  3297. delete mediaData.batchData[batchNum]
  3298. }
  3299. }
  3300. mediaData.allMediaItems = []
  3301. const maxBatch = Math.max(...Object.keys(mediaData.batchData).map(Number))
  3302. for (let i = 0; i <= maxBatch; i++) {
  3303. if (mediaData.batchData[i]) {
  3304. mediaData.allMediaItems = [...mediaData.allMediaItems, ...mediaData.batchData[i]]
  3305. }
  3306. }
  3307.  
  3308. const mediaTypeLabel = getMediaTypeLabel(settings.mediaType)
  3309.  
  3310. if (settings.batchEnabled) {
  3311. const accountIconHtml = createAccountIcon(settings.darkTheme).outerHTML
  3312. const mediaIconHtml = createMediaTypeIcon(settings.mediaType, settings.darkTheme).outerHTML
  3313. const totalItemsIconHtml = createTotalItemsIcon(settings.darkTheme).outerHTML
  3314. infoContainer.innerHTML = `
  3315. <div style="margin-bottom: 8px; display: flex; align-items: center;">${accountIconHtml}<strong style="margin-right: 6px;">Account:</strong><span>${data.account_info.name}</span></div>
  3316. <div style="margin-bottom: 8px; display: flex; align-items: center;">${mediaIconHtml}<strong style="margin-right: 6px;">${mediaTypeLabel} Found:</strong><span>${formatNumber(data.total_urls)}</span></div>
  3317. <div style="margin-bottom: 8px; display: flex; align-items: center;">${totalItemsIconHtml}<strong style="margin-right: 6px;">Total Items:</strong><span>${formatNumber(mediaData.allMediaItems.length)}</span></div>
  3318. `
  3319.  
  3320. const currentBatchIconHtml = createCurrentBatchIcon(settings.darkTheme).outerHTML
  3321. currentBatchLabel.innerHTML = `<div style="display: flex; align-items: center;">${currentBatchIconHtml}<strong style="margin-right: 6px; color: ${settings.darkTheme ? '#ffffff' : '#475569'};">Current Batch:</strong><span style="color: ${settings.darkTheme ? '#ffffff' : '#475569'};">${mediaData.currentPage + 1}</span></div>`
  3322.  
  3323. const totalBatches = Math.ceil(data.total_urls / settings.batchSize)
  3324. const totalZipIconHtml = createTotalZipIcon(settings.darkTheme).outerHTML
  3325. totalBatchLabel.innerHTML = `<div style="display: flex; align-items: center;">${totalZipIconHtml}<strong style="margin-right: 6px; color: ${settings.darkTheme ? '#ffffff' : '#475569'};">Total ZIP ${totalBatches === 1 ? 'File' : 'Files'}:</strong><span style="color: ${settings.darkTheme ? '#ffffff' : '#475569'};">${totalBatches}</span></div>`
  3326. batchInfoContainer.style.display = "flex"
  3327. batchNavContainer.style.display = "flex"
  3328. }
  3329.  
  3330. infoContainer.style.display = "block"
  3331.  
  3332. if (settings.batchEnabled) {
  3333. buttonContainer.style.display = "none"
  3334. } else {
  3335. buttonContainer.innerHTML = ""
  3336. buttonContainer.appendChild(downloadButton)
  3337. buttonContainer.style.display = "block"
  3338. }
  3339. if (settings.batchEnabled && mediaData.hasMore) {
  3340. nextBatchButton.style.display = "block"
  3341. }
  3342. if (settings.batchEnabled && mediaData.currentPage > 0) {
  3343. prevBatchButton.style.display = "block"
  3344. }
  3345. reassignDownloadHandlers()
  3346. } else {
  3347. fetchButton.click()
  3348. }
  3349. }
  3350. })
  3351.  
  3352. function chunkMediaItems(items) {
  3353. const chunks = []
  3354. for (let i = 0; i < items.length; i += 500) {
  3355. chunks.push(items.slice(i, i + 500))
  3356. }
  3357. return chunks
  3358. }
  3359.  
  3360. function reassignDownloadHandlers() {
  3361. const settings = getSettings()
  3362. if (settings.batchEnabled) {
  3363. downloadCurrentButton.onclick = () => downloadMedia(false)
  3364. downloadAllButton.onclick = () => downloadMedia(true)
  3365. }
  3366. }
  3367.  
  3368. async function downloadMedia(downloadAll) {
  3369. if (mediaData.downloading) return
  3370.  
  3371. mediaData.downloading = true
  3372.  
  3373. const settings = getSettings()
  3374. const timestamp = getCurrentTimestamp()
  3375.  
  3376. let itemsToDownload
  3377. if (downloadAll) {
  3378. itemsToDownload = mediaData.allMediaItems
  3379. } else {
  3380. itemsToDownload = mediaData.mediaItems
  3381. }
  3382.  
  3383. mediaData.totalToDownload = itemsToDownload.length
  3384. mediaData.totalDownloaded = 0
  3385.  
  3386. progressText.textContent = `Downloading 0/${formatNumber(mediaData.totalToDownload)}`
  3387. progressFill.style.width = "0%"
  3388. progressContainer.style.display = "block"
  3389.  
  3390. fetchButton.disabled = true
  3391. if (settings.batchEnabled) {
  3392. downloadCurrentButton.disabled = true
  3393. downloadAllButton.disabled = true
  3394. } else {
  3395. downloadButton.disabled = true
  3396. }
  3397. nextBatchButton.disabled = true
  3398.  
  3399. const chunks = chunkMediaItems(itemsToDownload)
  3400.  
  3401. for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
  3402. const chunk = chunks[chunkIndex]
  3403.  
  3404. if (chunk.length === 1 && chunks.length === 1) {
  3405. try {
  3406. const item = chunk[0]
  3407. const formattedDate = formatDate(item.date)
  3408. const baseFilename = `${username}_${formattedDate}_${item.tweet_id}`
  3409. const fileExtension = item.type === "photo" ? "jpg" : "mp4"
  3410.  
  3411. const filename = `${baseFilename}.${fileExtension}`
  3412.  
  3413. progressText.textContent = `Downloading 0/1`
  3414.  
  3415. const blob = await fetchBinary(item.url)
  3416.  
  3417. const downloadLink = document.createElement("a")
  3418. downloadLink.href = URL.createObjectURL(blob)
  3419. downloadLink.download = filename
  3420. document.body.appendChild(downloadLink)
  3421. downloadLink.click()
  3422. document.body.removeChild(downloadLink)
  3423.  
  3424. mediaData.totalDownloaded = 1
  3425. progressText.textContent = `Downloading 1/1`
  3426. progressFill.style.width = "100%"
  3427.  
  3428. continue
  3429. } catch (error) {}
  3430. }
  3431.  
  3432. const zip = new JSZip()
  3433.  
  3434. const hasImages = chunk.some((item) => item.type === "photo")
  3435. const hasVideos = chunk.some((item) => item.type === "video")
  3436. const hasGifs = chunk.some((item) => item.type === "gif")
  3437.  
  3438. let imageFolder, videoFolder, gifFolder
  3439. if (settings.mediaType === "all") {
  3440. if (hasImages) imageFolder = zip.folder("image")
  3441. if (hasVideos) videoFolder = zip.folder("video")
  3442. if (hasGifs) gifFolder = zip.folder("gif")
  3443. }
  3444.  
  3445. const filenameMap = {}
  3446.  
  3447. const downloadInBatches = async (items, batchSize) => {
  3448. for (let i = 0; i < items.length; i += batchSize) {
  3449. const batch = items.slice(i, i + batchSize)
  3450.  
  3451. const downloadPromises = batch.map(async (item) => {
  3452. try {
  3453. const formattedDate = formatDate(item.date)
  3454. let baseFilename = `${username}_${formattedDate}_${item.tweet_id}`
  3455.  
  3456. if (filenameMap[baseFilename] !== undefined) {
  3457. filenameMap[baseFilename]++
  3458. baseFilename = `${baseFilename}_${String(filenameMap[baseFilename]).padStart(2, "0")}`
  3459. } else {
  3460. filenameMap[baseFilename] = 0
  3461. }
  3462.  
  3463. const fileExtension = item.type === "photo" ? "jpg" : "mp4"
  3464. const filename = `${baseFilename}.${fileExtension}`
  3465.  
  3466. const blob = await fetchBinary(item.url)
  3467.  
  3468. if (settings.mediaType === "all") {
  3469. if (item.type === "photo") {
  3470. imageFolder.file(filename, blob)
  3471. } else if (item.type === "video") {
  3472. videoFolder.file(filename, blob)
  3473. } else if (item.type === "gif") {
  3474. gifFolder.file(filename, blob)
  3475. }
  3476. } else {
  3477. zip.file(filename, blob)
  3478. }
  3479.  
  3480. mediaData.totalDownloaded++
  3481. const completedCount = mediaData.totalDownloaded
  3482. progressText.textContent = `Downloading ${formatNumber(completedCount)}/${formatNumber(mediaData.totalToDownload)}`
  3483. progressFill.style.width = `${(completedCount / mediaData.totalToDownload) * 100}%`
  3484.  
  3485. } catch (error) {
  3486. console.error("Error downloading item:", error)
  3487. mediaData.totalDownloaded++
  3488. }
  3489. })
  3490.  
  3491. await Promise.all(downloadPromises)
  3492. }
  3493. }
  3494.  
  3495. await downloadInBatches(chunk, settings.concurrentDownloads)
  3496.  
  3497. progressText.textContent = `Creating ZIP file ${chunkIndex + 1}/${chunks.length}...`
  3498.  
  3499. try {
  3500. const zipBlob = await zip.generateAsync({ type: "blob" })
  3501.  
  3502. let zipFilename
  3503. if (chunks.length === 1 && chunk.length < 500) {
  3504. zipFilename = `${username}_${timestamp}.zip`
  3505. } else if (settings.batchEnabled && !downloadAll) {
  3506. zipFilename = `${username}_${timestamp}_part_${String(mediaData.currentPage + 1).padStart(2, "0")}.zip`
  3507. } else {
  3508. zipFilename = `${username}_${timestamp}_part_${String(chunkIndex + 1).padStart(2, "0")}.zip`
  3509. }
  3510.  
  3511. const downloadLink = document.createElement("a")
  3512. downloadLink.href = URL.createObjectURL(zipBlob)
  3513. downloadLink.download = zipFilename
  3514. document.body.appendChild(downloadLink)
  3515. downloadLink.click()
  3516. document.body.removeChild(downloadLink)
  3517. } catch (error) {
  3518. progressText.textContent = `Error creating ZIP ${chunkIndex + 1}: ${error.message}`
  3519. }
  3520. }
  3521. mediaData.downloading = false
  3522. progressContainer.style.display = "none"
  3523. fetchButton.disabled = false
  3524. if (settings.batchEnabled) {
  3525. downloadCurrentButton.disabled = false
  3526. downloadAllButton.disabled = false
  3527. reassignDownloadHandlers()
  3528. } else {
  3529. downloadButton.disabled = false
  3530. }
  3531. nextBatchButton.disabled = false
  3532. createInfoDialog("All media downloaded successfully.", "Download Complete")
  3533. return
  3534. }
  3535.  
  3536. document.body.appendChild(modal)
  3537. }
  3538.  
  3539. function extractUsername() {
  3540. const pathParts = window.location.pathname.split("/").filter((part) => part)
  3541. if (pathParts.length > 0) {
  3542. return pathParts[0]
  3543. }
  3544. return null
  3545. }
  3546.  
  3547. function insertDownloadIcon() {
  3548. const usernameDivs = document.querySelectorAll('[data-testid="UserName"]')
  3549.  
  3550. usernameDivs.forEach((usernameDiv) => {
  3551. if (!usernameDiv.querySelector(".download-icon")) {
  3552. const username = extractUsername()
  3553. if (!username) return
  3554.  
  3555. const verifiedButton = usernameDiv
  3556. .querySelector('[aria-label*="verified"], [aria-label*="Verified"]')
  3557. ?.closest("button")
  3558.  
  3559. const targetElement = verifiedButton
  3560. ? verifiedButton.parentElement
  3561. : usernameDiv.querySelector(".css-1jxf684")?.closest("span")
  3562.  
  3563. if (targetElement) {
  3564. const downloadIcon = createDownloadIcon()
  3565.  
  3566. const iconDiv = document.createElement("div")
  3567. iconDiv.className = "download-icon css-175oi2r r-1awozwy r-xoduu5"
  3568. iconDiv.style.cssText = `
  3569. display: inline-flex;
  3570. align-items: center;
  3571. margin-left: 6px;
  3572. margin-right: 6px;
  3573. gap: 6px;
  3574. padding: 0 3px;
  3575. transition: transform 0.2s, color 0.2s;
  3576. `
  3577. iconDiv.appendChild(downloadIcon)
  3578.  
  3579. iconDiv.addEventListener("mouseenter", () => {
  3580. iconDiv.style.transform = "scale(1.1)"
  3581. iconDiv.style.color = "#0ea5e9"
  3582. })
  3583.  
  3584. iconDiv.addEventListener("mouseleave", () => {
  3585. iconDiv.style.transform = "scale(1)"
  3586. iconDiv.style.color = ""
  3587. })
  3588.  
  3589. iconDiv.addEventListener("click", (e) => {
  3590. e.stopPropagation()
  3591. createModal(username)
  3592. })
  3593.  
  3594. const wrapperDiv = document.createElement("div")
  3595. wrapperDiv.style.cssText = `
  3596. display: inline-flex;
  3597. align-items: center;
  3598. gap: 4px;
  3599. `
  3600. wrapperDiv.appendChild(iconDiv)
  3601. targetElement.parentNode.insertBefore(wrapperDiv, targetElement.nextSibling)
  3602. }
  3603. }
  3604. })
  3605. }
  3606.  
  3607. insertDownloadIcon()
  3608.  
  3609. function checkForUserNameElement() {
  3610. const usernameDivs = document.querySelectorAll('[data-testid="UserName"]')
  3611. if (usernameDivs.length > 0) {
  3612. insertDownloadIcon()
  3613. }
  3614. }
  3615.  
  3616. setInterval(checkForUserNameElement, 100)
  3617.  
  3618. let lastUrl = location.href
  3619. let lastUsername = extractUsername()
  3620.  
  3621. function checkForChanges() {
  3622. const currentUrl = location.href
  3623. const currentUsername = extractUsername()
  3624.  
  3625. if (currentUrl !== lastUrl || currentUsername !== lastUsername) {
  3626. lastUrl = currentUrl
  3627. lastUsername = currentUsername
  3628.  
  3629. document.querySelectorAll(".download-icon").forEach((icon) => {
  3630. const wrapper = icon.closest("div[style*='display: inline-flex']")
  3631. if (wrapper) {
  3632. wrapper.remove()
  3633. }
  3634. })
  3635.  
  3636. setTimeout(insertDownloadIcon, 50)
  3637. }
  3638. }
  3639.  
  3640. const observer = new MutationObserver(() => {
  3641. checkForChanges()
  3642. checkForUserNameElement()
  3643. })
  3644.  
  3645. observer.observe(document.body, {
  3646. childList: true,
  3647. subtree: true,
  3648. attributes: true,
  3649. characterData: true,
  3650. })
  3651.  
  3652. setInterval(checkForChanges, 300)
  3653.  
  3654. const originalPushState = history.pushState
  3655. const originalReplaceState = history.replaceState
  3656.  
  3657. history.pushState = function () {
  3658. originalPushState.apply(this, arguments)
  3659. checkForChanges()
  3660. insertDownloadIcon()
  3661. }
  3662.  
  3663. history.replaceState = function () {
  3664. originalReplaceState.apply(this, arguments)
  3665. checkForChanges()
  3666. insertDownloadIcon()
  3667. }
  3668.  
  3669. window.addEventListener("popstate", () => {
  3670. checkForChanges()
  3671. insertDownloadIcon()
  3672. })
  3673. })()

QingJ © 2025

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