// ==UserScript==
// @name 腾讯,爱奇艺,优酷。B站VIP解析+B站下载(乔帅分享)
// @namespace http://tampermonkey.net/
// @version 1.3
// @description 界面优化版:输入框提示文字 + 接口中文别名,隐藏真实地址
// @author 乔帅
// @match *://*/*
// @grant GM_openInTab
// @grant GM_download
// @grant GM_xmlhttpRequest
// @require https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// 解析接口列表:显示名+真实地址
const parserList = [
{ name: '虾米解析', url: 'https://jx.yparse.com/index.php?url=' },
{ name: '云解析1', url: 'https://jx.xmflv.cc/?url=' },
{ name: '云解析2', url: 'https://jx.playerjy.com/?url=' },
{ name: '高清解析', url: 'https://www.8090g.cn/jiexi/?url=' },
{ name: '备用解析', url: 'https://www.ckplayer.vip/jiexi/?url=' }
];
// 创建缩小版深色悬浮窗,默认右下角
function createFloatWindow() {
const style = document.createElement('style');
style.innerHTML = `
#videoToolWindow {
position: fixed;
/* 默认右下角停靠 */
right: 15px;
bottom: 15px;
width: 420px;
height: 360px;
background: #222831;
color: #eee;
z-index: 999999;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0,0,0,0.5);
font-family: "微软雅黑", sans-serif;
overflow: hidden;
}
#videoToolWindow .drag-bar {
width: 100%;
height: 28px;
background: #393E46;
cursor: move;
line-height: 28px;
padding-left: 12px;
box-sizing: border-box;
font-weight: bold;
font-size: 13px;
}
#videoToolWindow .close-btn {
position: absolute;
right: 12px;
top: 0;
cursor: pointer;
color: #ff6b6b;
font-size: 16px;
}
#videoToolWindow input,
#videoToolWindow select {
background: #393E46;
color: #fff;
border: 1px solid #4a4f5a;
border-radius: 4px;
outline: none;
padding: 0 6px;
}
#videoToolWindow button {
background: #00adb5;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}
#videoToolWindow button:hover {
opacity: 0.9;
}
.divider-line {
height: 1px;
background: #444;
margin: 10px 0;
}
`;
document.head.appendChild(style);
const win = document.createElement('div');
win.id = 'videoToolWindow';
win.innerHTML = `
二合一工具
✕
VIP视频解析
B站1080P下载
状态:准备就绪
支持BV/番剧EP链接,自动下载MP4
`;
document.body.appendChild(win);
// 窗口拖动
makeDraggable(win);
// 关闭按钮
win.querySelector('.close-btn').onclick = () => win.remove();
return win;
}
// 拖动逻辑
function makeDraggable(el) {
const bar = el.querySelector('.drag-bar');
let ox = 0, oy = 0, dragging = false;
bar.onmousedown = e => {
dragging = true;
ox = e.clientX - el.getBoundingClientRect().left;
oy = e.clientY - el.getBoundingClientRect().top;
};
document.onmousemove = e => {
if (!dragging) return;
el.style.left = e.clientX - ox + 'px';
el.style.right = 'auto';
el.style.top = e.clientY - oy + 'px';
el.style.bottom = 'auto';
};
document.onmouseup = () => dragging = false;
}
// 绑定所有事件
function bindEvents(win) {
const $ = s => win.querySelector(s);
// 清空按钮
$('#vipClear').onclick = () => $('#vipUrl').value = '';
$('#biliClear').onclick = () => $('#biliUrl').value = '';
// 跳转网站
$('#toIqiyi').onclick = () => window.open('https://www.iqiyi.com');
$('#toTencent').onclick = () => window.open('https://v.qq.com');
$('#toYouku').onclick = () => window.open('https://youku.com');
$('#toBilibili').onclick = () => window.open('https://www.bilibili.com');
$('#toBiliHome').onclick = () => window.open('https://www.bilibili.com');
// VIP解析播放
$('#playVip').onclick = () => {
let url = $('#vipUrl').value.trim();
if (!url) return alert('请输入视频链接');
if (!url.startsWith('http')) url = 'https://' + url;
const index = $('#parserSelect').value;
const parserUrl = parserList[index].url;
window.open(parserUrl + encodeURIComponent(url));
};
// 状态更新
function setStatus(text) {
$('#status').innerText = '状态:' + text;
}
// 解析B站视频
async function parseBilibili(url) {
const res = await axios.get(url, { headers: { Referer: 'https://www.bilibili.com/' } });
const html = res.data;
const match = html.match(/window\.__INITIAL_STATE__=(.*?)(?:\}\;|\);\(function\(\))/);
if (!match) return [];
const data = JSON.parse(match[1]);
const videos = [];
const qn = '112';
if (url.includes('/bangumi/play/ep')) {
const ep = data.epInfo;
videos.push({
title: ep.share_copy,
url: `https://api.bilibili.com/x/player/playurl?cid=${ep.cid}&avid=${ep.aid}&qn=${qn}`
});
} else if (url.includes('/video/BV')) {
const vd = data.videoData;
const aid = vd.aid;
for (let p of vd.pages) {
const title = vd.pages.length > 1 ? p.part : vd.title;
videos.push({
title: title,
url: `https://api.bilibili.com/x/player/playurl?cid=${p.cid}&avid=${aid}&qn=${qn}`
});
}
}
return videos;
}
// 下载视频
async function downloadVideo(info) {
return new Promise(async resolve => {
try {
const res = await axios.get(info.url, { headers: { Referer: 'https://www.bilibili.com/' } });
const d = res.data;
if (d.code !== 0) return resolve();
let title = info.title.replace(/[\\/:*?"<>|]/g, '') + '.mp4';
GM_download({
url: d.data.durl[0].url,
name: title,
headers: { Referer: 'https://www.bilibili.com/' },
onload: resolve,
onerror: resolve
});
} catch (e) { resolve(); }
});
}
// 开始下载
$('#startDownload').onclick = async () => {
const url = $('#biliUrl').value.trim();
if (!url) return alert('请输入B站链接');
setStatus('正在解析...');
try {
const list = await parseBilibili(url);
if (!list.length) {
setStatus('解析失败');
return alert('解析失败,检查链接');
}
setStatus(`准备下载${list.length}个视频`);
for (let item of list) await downloadVideo(item);
setStatus('全部下载完成');
alert('B站视频下载完成!');
} catch (e) {
setStatus('解析出错');
}
};
}
// 初始化启动
const win = createFloatWindow();
bindEvents(win);
})();