// ==UserScript== // @name 视频嗅探 // @namespace http://tampermonkey.net/ // @version 0.2 // @description 自动嗅探页面上的视频资源,将链接展示出来,并提供复制和下载方法(除部分流媒体不能下载,需要专用的下载器)。 // @author geigei717 // @license MIT // @match https://*/* // @match http://*/* // @icon https://img-blog.csdnimg.cn/20181221195058594.gif // @require https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js // @grant GM_addElement // @grant GM_download // @grant GM_setClipboard // @downloadURL none // ==/UserScript== (function() { GM_addElement('script', { src: 'https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js', type: 'text/javascript' }); let URLs = []; unsafeWindow.GM_D = []; unsafeWindow.download = function (url,name){ GM_download(url, name); } //$("head").append(' ') var m = -1,n=0; $("body").append("") .append("
" + "+" + "
") $(".MyUrls").append("
") //下载链接 $(".SaveUrl1").click(function (){ //$(obj).attr("disabled","disabled") var that = $(this) $(that).css("display","none").next('.StopSaveUrl1').css("display","inline-block") var url = $(that).prevAll(".downUrl").val() var name = $(that).prevAll(".downName").val() if(name.trim()==""||name==undefined){ name = url.split("/").pop().split("?")[0] if(name.trim() ==''||name==undefined){ name = "video.mp4"} } if(! /\.[\w]+$/.test(name)){ name = name + ".mp4"} const download = GM_download({ url: url, name: name, onprogress : function (event) { if (event.lengthComputable) { var loaded = parseInt(event.loaded / event.total * 100); if(loaded==100){ $(that).text("下载").css("display","inline-block").next('.StopSaveUrl1').css("display","none") }else{ $(that).next('.StopSaveUrl1').text(loaded+"%") } } }, onload : function () { $(that).text("下载").css("display","inline-block").next('.StopSaveUrl1').css("display","none").text("0%") }, onerror : function () { $(that).text("继续").css("display","inline-block").next('.StopSaveUrl1').css("display","none") } }); var num =GM_D.push(download) $(that).next('.StopSaveUrl1').data('num',num-1) }) $(".StopSaveUrl1").click(function (){ var num = $(this).data("num") GM_D[num].abort() //GM_D.splice(num,1); }) for(var i=0;i<100;i++){ $(".MyUrls").append("") } $("#MyUpDown").click(function () { $("#MyUrls").slideToggle("slow", function () { if (m=="1"){ $("#MyUpDown span").text('+') }else { $("#MyUpDown span").text('–') } m = -m; }); }) //复制链接 $(".GoUrl").click(function (){ var url = $(this).prevAll("p").attr("title") window.open(url) }) //复制链接 $(".CopyUrl").click(function (){ var url = $(this).prevAll("p").attr("title") GM_setClipboard(url); $(this).text("已复制") }) //下载链接 $(".SaveUrl").click(function (){ //$(obj).attr("disabled","disabled") var that = $(this) $(that).css("display","none").next('.StopSaveUrl').css("display","inline-block") var url = $(that).prevAll("p").attr("title") var name = url.split("/").pop().split("?")[0] if(name==''||name==undefined){ name = "video.mp4"} if(! /\.[\w]+$/.test(name)){ name = name + ".mp4"} const download = GM_download({ url: url, name: name, onprogress : function (event) { if (event.lengthComputable) { var loaded = parseInt(event.loaded / event.total * 100); if(loaded==100){ $(that).text("下载").css("display","inline-block").next('.StopSaveUrl').css("display","none") }else{ $(that).next('.StopSaveUrl').text(loaded+"%") } } }, onload : function () { $(that).text("下载").css("display","inline-block").next('.StopSaveUrl').css("display","none").text("0%") }, onerror : function () { $(that).text("继续").css("display","inline-block").next('.StopSaveUrl').css("display","none") } }); var num =GM_D.push(download) $(that).next('.StopSaveUrl').data('num',num-1) }) $(".StopSaveUrl").click(function (){ var num = $(this).data("num") GM_D[num].abort() }) function getNetworkRequsts(){ return performance.getEntriesByType("resource").filter((entry) => { return entry.initiatorType === "xmlhttprequest"||entry.initiatorType === "video"; }); } var observer = new PerformanceObserver(perf_observer); observer.observe({entryTypes: ["resource"]}) function perf_observer(list,observer){ var z var scripts =getNetworkRequsts() scripts.forEach(function (x,i) { if (x.initiatorType === "xmlhttprequest") { z = x.name if(/m3u8/.test(x.name) && !/\.ts/.test(x.name)){ if(! URLs.includes(z) ){ URLs.push(z) //console.log('type: m3u8 , url: ' + x.name) $(".urlnone").remove() $(".MyUrls .noneUrl:first").css("display","block").attr("class","isUrl").children("p").attr('title',z).text(z).nextAll(".SaveUrl").css("display","none") //$(".MyUrls").append("
") } }else if(/\.mp4$/.test(z.split('?')[0])){ if(! URLs.includes(z) ){ URLs.push(z) //console.log('type: m3u8 , url: ' + x.name) $(".urlnone").remove() $(".MyUrls .noneUrl:first").css("display","block").attr("class","isUrl").children("p").attr('title',z).text(z) //$(".MyUrls").append("
") } } } if (x.initiatorType === "video" && !/\.jpg/.test(x.name)) { z = x.name if(! URLs.includes(z) ){ URLs.push(z) //console.log('type: video , url: ' + x.name) $(".urlnone").remove() $(".MyUrls .noneUrl:first").css("display","block").attr("class","isUrl").children("p").attr('title',z).text(z) //$(".MyUrls").append("
") } } }) $("video").each(function () { if(!/^blob:/.test(this.currentSrc)){ z = this.currentSrc if(! URLs.includes(z)&& this.currentSrc!=""){ URLs.push(z) //console.log('type: video , url: ' + this.currentSrc) $(".urlnone").remove() $(".MyUrls .noneUrl:first").css("display","block").attr("class","isUrl").children("p").attr('title',z).text(z) //$(".MyUrls").append("
") } } $(this).find("source").each(function () { if($(this).attr('src')!=''&&$(this).attr('src')!=undefined){ if(!/^(http:|https:)/.test($(this).attr('src'))){ z = location.href.split("://")[0] +':'+ $(this).attr('src') }else{ z = $(this).attr('src') } if(! URLs.includes(z) && z != ""){ URLs.push(z) //console.log('type: src , url: ' + z) $(".urlnone").remove() $(".MyUrls .noneUrl:first").css("display","block").attr("class","isUrl").children("p").attr('title',z).text(z) //$(".MyUrls").append("
") } } }) }) //if(URLs.length>0 && $("#MyUrls").css("display")=="none"&& n==0){ // $("#MyUpDown").click() // n = 1 //} } })();