Bunkrr DL Button

Add a direct download button below each thumbnails

当前为 2024-01-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Bunkrr DL Button
  3. // @version 1.3
  4. // @description Add a direct download button below each thumbnails
  5. // @match https://bunkrr.ru/a/*
  6. // @namespace bunkrr
  7. // @license MIT
  8. // @grant GM_download
  9. // ==/UserScript==
  10.  
  11. const extensions = [
  12. "mp4",
  13. "jpg",
  14. "png",
  15. "jpeg",
  16. "zip",
  17. "rar",
  18. "webp",
  19. "gif",
  20. "mp3",
  21. "mkv",
  22. "avi",
  23. "mov",
  24. "wmv",
  25. "flv",
  26. ];
  27.  
  28. const extensionsSelector = extensions
  29. .map((ext) => `a[href$='.${ext}']`)
  30. .join(", ");
  31. (async () => {
  32. "use strict";
  33. const mediaLinks = [...document.querySelectorAll(".grid-images_box-link")];
  34.  
  35. const links = mediaLinks.map((mediaLink) => {
  36. const relativeLink = mediaLink.getAttribute("href");
  37.  
  38. return window.location.origin + relativeLink;
  39. });
  40.  
  41. const medias = document.querySelectorAll(".grid-images > *");
  42.  
  43. await Promise.all(
  44. links.map(async (link, i) => {
  45. const response = await fetch(link);
  46. const html = await response.text();
  47.  
  48. const parser = new DOMParser();
  49. const doc = parser.parseFromString(html, "text/html");
  50.  
  51. const ddlLink = doc
  52. .querySelector(extensionsSelector)
  53. .getAttribute("href");
  54.  
  55. const media = medias[i];
  56. const mediaStyle = {
  57. display: "flex",
  58. flexDirection: "column",
  59. border: "none",
  60. padding: "0",
  61. };
  62. Object.assign(media.style, mediaStyle);
  63.  
  64. const mediaChildren = media.querySelectorAll(":scope > *");
  65. mediaChildren[mediaChildren.length - 1].style.bottom = "0";
  66.  
  67. const newMediaBox = document.createElement("div");
  68. const newMediaBoxStyle = {
  69. position: "relative",
  70. padding: "0.625rem",
  71. paddingBottom: "0",
  72. border: "solid #ffd369 2px",
  73. borderBottom: "none",
  74. };
  75.  
  76. Object.assign(newMediaBox.style, newMediaBoxStyle);
  77.  
  78. newMediaBox.append(...mediaChildren);
  79.  
  80. const dlBox = document.createElement("a");
  81. dlBox.setAttribute("href", ddlLink);
  82.  
  83. dlBox.textContent = "Download";
  84.  
  85. dlBoxEventListener(dlBox);
  86.  
  87. const dlBoxStyle = {
  88. border: "solid #ffd369 2px",
  89. borderRadius: "0px 0px 20px 20px",
  90. width: "100%",
  91. };
  92.  
  93. Object.assign(dlBox.style, dlBoxStyle);
  94.  
  95. media.append(newMediaBox, dlBox);
  96. })
  97. );
  98. })();
  99.  
  100. function dlBoxEventListener(dlBox) {
  101. dlBox.addEventListener("click", async (e) => {
  102. e.preventDefault();
  103. const url = dlBox.getAttribute("href");
  104. const name = url.split("/").pop();
  105. GM_download({
  106. url,
  107. name,
  108. saveAs: true,
  109. onerror: (e) => console.error(e),
  110. });
  111. });
  112. }