Video Download Button

This script adds a download button on many video sites.

当前为 2016-06-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Video Download Button
  3. // @namespace VDBMB
  4. // @author MegaByte
  5. // @description This script adds a download button on many video sites.
  6. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  7. // @run-at document-end
  8. // @noframes
  9. // @include http*://*streamcloud.eu/*
  10. // @include http*://*powerwatch.pw/*
  11. // @include http*://*vivo.sx/*
  12. // @include http*://*shared.sx/*
  13. // @include http*://*youtube.com/watch?v=*
  14. // @version 1.3
  15. // @grant GM_addStyle
  16. // ==/UserScript==
  17.  
  18.  
  19. /*
  20. * getStyleObject Plugin for jQuery JavaScript Library
  21. * From: http://upshots.org/?p=112
  22. */
  23.  
  24. (function($){
  25. $.fn.getStyleObject = function(){
  26. var dom = this.get(0);
  27. var style;
  28. var returns = {};
  29. if(window.getComputedStyle){
  30. var camelize = function(a,b){
  31. return b.toUpperCase();
  32. };
  33. style = window.getComputedStyle(dom, null);
  34. for(var i = 0, l = style.length; i < l; i++){
  35. var prop = style[i];
  36. var camel = prop.replace(/\-([a-z])/g, camelize);
  37. var val = style.getPropertyValue(prop);
  38. returns[camel] = val;
  39. };
  40. return returns;
  41. };
  42. if(style = dom.currentStyle){
  43. for(var prop in style){
  44. returns[prop] = style[prop];
  45. };
  46. return returns;
  47. };
  48. return this.css();
  49. }
  50. })(jQuery);
  51.  
  52. $.fn.copyCSS = function(source){
  53. var styles = $(source).getStyleObject();
  54. this.css(styles);
  55. }
  56.  
  57.  
  58. function main() {
  59. var site = window.location.href || document.URL;
  60.  
  61. if(site.includes("streamcloud.eu")) streamcloud();
  62. else if(site.includes("powerwatch.pw")) powerwatch();
  63. else if(site.includes("vivo.sx")) vivo();
  64. else if(site.includes("shared.sx")) shared();
  65. else if(site.includes("youtube.com")) youtube();
  66. }
  67.  
  68. function streamcloud() {
  69. if($("#player_code").length === 0) return;
  70. var url = searchInScripts("file:\\s?\"https?:\\/\\/.+?\\.mp4\"", "http", ".mp4");
  71. if(url !== null)
  72. $(".container-fluid ul.nav").prepend("<li>" + button(url) + "</li>");
  73. }
  74.  
  75. function powerwatch() {
  76. if($("#vplayer").length === 0) return;
  77. var url = searchInScripts("file:\\s?\"https?:\\/\\/.+?\\.mp4\"", "http", ".mp4");
  78. if(url !== null) {
  79. $("h5.h4-fine").html("<span class='head'>"+$("h5.h4-fine").html()+"</span><span class='down'>" + button(url) + "</span>")
  80. GM_addStyle("h5.h4-fine { display: flex; } h5.h4-fine .head { flex-grow: 1; } h5.h4-fine .down { flex-grow: 0; }");
  81. }
  82. }
  83.  
  84. function vivo() {
  85. var e = $(".stream-content");
  86. if(e.length === 0) return;
  87. var url = e.attr("data-url");
  88. if(typeof url === "undefined") return;
  89. var lightBTN = $(".light-switch.btn");
  90. var downBTN = $("<div class='download'>" + button(url) + "</div>");
  91. downBTN.copyCSS(lightBTN);
  92. lightBTN.parent().prepend(downBTN);
  93. GM_addStyle(".download { margin-right: 15px !important;} .download:hover { color: #fff !important; background-color: #39b3d7 !important; border-color: #269abc !important; } .download a { text-decoration: none; color: white; }");
  94. }
  95.  
  96. function shared() {
  97. var e = $(".stream-content");
  98. if(e.length === 0) return;
  99. var url = e.attr("data-url");
  100. if(typeof url === "undefined") return;
  101. $(".light-switch").parent().prepend("<div class='download'>" + button(url) + "</div>");
  102. GM_addStyle(".addthis_toolbox { width: unset !important; } .download { position: relative; background-color: #FF6550; color: #FFF; float: right; font-size: 13px; font-weight: 700; height: 32px; line-height: 32px; margin: 0 0 0 10px; padding: 0 15px; width: auto; cursor: pointer; -webkit-transition: all .35s ease-in; -moz-transition: all .35s ease-in; -o-transition: all .35s ease-in; transition: all .35s ease-in; opacity: 1; z-index: 300; } .download a { text-decoration: none; color: white;}");
  103. }
  104.  
  105. function youtube() {
  106. $("script").each(function() {
  107. var cont = decodeURI($(this).html());
  108. if(!cont.includes("\"adaptive_fmts\":")) return;
  109. cont = cont.replace(",", "\\u0026");
  110. var data = cont.split("\\u0026");
  111. var format = [];
  112. var vid = {};
  113. for(var dat of data) {
  114. var tmp = dat.split("=");
  115. var name = tmp[0];
  116. var val = tmp[1];
  117. if("|type|quality_label|url|fps|".includes("|"+name+"|")) {
  118. if(name === "url" || name === "type") val = decodeURIComponent(val);
  119. if(name === "type") val = val.substring(0, val.indexOf(";"));
  120. if(name in vid) {
  121. if(("url" in vid) && ("type" in vid)) format.push(vid);
  122. vid = {};
  123. } else vid[name] = val;
  124. }
  125. }
  126. for(var t of format) console.log(t);
  127. var links = "";
  128. for(var t of format) links += "<li><span loop='0' class='yt-ui-menu-item'><a class='download-link' download href='" + t["url"] + "'>" + t["type"] + "|" + t["quality_label"] + "</a></span></a></li>";
  129. $("#watch8-secondary-actions").prepend("<button title='Download' aria-expanded='false' aria-pressed='false' aria-labelledby='yt-uix-tooltip25-arialabel' role='button' type='button' data-tooltip-text='Download' class='yt-uix-button yt-uix-button-size-default yt-uix-button-opacity yt-uix-tooltip' id='download-video-button'><span><span class='yt-uix-button-icon-wrapper'><img style='width:20px;height:20px;background-size:20px 20px;background-repeat:no-repeat;background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABG0lEQVRYR+2W0Q3CMAxE2wkYAdiEEWADmIxuACMwCmzABpCTEmRSO7YTQX+ChECV43t2nF7GYeHPuLD+0AKwC/DnWMAp/N5qimkBuAfBdRTF/+2/AV6ZYFUxVYuicAfoHegd6B3oHfhZB+ByF+JyV8FkrAB74pqH3DU5L3iGoBURhdVODIQF4EjEkWLmmhYALOQgNIBcHHke4buhxXAAaFnaAhqbQ5QAOHHkwhZ8balkx1ICCiEBWNZ+CivdB7REHIC2ZjZK2oWklDDdB1NSdCd/Js2PqQMpSIKYVcM8kE6QCwDBNRCqOBJrW0CL8kCYxL0A1k6YxWsANAiXeC2ABOEWbwHAWrwxpzgkmA/JtIqnxTOElmPnjlkc4A3FykAhA42AxwAAAABJRU5ErkJggg==);' class='yt-uix-button-icon' src='//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif'></span><span class='yt-uix-button-content'>Download </span><ul class='yt-uix-button-menu hid' style='min-width: 114px; left: 40px; top: 501px; display: none;'>" + links + "</ul></span></button>");
  130. GM_addStyle(".download-link { text-decoration: none; color: inherit; } .download-link:hover { text-decoration: none; }");
  131. });
  132. }
  133.  
  134. function searchInScripts(patt, start, end) {
  135. var url = null;
  136. $("body script").each(function() {
  137. var regex = new RegExp(patt);
  138. var out = regex.exec($(this).html());
  139. if(typeof out !== "undefined" && out !== "" && out !== null) {
  140. if(typeof out !== "string") out = out[0];
  141. var s = out.indexOf(start);
  142. var e = out.lastIndexOf(end);
  143. if( s!==-1 && e!==-1 ) url = out.substring(s, e);
  144. return false;
  145. }
  146. });
  147. return url;
  148. }
  149.  
  150. function button(url) {
  151. return "<a href='" + url + "' download target='_blank'>Download</a>";
  152. }
  153.  
  154. main();