// ==UserScript== // @name Download Sibnet Video as MP4 // @namespace http://video.sibnet.ru // @description Выдает ссылку на видео в правом нижнем углу плеера // @include *://video.sibnet.ru/* // @version 1.2.8.2 // @author Iron_man // @grant none // @downloadURL none // ==/UserScript== var POSTMessage = true; var XMLHTTPFactory = [ function(){return new XMLHttpRequest();}, function(){return new ActiveXObject('Msxml3.XMLHTTP');}, function(){return new ActiveXObject('Msxml2.XMLHTTP.6.0');}, function(){return new ActiveXObject('Msxml2.XMLHTTP.3.0');}, function(){return new ActiveXObject('Msxml2.XMLHTTP');}, function(){return new ActiveXObject('Microsoft.XMLHTTP');}, ]; window.addEventListener('message', recieveMessage, false ); document.addEventListener('DOMContentLoaded', start, false ); function start() { try{ removeAds(); var pladform = detectPladformIFrames(); if( pladform ) { console.log('embeded video from pladform.ru'); return; } var video_path = findVideoPath();// get video path name '/v/{numbers}/{videoid}.mpd' from current html source page if( !video_path ) throw new Error("can't find video path"); var xhr = createXMLHttpObject(); xhr.onreadystatechange = function() { if( xhr.readyState == 4 && xhr.status == 200 ) { var video_link = findVideoLink( xhr.responseText );// get downloadable video link if( !video_link ) { console.error("[start] can't find video source link"); return; } clog('video link: ', video_link); var stat = insertLink( video_link );// try to insert the link into 'video_size' element of html source page if( stat !== 0 )// if failed to insert the link then { if( window.parent !== window.self && POSTMessage )// if not in parent window then post video_link to parent window.parent.postMessage( video_link + '&id=' + video_path.match(/\d+\.mpd/)[0].slice(0,-4), '*'); window.location = video_link;// open it in current page } } }; clog('video path: ', video_path); xhr.open('GET', video_path, true);// send 'GET' request to 'http://video.sibnet.ru/v/{numbers}/{videoid}.mpd' xhr.send(null); }catch(e){ console.error("[start] ", e); } } function findVideoPath() { var video, source_str, pos, end; try{ video = document.getElementById('video'); if( video ) source_str = video.innerHTML; else source_str = document.body.innerHTML; pos = source_str.indexOf( "player.src([{src: \"" ); if( pos == -1 ) throw new Error("matching 'player.src([{src: \"' string not found"); pos = source_str.indexOf("/v/", pos); end = source_str.indexOf(".mpd", pos); if( end == -1 ) throw new Error("matching '.mpd' string not found"); return source_str.substring(pos, end+4); }catch(e){ console.error("[findVideoPath] ", e); return null; } } function createXMLHttpObject() // create xhr object { for( var i = 0; i < XMLHTTPFactory.length; ++i ) { try{ return XMLHTTPFactory[i](); }catch(e){} } console.error("[createXMLHttpObject] can't create xhr object"); return null; } function removeAds() { try{document.querySelector('.main tbody').children[0].innerHTML = '