// ==UserScript== // @name Download Sibnet Video as MP4 // @namespace http://video.sibnet.ru // @description Выдает ссылку на видео в правом нижнем углу плеера // @include *://video.sibnet.ru/* // @version 1.2.14 // @author Iron_man // @grant GM_xmlhttpRequest // @downloadURL none // ==/UserScript== window.addEventListener('message', recieveMessage, false ); document.addEventListener('DOMContentLoaded', start, false ); var postMessage = true; var clickCancel = true; function start() { removeAds(); if( clickCancel ) setCancelPostvideo(); var pladform = detectPladformIFrames(); if( pladform ) { console.log('embeded video from pladform.ru'); return; } var video_path = getVideoPath();// get video path name '/v/{numbers}/{videoid}.mpd' from current html source page console.log("video path: " + video_path); if( video_path ) { GM_xmlhttpRequest({ url: video_path, method: 'HEAD', onload: makeVideoLink, }); } } function getVideoPath() { var video, source_str, pos, end; 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 ) return null; pos = source_str.indexOf("/v/", pos); end = source_str.indexOf(".mpd", pos); if( end == -1 ) return null; return source_str.substring(pos, end+4); } function makeVideoLink( xhr ) { var video_link = xhr.finalUrl.replace('/manifest.mpd', '.mp4');// get downloadable video link console.log("video file: ", video_link); if( !video_link ) { console.error("[makeVideoLink] can't find video source link"); return; } 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=' + this.url.match(/\d+\.mpd/)[0].slice(0,-4), '*'); window.location.href = video_link;// open it in current page } } function insertLink( source_link, size_mb ) // insert hyper reference into video_size element { var video_size = document.getElementsByClassName('video_size')[0]; if( !video_size ) return 1; video_size.innerHTML = '' + '' + ( size_mb ? size_mb : video_size.innerHTML ) + ''; return 0; } function removeAds() { var tbody = document.querySelector('.main tbody'); if( tbody && tbody.children && tbody.children[0] ) tbody.children[0].innerHTML = '