// ==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/*
// @include http*://*youtube.com/watch?v=*
// @version 1.3
// @grant GM_addStyle
// @downloadURL none
// ==/UserScript==
/*
* getStyleObject Plugin for jQuery JavaScript Library
* From: http://upshots.org/?p=112
*/
(function($){
$.fn.getStyleObject = function(){
var dom = this.get(0);
var style;
var returns = {};
if(window.getComputedStyle){
var camelize = function(a,b){
return b.toUpperCase();
};
style = window.getComputedStyle(dom, null);
for(var i = 0, l = style.length; i < l; i++){
var prop = style[i];
var camel = prop.replace(/\-([a-z])/g, camelize);
var val = style.getPropertyValue(prop);
returns[camel] = val;
};
return returns;
};
if(style = dom.currentStyle){
for(var prop in style){
returns[prop] = style[prop];
};
return returns;
};
return this.css();
}
})(jQuery);
$.fn.copyCSS = function(source){
var styles = $(source).getStyleObject();
this.css(styles);
}
function main() {
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();
else if(site.includes("youtube.com")) youtube();
}
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("
" + button(url) + "");
}
function powerwatch() {
if($("#vplayer").length === 0) return;
var url = searchInScripts("file:\\s?\"https?:\\/\\/.+?\\.mp4\"", "http", ".mp4");
if(url !== null) {
$("h5.h4-fine").html(""+$("h5.h4-fine").html()+"" + button(url) + "")
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;
var lightBTN = $(".light-switch.btn");
var downBTN = $("" + button(url) + "
");
downBTN.copyCSS(lightBTN);
lightBTN.parent().prepend(downBTN);
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; }");
}
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("" + button(url) + "
");
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 youtube() {
$("script").each(function() {
var cont = decodeURI($(this).html());
if(!cont.includes("\"adaptive_fmts\":")) return;
cont = cont.replace(",", "\\u0026");
var data = cont.split("\\u0026");
var format = [];
var vid = {};
for(var dat of data) {
var tmp = dat.split("=");
var name = tmp[0];
var val = tmp[1];
if("|type|quality_label|url|fps|".includes("|"+name+"|")) {
if(name === "url" || name === "type") val = decodeURIComponent(val);
if(name === "type") val = val.substring(0, val.indexOf(";"));
if(name in vid) {
if(("url" in vid) && ("type" in vid)) format.push(vid);
vid = {};
} else vid[name] = val;
}
}
for(var t of format) console.log(t);
var links = "";
for(var t of format) links += "";
$("#watch8-secondary-actions").prepend("");
GM_addStyle(".download-link { text-decoration: none; color: inherit; } .download-link:hover { text-decoration: none; }");
});
}
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 "Download";
}
main();