// ==UserScript== // @name 直播流获取 // @namespace mscststs // @version 0.51 // @description bilibili 获取直播流 // @author mscststs // @match https://live.bilibili.com/blanc/* // @match https://live.bilibili.com/* // @require https://greasyfork.org/scripts/38220-mscststs-tools/code/MSCSTSTS-TOOLS.js?version=713767 // @require https://cdn.bootcss.com/jquery/3.3.1/jquery.js // @grant GM_setValue // @grant GM_getValue // @grant GM_addValueChangeListener // @grant GM_registerMenuCommand // @downloadURL none // ==/UserScript== (function() { 'use strict'; /** 工具库,拷贝 */ const valueKey = "bilibili_live_stream_invisible" let showBtn = 0, closeBtn = 0; if(GM_getValue(valueKey,0)){ $("body").append(``) showBtn = GM_registerMenuCommand( "隐藏右下角菜单",()=>{ GM_setValue(valueKey,false); location.reload(); }); }else{ $("body").append(``) closeBtn = GM_registerMenuCommand( "显示右下角菜单",()=>{ GM_setValue(valueKey,true); location.reload(); }); } function msg(text,level,time,left,top){ text=text||"这是一个提示"; level=level||"success"; time=time||2000; if(level!="success"){ console.log(text); } var id = (new Date()).valueOf(); $("body").append(''); $("div.link-toast[data-id='"+id+"']").slideDown("normal",function(){setTimeout(function(){$("div.link-toast[data-id='"+id+"']").fadeOut("normal",function(){$("div.link-toast[data-id='"+id+"']").remove();});},time);}); } window.copy = window.copy || function (url) { const input = document.createElement('input'); input.setAttribute('value', url); input.setAttribute('readonly', 'readonly'); document.body.appendChild(input); input.select(); input.setSelectionRange(0, 99999999999); if (document.execCommand('copy')) { document.execCommand('copy'); console.log('复制成功',url); } document.body.removeChild(input); } let roomid = (()=>{ try{ let [[,roomid]] = [...window.location.pathname.matchAll(/\/(\d{1,})/g)] return roomid }catch(e){ return false; } })() console.log("roomid >>>>",roomid ) if(roomid){ (async ()=>{ $("body").append(` `) let {data:{play_url}} = await (await fetch(`https://api.live.bilibili.com/xlive/web-room/v1/index/getRoomPlayInfo?room_id=${roomid}&play_url=1&mask=1&qn=20000&platform=web`)).json() console.log(play_url.durl[0].url) $("div.right-container").prepend( `

直播流获取器

`) let contextMenu = await mscststs.wait("ul[class^=_web-player-context-menu_]"); const hash = contextMenu.className.split("_").reverse()[0]; $(contextMenu).prepend(`
  • 复制直播流地址
  • `) $("body").on("click",".stream_link",function(e){ var url = $(this).attr("data-url"); console.log("url",url,e) window.copy(url) msg("复制成功","success",2000,e.pageX+"px",e.pageY+"px") document.querySelector(("ul[class^=_web-player-context-menu_]")).style.opacity=0 // 隐藏contextMenu }); })() } // Your code here... })();