哔哩哔哩扩展
// ==UserScript==
// @name BiliBiliEX
// @name:zh-CN 哔哩哔哩扩展
// @namespace FyrGlow.BiliBili
// @version 1.0
// @description BiliBili Enhance
// @description:zh-CN 对哔哩哔哩添加一些扩展功能
// @author FyrGlow
// @match https://www.bilibili.com/video/*
// @require https://gitee.com/ASev/chrome/raw/master/SharedArrayBuffer.js
// @require https://update.greasyfork.org/scripts/4274/13748/FileSaverjs.js
// @require https://cdn.jsdelivr.net/npm/@ffmpeg/ffmpeg@0.11.6/dist/ffmpeg.min.js
// @icon https://static.hdslb.com/images/favicon.ico
// @homepage https://space.bilibili.com/266986139
// @grant none
// @license CC BY-NC-ND
// ==/UserScript==
(function () {
'use strict';
function log(string) {
console.log(string);
}
function getVideoBV(url) {
const pattern = /BV[0-9A-Za-z]+(?![\w\s])/;
const result = url.match(pattern);
return result ? result[0] : null;
}
// 正则表达式匹配BV号 函数
async function getBvJson(Burl) {
const url = Burl
try {
const response = await fetch(url, {
credentials: 'include'
});
if (!response.ok) {
throw new Error(`HTTP错误! 状态: ${response.status}`);
}
const json = await response.json();
return json;
} catch (error) {
// 处理错误
console.error('获取JSON出错:', error);
}
}
// 获取视频信息 函数
function getElementsXY(elements) {
var elementsXY = document.getElementsByClassName(elements);
for (var i = 0; i < elementsXY.length; i++) {
var elementXY = elementsXY[i];
var rectXY = elementXY.getBoundingClientRect();
}
return rectXY;
}
// 取元素矩形信息
function SynElement(OElement, IElement) {
var sourceIcon = document.querySelector(OElement);
var styles = window.getComputedStyle(sourceIcon);
var targetIcon = document.querySelector(IElement);
Object.keys(styles).forEach(function (key) {
var property = styles[key];
if (property && property !== 'undefined' && targetIcon.style.setProperty) {
targetIcon.style.setProperty(key, property, styles.getPropertyPriority(key));
}
});
}
// 同步元素样式
function createNewBDB(xz, EBYID, id) {
var newDivBDB = document.createElement('div');
if (xz == 1) {
newDivBDB.innerHTML = `<div class="bpx-player-dm-setting-right-fontborder-content bui bui-radio bui-dark" style="margin-bottom: 10px;" id="bpdsrfc1"><div class="bui-area"><div class="bui-radio-wrap bui-radio-button"><div class="bui-radio-group" style="margin: 0 -4px;height: 28px;"><label class="bui-radio-item" style="margin: 0 4px;"><input class="bui-radio-input" value="0" name="xzzlxz" type="radio" id="${id}"><span class="bui-radio-label"><span class="bui-radio-text">${id}</span></span></label></div></div></div></div>`;
} else if (xz == 2) {
newDivBDB.innerHTML = `<div class="bpx-player-dm-setting-right-fontborder-content bui bui-radio bui-dark" style="margin-bottom: 10px;" id="bpdsrfc2"><div class="bui-area"><div class="bui-radio-wrap bui-radio-button"><div class="bui-radio-group" style="margin: 0 -4px;height: 28px;"><label class="bui-radio-item" style="margin: 0 4px;"><input class="bui-radio-input" value="0" name="xzgsxz" type="radio" id="${id}"><span class="bui-radio-label"><span class="bui-radio-text">${id}</span></span></label></div></div></div></div>`;
}
var parentDiv = document.getElementById(EBYID);
if (parentDiv) {
parentDiv.insertAdjacentElement('afterend', newDivBDB);
} else {
console.error('找不到ID为' + EBYID + '的元素');
}
}
// 选择插入位置
function removeDiv(ID) {
var elements = document.querySelectorAll('#' + ID);
elements.forEach(function (element) {
element.remove();
});
}
// 删除元素
function toggleElements(height, width, translateX) {
var bpia = document.getElementById('bpia');
bpia.style.width = width + 'px';
bpia.style.height = height + 'px';
var bpmtra = document.getElementById('bpmtra');
bpmtra.style.transform = 'translateX(' + translateX + 'px)';
var bdcbpw = document.getElementById('bdcbpw');
bdcbpw.style.height = height + 'px';
var bpiac = document.getElementById('bpiac');
bpiac.style.height = height + 'px';
}
// 切换页面大小函数
function toggleWrap(show) {
var etw = document.querySelectorAll('.bpx-player-top-wrap');
var ecw = document.querySelectorAll('.bpx-player-control-wrap');
etw.forEach(function (element) {
element.style.display = show ? 'block' : 'none';
});
ecw.forEach(function (element) {
element.style.display = show ? 'block' : 'none';
});
}
// 切换warp的显示状态
function addInputEvent(name) {
var radioButtons = document.querySelectorAll('input[type="radio"][name="' + name + '"]');
radioButtons.forEach(function (radio) {
radio.addEventListener('change', function (event) {
if (this.checked) {
removeDiv('bpdsrfc2')
addFormat(this.id);
}
});
});
}
// 添加选择事件
function addFormat(ID) {
const BvSF = BvJson.data.support_formats;
for (var i = BvSF.length - 1; i >= 0; i--) {
if (BvSF[i].new_description == ID) {
const BvCodecs = BvSF[i].codecs;
var BCCount = BvCodecs.length;
BDSW2height = 70 + (BCCount * 38);
for (var j = BCCount - 1; j >= 0; j--) {
createNewBDB(2, 'bdwd', BvCodecs[j]);
if (j === 0) {
var av01 = document.getElementById(BvCodecs[j]);
av01.checked = true;
}
}
setFormatSettingText('选择 [ ' + ID + ' ] 的视频格式')
}
}
}
// 为指定质量视频添加格式选择
function setFormatSettingText(newText) {
const formatSettingElement = document.querySelector('#bpdslm .bpx-player-dm-setting-left-more-text');
formatSettingElement.textContent = newText;
}
// 设置格式选择的导航提醒
function checkJsonPathValue(jsonObj, path, content) {
function getValueFromPath(obj, keys) {
if (!keys.length) {
return [obj];
}
if (Array.isArray(obj)) {
let result = [];
for (let item of obj) {
result = result.concat(getValueFromPath(item, keys));
}
return result;
} else if (obj !== null && typeof obj === 'object' && keys[0] in obj) {
return getValueFromPath(obj[keys[0]], keys.slice(1));
} else {
return [];
}
}
let keys = path.split('.');
let values = getValueFromPath(jsonObj, keys);
return values.includes(content);
}
// 接受三个函数:json、路径、值 | 如果存在返回true
function StartDownload() {
var spzlID = SeltctedID('xzzlxz');
var spgsID = SeltctedID('xzgsxz');
var spzlQID = findQualityByDescription(BvJson, spzlID);
var spLink = findBaseUrlByIdAndCodecs(BvJson, spzlQID, spgsID);
var ypLink = BvJson.data.dash.audio[0].baseUrl;
var BiliURL = window.location.href;
var BVString = getVideoBV(BiliURL);
var BVtitle = document.title.match(/^[^_]+/);
if (yspxz.checked) {
startDownloadBVM(spLink, ypLink, `${BVtitle[0]}_${BVString}_${spzlID}.mp4`);
} else {
if (spxz.checked) {
startDownloadBV(spLink, `video_${BVtitle[0]}_${BVString}_${spzlID}.mp4`);
}
if (ypxz.checked) {
startDownloadBV(ypLink, `audio_${BVtitle[0]}_${BVString}.mp3`);
}
}
}
// 预备开始下载
const fetchFile = async (url, merge) => {
const text = document.querySelector('.video-title.special-text-indent');
const oldtext = text.textContent;
const res = await fetch(url);
const reader = res.body.getReader();
const contentLength = +res.headers.get("Content-Length");
if (!contentLength) {
const data = await res.arrayBuffer();
return new Uint8Array(data);
}
let receivedLength = 0;
let chunks = [];
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
chunks.push(value);
receivedLength += value.length;
console.log(
`文件总大小: ${contentLength} %c 已下载: ${receivedLength}`,
"background: #222; color: #bada55"
);
let percentage = (receivedLength / contentLength) * 100;
text.textContent = '正在下载,进度:' + percentage.toFixed(2) + '%';
}
text.textContent = oldtext;
if (merge === false) {
return new Blob(chunks);
} else {
let chunksAll = new Uint8Array(receivedLength);
let position = 0;
for (let chunk of chunks) {
chunksAll.set(chunk, position);
position += chunk.length;
}
return chunksAll;
}
};
// 下载文件
const Download = async (data, fileName = "download.mp4") => {
saveAs(data, fileName);
};
const startDownloadBV = async (Url, fileName) => {
const downFile = await fetchFile(Url, false);
Download(downFile, fileName);
console.log(
`%c 下载完成!`,
"background: #222; color: #bada55"
);
};
// 下载单文件
const startDownloadBVM = async (videoUrl, audioUrl, fileName) => {
const video = await fetchFile(videoUrl, true);
const audio = await fetchFile(audioUrl, true);
const downFile = await FFMerge(video, audio);
Download(downFile, fileName);
console.log(
`%c 下载合并完成!`,
"background: #222; color: #bada55"
);
};
// 下载合并文件
function SeltctedID(name) {
var selectedRadio = document.querySelector('input[name=' + name + ']:checked');
if (selectedRadio) {
var selectedId = selectedRadio.id;
return selectedId;
} else {
console.log('错误:没有ID为' + name + '的选项');
}
}
// 获取单选框所选中ID
function findQualityByDescription(Json, spzlID) {
for (var i = 0; i < Json.data.support_formats.length; i++) {
if (Json.data.support_formats[i].new_description === spzlID) {
return Json.data.support_formats[i].quality;
}
}
return 80;
}
// 获取视频质量ID
function findBaseUrlByIdAndCodecs(Json, spzlQID, spgsID) {
for (var i = 0; i < Json.data.dash.video.length; i++) {
if (Json.data.dash.video[i].id === spzlQID && Json.data.dash.video[i].codecs === spgsID) {
return Json.data.dash.video[i].baseUrl;
}
}
return null;
}
// 获取视频下载链接
const initFFmpeg = () => {
const { createFFmpeg } = FFmpeg;
let ffmpeg = null;
if (ffmpeg === null) {
ffmpeg = createFFmpeg({ log: false });
}
if (!ffmpeg.isLoaded()) {
ffmpeg.load();
}
return ffmpeg;
};
// 初始化FFmpeg
const FFMerge = async (video, audio) => {
if (!ffmpeg.isLoaded()) {
await ffmpeg.load();
}
ffmpeg.FS("writeFile", "video.mp4", video);
ffmpeg.FS("writeFile", "audio.mp3", audio);
await ffmpeg.run(
...`-i video.mp4 -i audio.mp3 -c copy -map 0:v:0 -map 1:a:0 output.mp4`.split(
" "
)
);
const data = ffmpeg.FS("readFile", "output.mp4");
return new Blob([data.buffer], { type: "video/mp4" });
};
// 合并音视频
// --------On函数群--------
var BDSWheight = 175;
var BDSW2height = 76;
var BvJson;
var FullScreen = false;
// --------On全局变量--------
function AllStart() {
var elements = document.querySelectorAll('.bd-down-dl-open');
elements.forEach(function (element) {
element.remove();
});
toggleWrap(true);
// 删除遗留元素
var originalDiv = document.querySelector('.bpx-player-dm-setting');
var newDiv = document.createElement('div');
newDiv.className = 'bd-down-dl-open';
newDiv.innerHTML = '<span class="bd-down-svg-icon"><svg t="1716541874583" class="icon" viewBox="0 0 1029 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2089" width="22.4375px" height="21px" style="padding-top: 1.8;"><path d="M487.966546 867.289336c-0.191055 0-0.38211 0-0.577318-0.008306-85.119089-0.926201-171.396967-8.3898-256.428835-22.178976a29.812863 29.812863 0 0 0-0.598085-0.095528c-75.890309-13.224318-150.032051-79.636645-165.274905-148.050895l-0.161981-0.751759c-33.405525-161.104925-33.405525-324.473435 0-485.570054 0.053994-0.249202 0.103834-0.498404 0.161981-0.743452C80.326104 141.467809 154.471999 75.051329 230.370615 61.835317l0.593931-0.09968a1713.961362 1713.961362 0 0 1 550.250427 0.09968c75.890309 13.207705 150.036204 79.624185 165.279059 148.055049 0.058147 0.249202 0.107988 0.494251 0.157827 0.743452 21.672265 104.444702 29.385067 210.417843 22.943196 314.962227-1.761027 28.620847-26.390489 50.355413-55.011337 48.627612-28.625001-1.765181-50.38864-26.390489-48.627612-55.011336 5.864553-95.195155-1.158789-191.769229-20.878973-287.043298-6.836441-29.630115-51.015798-62.56631-81.414286-67.99476a1610.243499 1610.243499 0 0 0-515.735953 0c-30.394335 5.432603-74.577845 38.368798-81.422593 67.990606-30.377721 146.817345-30.381874 295.690607 0 442.512105 6.853054 29.621808 51.028258 62.55385 81.422593 67.986453 79.81524 12.925276 160.756042 19.923698 240.587896 20.791752 28.670688 0.315656 51.65957 23.802942 51.352221 52.481936-0.311502 28.479633-23.49144 51.352221-51.900465 51.352221z" p-id="2090"></path><path d="M727.790223 570.539621c20.272581 20.272581 53.150628 20.276734 73.427362 0s20.276734-53.146475 0-73.423209l-102.762589-102.766742a51.917079 51.917079 0 0 0-73.427362 0l-86.036983 86.036982-66.055138-66.055137c-20.272581-20.272581-53.146475-20.272581-73.423209 0l-162.716431 162.712278c-20.272581 20.280888-20.272581 53.150628 0 73.423209a51.759251 51.759251 0 0 0 36.711604 15.209628c13.286619 0 26.573238-5.075414 36.711605-15.209628l126.004827-126.004826 66.055137 66.055137c20.276734 20.280888 53.146475 20.280888 73.419056 0l86.04529-86.036983 66.046831 66.059291zM974.911364 766.408222c-20.272581-20.272581-53.142322-20.272581-73.427363 0l-40.877431 40.881585v-133.318905c0-28.670688-23.246391-51.917079-51.917079-51.917079s-51.917079 23.246391-51.917078 51.917079v133.318905l-40.877432-40.881585c-20.285041-20.272581-53.154782-20.272581-73.427362 0-20.272581 20.280888-20.272581 53.150628 0 73.427363l129.510268 129.501961c10.138367 10.134214 23.424986 15.205474 36.711604 15.205474s26.569084-5.07126 36.711605-15.205474l129.510268-129.501961c20.268428-20.276734 20.268428-53.146475 0-73.427363z" p-id="2091"></path></svg></span><div class="bpx-player-dm-setting-wrap" style="height: 350px; bottom: 50px; display: none;" id="bd-setting-warp"><div class="bpx-player-dm-setting-box bui bui-panel bui-dark"><div class="bui-area"><div class="bui-panel-wrap" style="width: 320px;height: 175px;" id="bdcbpw"><div class="bui-panel-move" style="width: 586px; transform: translateX(0px);" id="bpmtra"><div class="bui-panel-item bui-panel-item-active" style="width: 320px;height: 175px;" id="bpiac"><div class="bpx-player-dm-setting-left"><div class="bpx-player-dm-setting-left-block"><div class="bpx-player-dm-setting-left-block-title">选择下载类型</div><div class="bpx-player-dm-setting-left-radio" style="margin-bottom: 0px;"><span class="bpx-player-dm-setting-left-fs bui bui-checkbox bui-dark" style="margin-right: 8px;"><div class="bui-area"><input class="bui-checkbox-input" type="checkbox" aria-label="音视频下载" id="yspxz"><label class="bui-checkbox-label"><span class="bui-checkbox-icon bui-checkbox-icon-default"><svg xmlns="http://www.w3.org/2000/svg" data-pointer="none" viewBox="0 0 32 32"><path d="M8 6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2H8zm0-2h16c2.21 0 4 1.79 4 4v16c0 2.21-1.79 4-4 4H8c-2.21 0-4-1.79-4-4V8c0-2.21 1.79-4 4-4z"></path></svg></span><span class="bui-checkbox-icon bui-checkbox-icon-selected"><svg xmlns="http://www.w3.org/2000/svg" data-pointer="none" viewBox="0 0 32 32"><path d="m13 18.25-1.8-1.8c-.6-.6-1.65-.6-2.25 0s-.6 1.5 0 2.25l2.85 2.85c.318.318.762.468 1.2.448.438.02.882-.13 1.2-.448l8.85-8.85c.6-.6.6-1.65 0-2.25s-1.65-.6-2.25 0l-7.8 7.8zM8 4h16c2.21 0 4 1.79 4 4v16c0 2.21-1.79 4-4 4H8c-2.21 0-4-1.79-4-4V8c0-2.21 1.79-4 4-4z"></path></svg></span><span class="bui-checkbox-name">音视频下载</span></label></div></span><span class="bpx-player-dm-setting-left-ps bui bui-checkbox bui-dark"><div class="bui-area"><input class="bui-checkbox-input" type="checkbox" aria-label="视频下载" id="spxz"><label class="bui-checkbox-label"><span class="bui-checkbox-icon bui-checkbox-icon-default"><svg xmlns="http://www.w3.org/2000/svg" data-pointer="none" viewBox="0 0 32 32"><path d="M8 6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2H8zm0-2h16c2.21 0 4 1.79 4 4v16c0 2.21-1.79 4-4 4H8c-2.21 0-4-1.79-4-4V8c0-2.21 1.79-4 4-4z"></path></svg></span><span class="bui-checkbox-icon bui-checkbox-icon-selected"><svg xmlns="http://www.w3.org/2000/svg" data-pointer="none" viewBox="0 0 32 32"><path d="m13 18.25-1.8-1.8c-.6-.6-1.65-.6-2.25 0s-.6 1.5 0 2.25l2.85 2.85c.318.318.762.468 1.2.448.438.02.882-.13 1.2-.448l8.85-8.85c.6-.6.6-1.65 0-2.25s-1.65-.6-2.25 0l-7.8 7.8zM8 4h16c2.21 0 4 1.79 4 4v16c0 2.21-1.79 4-4 4H8c-2.21 0-4-1.79-4-4V8c0-2.21 1.79-4 4-4z"></path></svg></span><span class="bui-checkbox-name">视频下载</span></label></div></span><span class="bpx-player-dm-setting-left-ps bui bui-checkbox bui-dark"><div class="bui-area"><input class="bui-checkbox-input" type="checkbox" aria-label="音频下载" id="ypxz"><label class="bui-checkbox-label"><span class="bui-checkbox-icon bui-checkbox-icon-default"><svg xmlns="http://www.w3.org/2000/svg" data-pointer="none" viewBox="0 0 32 32"><path d="M8 6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2H8zm0-2h16c2.21 0 4 1.79 4 4v16c0 2.21-1.79 4-4 4H8c-2.21 0-4-1.79-4-4V8c0-2.21 1.79-4 4-4z"></path></svg></span><span class="bui-checkbox-icon bui-checkbox-icon-selected"><svg xmlns="http://www.w3.org/2000/svg" data-pointer="none" viewBox="0 0 32 32"><path d="m13 18.25-1.8-1.8c-.6-.6-1.65-.6-2.25 0s-.6 1.5 0 2.25l2.85 2.85c.318.318.762.468 1.2.448.438.02.882-.13 1.2-.448l8.85-8.85c.6-.6.6-1.65 0-2.25s-1.65-.6-2.25 0l-7.8 7.8zM8 4h16c2.21 0 4 1.79 4 4v16c0 2.21-1.79 4-4 4H8c-2.21 0-4-1.79-4-4V8c0-2.21 1.79-4 4-4z"></path></svg></span><span class="bui-checkbox-name">音频下载</span></label></div></span></div></div><div class="bpx-player-dm-setting-left-block-word" style="margin-bottom: 0px;"><div class="bpx-player-dm-setting-left-block-add" id="ksxz" style="color: white;">开始下载</div><div class="bpx-player-dm-setting-left-block-sync" id="qxxz" style="color: white;">取消下载</div></div><div class="bpx-player-dm-setting-right-fontborder" style="margin-top: 12px;"><div class="bpx-player-dm-setting-right-fontborder-title" id="bdws">选择视频质量</div></div><div class="bpx-player-dm-setting-left-more" id="bpdslm"><span class="bpx-player-dm-setting-left-more-text">格式设置</span><span class="bpx-common-svg-icon"><svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" data-pointer="none" viewBox="0 0 16 16"><path d="m9.188 7.999-3.359 3.359a.75.75 0 1 0 1.061 1.061l3.889-3.889a.75.75 0 0 0 0-1.061L6.89 3.58a.75.75 0 1 0-1.061 1.061l3.359 3.358z"></path></svg></span></div></div></div><div class="bui-panel-item bui-panel-item-active" style="width: 250px; height: 175px;" id="bpia"><div class="bpx-player-dm-setting-right"><div class="bpx-player-dm-setting-right-more" id="bpdsrm"><span class="bpx-common-svg-icon"><svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" data-pointer="none" viewBox="0 0 16 16"><path d="m6.811 8.001 3.359-3.359a.75.75 0 1 0-1.061-1.061L5.22 7.471a.75.75 0 0 0 0 1.061l3.889 3.888a.75.75 0 1 0 1.061-1.061L6.811 8.001z"></path></svg></span><span class="bpx-player-dm-setting-right-more-text">返回视频下载</span></div><div class="bpx-player-dm-setting-right-separator" style="margin-left: 20px;"></div><div class="bpx-player-dm-setting-right-fontborder" style="margin-left: 17px;margin-top: 10px;"><div class="bpx-player-dm-setting-right-fontborder-title" id="bdwd">选择视频格式</div></div></div></div></div></div></div></div></div>';
originalDiv.parentNode.insertBefore(newDiv, originalDiv.nextSibling);
// SynElement('.bpx-player-dm-setting-wrap','.bd-down-dl-setting-wrap');
var bdOpen = document.querySelector('.bd-down-svg-icon');
var bdSetting = document.getElementById('bd-setting-warp');
var bdOpenBool = false;
if (bdOpen) {
bdOpen.addEventListener('click', function () {
if (bdOpenBool == false) {
bdSetting.style.display = '';
if (!FullScreen) {
toggleWrap(false)
} else {
toggleWrap(true)
}
bdOpenBool = true;
} else {
bdSetting.style.display = 'none';
toggleWrap(true)
bdOpenBool = false;
}
});
}
// 插入下载按钮元素
SynElement('.bpx-player-dm-switch', '.bd-down-dl-open');
// --brand_blue
var style = document.createElement('style');
style.innerHTML = `.bd-down-svg-icon:hover .icon {fill: var(--brand_blue);}`;
document.head.appendChild(style);
var classMode = document.getElementById('bilibili-player');
new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
if (classMode.className === 'mode-webscreen') {
var svgElements = document.querySelectorAll('.bd-down-svg-icon');
svgElements.forEach(function (svgElement) {
svgElement.style.fill = 'rgba(255, 255, 255, 0.9)';
FullScreen = true;
});
} else {
var svgElements = document.querySelectorAll('.bd-down-svg-icon');
svgElements.forEach(function (svgElement) {
svgElement.style.fill = '#757575';
FullScreen = false;
});
}
}
});
}).observe(classMode, {
attributes: true
});
// 同步元素样式
var yspxz = document.getElementById('yspxz');
var spxz = document.getElementById('spxz');
var ypxz = document.getElementById('ypxz');
var yspxzc = localStorage.getItem('yspxz');
var spxzc = localStorage.getItem('spxz');
var ypxzc = localStorage.getItem('ypxz');
if (yspxzc == null || yspxzc == 1 || (spxzc == 0 && ypxzc == 0)) {
yspxz.checked = true;
}
if (spxzc == 1) {
spxz.checked = true;
}
if (ypxzc == 1) {
ypxz.checked = true;
}
yspxz.addEventListener('change', function () {
if (this.checked) {
localStorage.setItem('yspxz', 1)
localStorage.setItem('spxz', 0)
localStorage.setItem('ypxz', 0)
spxz.checked = false;
ypxz.checked = false;
} else {
if (spxz.checked == false && ypxz.checked == false) {
spxz.checked = true;
localStorage.setItem('spxz', 1)
ypxz.checked = true;
localStorage.setItem('ypxz', 1)
localStorage.setItem('yspxz', 0)
}
}
});
spxz.addEventListener('change', function () {
if (this.checked) {
localStorage.setItem('yspxz', 0)
localStorage.setItem('spxz', 1)
yspxz.checked = false;
} else {
localStorage.setItem('spxz', 0)
if (spxz.checked == false && ypxz.checked == false) {
yspxz.checked = true;
localStorage.setItem('yspxz', 1)
}
}
});
ypxz.addEventListener('change', function () {
if (this.checked) {
localStorage.setItem('yspxz', 0)
localStorage.setItem('ypxz', 1)
yspxz.checked = false;
} else {
localStorage.setItem('ypxz', 0)
if (spxz.checked == false && ypxz.checked == false) {
yspxz.checked = true;
localStorage.setItem('yspxz', 1)
}
}
});
var startBD = document.getElementById('ksxz');
var cancelBD = document.getElementById('qxxz');
startBD.addEventListener('click', function () {
console.log('开始下载!');
StartDownload()
// 在这里添加开始下载的逻辑
});
cancelBD.addEventListener('click', function () {
console.log('我给你取消个蛋!');
// 在这里添加取消下载的逻辑
});
// 设置选择与按钮
const BiliBiliURL = window.location.href;
const BV = getVideoBV(BiliBiliURL);
const BvUrl = `https://api.bilibili.com/x/web-interface/view?bvid=${BV}`;
getBvJson(BvUrl)
.then(BVInfo => {
const Cids = BVInfo.data.pages.map(page => page.cid);
const CidUrl = `https://api.bilibili.com/x/player/wbi/playurl?bvid=${BV}&cid=${Cids[0]}&fnval=4048`;
// log('CidUrl = ' + CidUrl);
getBvJson(CidUrl)
.then(BVInfo => {
BvJson = BVInfo;
const BvFormats = BVInfo.data.support_formats;
var sfcount = BvFormats.length;
var BDSWheightVar = 0;
for (var i = sfcount - 1; i >= 0; i--) {
const BvDescription = BvFormats[i].new_description;
const BvQuality = BvFormats[i].quality;
const DlQuality = "data.dash.video.id";
if (checkJsonPathValue(BVInfo, DlQuality, BvQuality)) {
createNewBDB(1, 'bdws', BvDescription);
var lastBDB = BvDescription;
BDSWheightVar++;
};
}
BDSWheight = 170 + (BDSWheightVar * 38);
toggleElements(BDSWheight, 250, 0);
var topQuality = document.getElementById(lastBDB);
topQuality.checked = true;
addFormat(lastBDB);
addInputEvent('xzzlxz');
})
})
.catch(error => {
console.error('获取视频CID出错:', error);
});
// 获取视频下载地址 添加下载选项
document.getElementById('bpdslm').addEventListener('click', function () {
toggleElements(BDSW2height, 320, -320);
});
document.getElementById('bpdsrm').addEventListener('click', function () {
toggleElements(BDSWheight, 250, 0);
});
// 设置切换页面
}
// 注入功能面板
var checkInterval = setInterval(function () {
var element = document.querySelector('.bpx-player-dm-setting');
if (element) {
AllStart()
clearInterval(checkInterval);
console.log('%c ____ __ _______ __ _____ __ __ __\n / __ )/ / / ____/ |/ / / ___// /_____ ______/ /_/ /\n / __ / / / __/ | / \\__ \\/ __/ __ `/ ___/ __/ / \n / /_/ / /___/ /___ / |_ ___/ / /_/ /_/ / / / /_/_/ \n/_____/_____/_____//_/|_( )____/\\__/\\__,_/_/ \\__(_) \n |/ By BiliBili FyrGlow', 'color: #00a1d6; font-size: 16px;');
}
}, 100); // 持续检测元素 存在则注入面板
const ffmpeg = initFFmpeg();
log(ffmpeg);
// 初始化FFMPEG
function reloadScript() {
AllStart();
console.log('%c ____ __ _______ __ _____ __ __ __\n / __ )/ / / ____/ |/ / / ___// /_____ ______/ /_/ /\n / __ / / / __/ | / \\__ \\/ __/ __ `/ ___/ __/ / \n / /_/ / /___/ /___ / |_ ___/ / /_/ /_/ / / / /_/_/ \n/_____/_____/_____//_/|_( )____/\\__/\\__,_/_/ \\__(_) \n |/ By BiliBili FyrGlow', 'color: #00a1d6; font-size: 16px;');
}
let ourlBV = getVideoBV(window.location.href);
const observer = new MutationObserver(() => {
if (ourlBV !== getVideoBV(window.location.href)) {
ourlBV = getVideoBV(window.location.href);
reloadScript();
}
});
const config = { subtree: true, childList: true };
observer.observe(document, config);
window.addEventListener('popstate', reloadScript);
// 检测URL改变,重载脚本
})();