rule34视频下载插件

快捷下载rule34.xxx的视频

  1. // ==UserScript==
  2. // @name Rule34 Video Downloader
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-02-07.1
  5. // @description 快捷下载rule34.xxx的视频
  6. // @description:zh-cn 快捷下载rule34.xxx的视频
  7. // @author 键盘&GPT4
  8. // @match https://rule34.xxx/index.php?page=post&s=view&id=*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=rule34.xxx
  10. // @grant GM_xmlhttpRequest
  11. // @license MIT
  12. // @name:zh-CN rule34视频下载插件
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. 'use strict';
  17.  
  18. // Your code here...
  19.  
  20. // 创建一个下载按钮放在id为gelcomVideoPlayer的video标签的右上角
  21. var video = document.getElementById('gelcomVideoPlayer');
  22. var downloadButton = document.createElement('p');
  23. downloadButton.href = video.src;
  24. downloadButton.download = video.src;
  25. downloadButton.innerHTML = '下载';
  26. downloadButton.style.position = 'absolute';
  27. downloadButton.style.right = '0';
  28. downloadButton.style.top = '0';
  29.  
  30. // 美化按钮
  31. downloadButton.style.padding = '5px';
  32. downloadButton.style.backgroundColor = 'rgba(0,0,0,0.5)';
  33. downloadButton.style.color = 'white';
  34. downloadButton.style.borderRadius = '5px';
  35. downloadButton.style.textDecoration = 'none';
  36. downloadButton.style.zIndex = '999';
  37. downloadButton.style.cursor = 'pointer';
  38. downloadButton.style.userSelect = 'none';
  39. video.parentElement.appendChild(downloadButton);
  40.  
  41. // 点击下载按钮时触发下载
  42. downloadButton.onclick = function () {
  43. const videolink = video.getElementsByTagName('source')[0].src;
  44. if (videolink) {
  45. // 使用 GM_xmlhttpRequest 发送跨域请求
  46. GM_xmlhttpRequest({
  47. method: "GET",
  48. url: videolink,
  49. responseType: 'blob', // 确保以blob形式接收视频数据
  50. onload: function (response) {
  51. // 这里我们接收到了一个Blob对象,我们可以创建一个下载
  52. if (response.status === 200) {
  53. var blob = response.response;
  54. var url = URL.createObjectURL(blob); // 创建一个指向blob的URL
  55. var filename = "video.mp4"; // 假设你知道视频的格式,或者从Content-Disposition头或URL中提取
  56.  
  57. // 创建一个临时的a元素用于下载文件
  58. var a = document.createElement('a');
  59. a.href = url;
  60. a.download = filename; // 设置下载文件名
  61. document.body.appendChild(a);
  62. a.click(); // 触发下载
  63.  
  64. window.URL.revokeObjectURL(url); // 释放URL对象
  65. a.remove(); // 删除临时创建的a元素
  66. } else {
  67. console.error('视频加载失败:', response.status);
  68. }
  69. },
  70. onerror: function (error) {
  71. // 处理错误
  72. console.error('视频请求失败:', error);
  73. }
  74. });
  75. }
  76. }
  77.  
  78. })();