Rumble Download Button

Add a download button for Rumble

  1. // ==UserScript==
  2. // @name Rumble Download Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-02-11
  5. // @description Add a download button for Rumble
  6. // @author Zeek Bower
  7. // @match https://rumble.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=rumble.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. window.addEventListener("load", function() {
  17. console.log("load");
  18.  
  19. function downloadMP4WithProgress() {
  20. const mp4Url = document.getElementsByTagName("video")[0].currentSrc.split('?')[0];
  21.  
  22. fetch(mp4Url)
  23. .then(response => {
  24. if (!response.ok) {
  25. throw new Error('Network response was not ok');
  26. }
  27. const totalSize = parseInt(response.headers.get('content-length')); // Get total size of the response
  28. let loadedBytes = 0;
  29.  
  30. const reader = response.body.getReader();
  31.  
  32. return new ReadableStream({
  33. start(controller) {
  34. function pump() {
  35. reader.read().then(({ done, value }) => {
  36. if (done) {
  37. controller.close();
  38. return;
  39. }
  40.  
  41. controller.enqueue(value);
  42. loadedBytes += value.byteLength;
  43.  
  44. const progress = loadedBytes / totalSize;
  45. const percentage = Math.round(progress * 100);
  46. console.log(`Downloaded ${percentage}%`);
  47.  
  48. let dlbutton = window.document.getElementsByClassName("subscribe-buttons")[0].lastChild
  49.  
  50. dlbutton.firstChild.innerText = `Downloaded ${percentage}%`;
  51.  
  52. // Trigger the progress event here if needed
  53.  
  54. pump();
  55. }).catch(error => {
  56. console.error('Stream read error:', error);
  57. controller.error(error);
  58. });
  59. }
  60.  
  61. pump();
  62. }
  63. });
  64. })
  65. .then(stream => new Response(stream))
  66. .then(response => response.blob())
  67. .then(blob => {
  68. const url = URL.createObjectURL(blob);
  69. const link = document.createElement('a');
  70. link.href = url;
  71. link.download = document.getElementsByTagName("h1")[0].innerText + ".mp4";
  72. link.click();
  73. })
  74. .catch(error => {
  75. console.error('Fetch error:', error);
  76. });
  77. }
  78.  
  79. function downloadMP4() {
  80. // URL of the MP4 file
  81. const mp4Url = document.getElementsByTagName("video")[0].currentSrc.split('?')[0];
  82.  
  83. // Fetch the MP4 file
  84. fetch(mp4Url)
  85. .then(response => response.blob())
  86. .then(response => console.log(response))
  87. .then(blob => {
  88. // Create a temporary URL for the blob
  89. const url = URL.createObjectURL(blob);
  90.  
  91. // Create a link element
  92. const link = document.createElement('a');
  93.  
  94. // Set the link's href to the URL of the blob
  95. link.href = url;
  96.  
  97. // Set the download attribute to specify the filename
  98. link.download = document.getElementsByTagName("h1")[0].innerText + ".mp4";
  99. // Simulate a click on the link to trigger the download
  100. link.click();
  101.  
  102. // Cleanup by revoking the object URL
  103. URL.revokeObjectURL(url);
  104. });
  105. }
  106.  
  107. // Create a button element
  108. const button = document.createElement('button');
  109.  
  110. // Set the button's text content
  111. button.textContent = 'DOWNLOAD4';
  112. button.innerHTML = "DOWNLOAD";
  113. button.class = "round-button bg-purple";
  114. button.setAttribute("class","round-button bg-purple");
  115.  
  116. // Assign the downloadMP4 function to the button's onclick event handler
  117. button.onclick = downloadMP4WithProgress;
  118.  
  119. const theVideo = document.getElementsByTagName("video")[0].currentSrc.split('?')[0];
  120. console.log(theVideo);
  121. const link = document.createElement('a');
  122.  
  123. const ourDiv = window.document.createElement("div");
  124. ourDiv.class = "subscribe-buttons";
  125. ourDiv.appendChild(button);
  126. const currentDiv = window.document.getElementsByClassName("subscribe-buttons");
  127. currentDiv[0].appendChild(ourDiv)
  128. console.log("end");
  129. });
  130.  
  131.  
  132. })();

QingJ © 2025

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