Skip to content

Instantly share code, notes, and snippets.

@TheZ3ro
Last active May 2, 2016 17:08
Show Gist options
  • Save TheZ3ro/82bda0eb8749c89664ce to your computer and use it in GitHub Desktop.
Save TheZ3ro/82bda0eb8749c89664ce to your computer and use it in GitHub Desktop.
Extract HTML5 video link from webpages
// ==UserScript==
// @name HTML5 Video Source
// @namespace thezero.org
// @include *
// @version 1
// @run-at document-end
// @grant none
// ==/UserScript==
// create element
function ce(n) { return document.createElement(n); } // end of function
// add style
function addStyle(css) {
var head = document.head || document.getElementsByTagName('head')[0];
if (head) {
var style = ce("style");
style.type = "text/css";
style.appendChild(document.createTextNode(css));
head.appendChild(style);
} // end if
} // end of function
// toggle visibility
function toggle(elem) {
if(elem.style.display!="block"){
elem.style.display="block";
}else{
elem.style.display="none";
}
}
// remove element by ID
function removeById(e_id) {
var elem = document.getElementById(e_id);
elem.parentNode.removeChild(elem);
}
// add css
function shareCSS(){
var s='';
download_icon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4AEIDBYVWhsYJQAAAAZiS0dEAP8A/wD/oL2nkwAAB1pJREFUWMPNV1tMHFUY/vfCsix3CssChZZLKRepLSWtWtv0yRejaWMTa1Ifij74YDAxMU1pTKMxmmBMTBNNfED7YEwaU9Mm2gfDpUSLSdMgvaCEUkopXZbbsrvssszuzoz/N8zZzG6XUhATD/w5Z2fOnP873385/zHRJrbm5mYaGBhI9Xy3qqq1aWlpO81m81aTydTkdDo/PHbs2B9Xr15d6uzsjM810X/Q0tPT87OysiotFksJy47s7OyPq6urs3ft2kWKouA9RA6Hw71+v/9VnhM+d+7c5gAqLS1t4gUbrFbrHt75/qKiosqKigo7s2Lfvn27raamxubxeCzT09M0NTVFCwsL2nfMmAaO+1YG851Yz/oE+h08uZkpLmppabk5Pz+fNjo62sDKW/hZs8vlauRdl5eVlVFjYyNVVVURA6GMjIy4wmg0SjyXxsb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:32px; cursor:pointer; background:url('+download_icon+') no-repeat scroll 50% 50% rgba(0, 0, 0, 0.7); border-radius:25px; }';
s+='.play_btn { -webkit-transition-duration:0.5s linear; -o-transition-duration:0.5s linear; -moz-transition-duration:0.5s linear; transition-duration:0.5s linear; opacity:0.65; }';
s+='.play_btn:hover { opacity:1; }';
s+='.vid_count{font-size: 12px;color: #000;border: 2px solid rgb(51, 51, 51);background: rgb(238, 238, 238) none repeat scroll 0% 0%;font-family: sans;border-radius: 32px;}';
s+='.vid_list{display:none;padding: 10px;border: 2px solid #555;border-radius: 10px;z-index: 1000;width: 400px;margin-left: -432px;background: #C8C8C8 none repeat scroll 0% 0%;margin-top: -90px;position: absolute;overflow-y: scroll;font-size: 13px;height: 75px;}';
s+='.vid_list a,.vid_list a:hover{font-family: sans;color:#000;text-decoration:underline}';
addStyle(''+s);
}
var el = (navigator.userAgent.indexOf('Firefox') != -1 || navigator.userAgent.indexOf('MSIE') != -1) ? document.documentElement.lastChild : document.body,
zIindex = 1001;
// main
function resource_counter() {
var resource = [];
var t = document.getElementsByTagName("video");
if(t.length > 0) {
for (var i = 0; i < t.length; i++) {
if(t[i].currentSrc != ""){
resource.push(t[i].currentSrc);
}
}
}
return resource;
}
function create_btn_element(r) {
var vid,vid_list,vid_count;
shareCSS();
if(el){
vid = ce('div');
vid.setAttribute('id','play_btn_vid');
vid.className = "play_btn";
vid_count = ce('span');
vid_count.setAttribute('id','vid_count');
vid_count.className = "vid_count";
vid_count.innerHTML = r.length;
vid_list = ce('div');
vid_list.setAttribute('id','vid_list');
vid_list.className = "vid_list";
for (var i = 0; i < r.length; i++) {
var a = ce('a');
a.href = r[i];
a.innerHTML = r[i];
a.target = "_blank";
//console.log(r[i]);
vid_list.appendChild(a);
var br = ce('br');
vid_list.appendChild(br);
}
vid.appendChild(vid_count);
vid.appendChild(vid_list);
el.appendChild(vid);
vid.addEventListener('click', function(){ toggle(document.getElementById("vid_list")) }, false);
} // end if
} // end of function
function init(){
var res = resource_counter();
console.log("Resource Count: "+res.length);
if(res.length > 0) {
if (document.getElementById('play_btn_vid') != null){
removeById('play_btn_vid');
}
create_btn_element(res);
}
}
el.onkeypress = function(e) {
e = e || event;
var key = String.fromCharCode(e.keyCode || e.charCode);
if(key == 'v' && e.ctrlKey && e.altKey ) {
init();
}
}
init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment