Video Download Button

This script adds a download button on many video sites.

目前為 2016-06-22 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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>";
}