Video Download Button

This script adds a download button on many video sites.

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Video Download Button
// @namespace   VDBMB
// @author      MegaByte
// @description This script adds a download button on many video sites.
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @run-at 		document-end
// @noframes
// @include     http*://*streamcloud.eu/*
// @include     http*://*powerwatch.pw/*
// @include     http*://*vivo.sx/*
// @include     http*://*shared.sx/*
// @version     1.0
// @grant       GM_addStyle
// ==/UserScript==


var site = window.location.href || document.URL;

if(site.includes("streamcloud.eu")) streamcloud();
else if(site.includes("powerwatch.pw")) powerwatch();
else if(site.includes("vivo.sx")) vivo();
else if(site.includes("shared.sx")) shared();

function streamcloud() {
  if($("#player_code").length === 0) return;
	var url = searchInScripts("file:\\s?\"https?:\\/\\/.+?\\.mp4\"", "http", ".mp4");
	if(url !== null) 
		$(".container-fluid ul.nav").prepend("<li>" + button(url) + "</li>");
}

function powerwatch() {
  if($("#vplayer").length === 0) return;
	var url = searchInScripts("file:\\s?\"https?:\\/\\/.+?\\.mp4\"", "http", ".mp4");
	if(url !== null) {
		$("h5.h4-fine").html("<span class='head'>"+$("h5.h4-fine").html()+"</span><span class='down'>" + button(url) + "</span>")
		GM_addStyle("h5.h4-fine { display: flex; } h5.h4-fine .head { flex-grow: 1; } h5.h4-fine .down { flex-grow: 0; }");
	}
}

function vivo() {
  var e = $(".stream-content");
  if(e.length === 0) return;
  var url = e.attr("data-url");
  if(typeof url === "undefined") return;
  $(".light-switch.btn").parent().prepend("<div class='light-switch btn btn-info download'>" + button(url) + "</div>");
  GM_addStyle(".download.light-switch { margin-right: 15px; }  .download.light-switch a { text-decoration: none; color: white; }");
}

function shared() {
  var e = $(".stream-content");
  if(e.length === 0) return;
  var url = e.attr("data-url");
  if(typeof url === "undefined") return;
  $(".light-switch").parent().prepend("<div class='download'>" + button(url) + "</div>");
  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;}");
}

function searchInScripts(patt, start, end) {
  var url = null;
	$("body script").each(function() {
    var regex = new RegExp(patt);
		var out = regex.exec($(this).html());
		if(typeof out !== "undefined" && out !== "" && out !== null) {
      if(typeof out !== "string") out = out[0];
      var s = out.indexOf(start);
      var e = out.lastIndexOf(end);
      if( s!==-1 && e!==-1 ) url = out.substring(s, e);
      return false;
    }
	});
  return url;
}

function button(url) {
  return "<a href='" + url + "' download target='_blank'>Download</a>";
}