// ==UserScript==
// @name Bilibili Evolved 强化辅助 (非 Bilibili Evolved 本体)
// @namespace Ninkror
// @version 1.2
// @author Ninkror
// @description 针对 Bilibili Evolved 的辅助脚本,旨在对 Bilibili Evolved 尚未实现的、已实现但不完善的、已经失效的功能进行优化与修复。在动态页对同时使用 Bilibili Evolved 和 “bilibili时间线筛选——分组查看b站动态” 脚本的情况进行了专门优化。
// @match https://live.bilibili.com/*
// @match https://space.bilibili.com/*
// @match https://t.bilibili.com/*
// @match https://www.bilibili.com/*
// @icon https://www.bilibili.com/favicon.ico
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_registerMenuCommand
// @license GPL
// @require https://greasyfork.org/scripts/463455-nelementgetter/code/NElementGetter.js?version=1172110
// ==/UserScript==
function autoHide() {
setInterval(function () {
var div0 = document.querySelector('.fresh-home-content-layout');
var div1 = div0.children[0];
var div2 = div0.children[4];
if (document.body.clientWidth <= 800) {
div1.style = 'display:none';
div2.style = 'display:none';
} else {
div1.removeAttribute('style');
div2.removeAttribute('style');
}
}, 500);
}
function sidebarAdjust() {
GM_addStyle(`
.bili-dyn-live-users__body {
max-height: calc(100vh - 150px) !important;
}
`);
GM_addStyle(`
#btf-tab-area {
padding: 0px 0px 0px !important;
}
`);
GM_addStyle(`
#btf-bwlist-area {
padding-top: 0px !important;
padding-bottom: 8px !important;
}
`);
var left = document.querySelector('aside.left');
var right = document.querySelector('aside.right');
new ElementGetter().get('.feeds-filter-section', document, 10000).then((dynFilter) => {
left.appendChild(dynFilter);
new ElementGetter().get('#btf-bwlist-area', document, 10000).then((advSel) => {
left.appendChild(advSel);
new ElementGetter().get('.bili-dyn-my-info', document, 10000).then((userInfo) => {
left.appendChild(userInfo);
new ElementGetter().get('.bili-dyn-live-users', document, 10000).then((liveList) => {
right.appendChild(liveList);
});
});
});
});
}
function animeHide() {
var hide = GM_addStyle('');
setInterval(function () {
const a = document.querySelector('.bili-dyn-list-tabs__item.active');
const b = document.querySelector('.van-tab.van-tab--active');
if ((a.textContent.indexOf('全部') != -1) && (b.textContent.indexOf('全部') != -1)) {
hide.textContent = `
[data-type="512"] {
display: none
}
`;
} else {
hide.textContent = '';
}
}, 500);
}
function autoRefresh() {
setInterval(function () {
if (document.querySelector('.bili-dyn-list__items').clientHeight == 0) {
window.scrollTo({ top: document.body.clientHeight });
window.scrollTo({ top: 0 });
}
}, 500);
}
function liveRoomClean() {
const blockList = [
'#gift-control-vm', //礼物栏
'#link-footer-vm', //底部
'#right-part > div:nth-child(2) > div:nth-child(3)', //顶栏右侧 饭贩
'#right-part > div:nth-child(2) > div:nth-child(4)', //顶栏右侧 我要开播
'#shop-popover-vm', //小橙车 弹窗
'#sidebar-vm', //右下角 浮窗
'.activity-gather-entry', //播放器顶栏 UP主名字左侧 再左侧
'.gift-planet-entry', //播放器顶栏 UP主名字左侧
'.right-ctnr > div:nth-child(3)', //播放器顶栏 举报
'.right-ctnr > div:nth-child(4)', //播放器顶栏 分享
'.room-feed', //UP主动态
'.web-player-icon-feedback', //播放器 右上角 反馈
];
GM_addStyle(blockList.join(', ') + '{display: none !important}');
}
function settingTop() {
GM_addStyle(`
.dialog-ctnr {
z-index: 9999 !important;
}
`);
}
function showPayUser() {
const getInfoByRoom = 'https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom';
const getOnlineGoldRank = 'https://api.live.bilibili.com/xlive/general-interface/v1/rank/getOnlineGoldRank';
new ElementGetter().get('.tab-list > .live-skin-main-text').then((item) => {
const rid = window.location.pathname.split('/').pop();
GM_xmlhttpRequest({
method: 'get',
url: `${getInfoByRoom}?room_id=${rid}`,
onload: function (res) {
if (res.status === 200) {
const resJson = JSON.parse(res.response);
if (resJson['code'] === 0) {
const uid = resJson['data']['room_info']['uid'];
setInterval(function () {
GM_xmlhttpRequest({
method: 'get',
url: `${getOnlineGoldRank}?ruid=${uid}&roomId=${rid}&page=1000&pageSize=1000`,
onload: function (res) {
if (res.status === 200) {
const resJson = JSON.parse(res.response);
if (resJson['code'] === 0) {
const userNum = resJson['data']['onlineNum'];
item.textContent = '高能用户(' + userNum + ')';
}
}
},
});
}, 2000);
}
}
},
});
});
}
function bottomHeightAdjust() {
new ElementGetter().get('.room-info-ctnr > div').then((left) => {
if (document.querySelector('.room-introduction-scroll-wrapper')) {
document.querySelector('.room-introduction-scroll-wrapper').removeAttribute('class');
}
var right = document.querySelector('.right-container > div');
if (right != null) {
var leftHeight = left.clientHeight;
var rightHeight = right.clientHeight;
if (leftHeight + 48 > rightHeight) {
right.style.height = leftHeight + 16 + 'px';
} else if (leftHeight < rightHeight) {
if (document.querySelector('.room-introduction-tags')) {
left.style.height = rightHeight - 96 + 'px';
} else {
left.style.height = rightHeight - 48 + 'px';
}
}
}
});
}
function showFullName() {
GM_addStyle(`
.room-owner-username {
max-width: 200px !important;
}
`);
}
function showShip() {
const spaceUrl = 'https://api.bilibili.com/x/space/acc/info';
const roomUrl = 'https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom';
const uid = window.location.pathname.split('/')[1];
new ElementGetter().each('.i-live-fo-count.space-fans', document, (item) => {
GM_xmlhttpRequest({
method: 'get',
url: `${spaceUrl}?mid=${uid}`,
onload: function (res) {
if (res.status === 200) {
const resJson = JSON.parse(res.response);
if (resJson['code'] === 0) {
const roomid = resJson['data']['live_room']['roomid'];
GM_xmlhttpRequest({
method: 'get',
url: `${roomUrl}?room_id=${roomid}`,
onload: function (res) {
if (res.status === 200) {
const resJson = JSON.parse(res.response);
if (resJson['code'] === 0) {
const num = resJson['data']['guard_info']['count'];
item.textContent = `${num}🚢`;
}
}
},
});
}
}
},
});
});
}
function videoClean() {
const blockElement = [
'#arc_toolbar_report > .more', //视频下方功能区 更多
'#arc_toolbar_report > .ops > .share', //视频下方功能区 分享
'#arc_toolbar_report > .rigth-btn', //视频下方功能区 右侧
'#v_desc > .tip-info', //版权提示
'.bpx-player-dm-hint', //弹幕发送栏 弹幕礼仪
'.float-nav__btn--fixed', //浮窗 前往新版
'.float-nav > .nav-menu > [title="帮助反馈"]', //浮窗 客服
];
GM_addStyle(blockElement.join(', ') + '{display:none!important}');
}
function videoCleanN() {
const blockElement_new = [
// '#playlistToolbar > .video-toolbar-left > div:has(.video-share-wrap)', //视频下方功能区 分享
'.float-nav-exp > div > a[title="帮助反馈"]', //浮窗 客服
'.reply-header > .reply-notice', //评论区顶端横幅
'.video-toolbar-right', //视频下方功能区 右侧
];
GM_addStyle(blockElement_new.join(', ') + '{display:none!important}');
}
function autoNextVideoN() {
new ElementGetter().each('.bpx-player-ending-functions-btn[data-action="restart"]', document, (restart) => {
var next = document.querySelector('.bpx-player-ctrl-btn.bpx-player-ctrl-next');
if (next == undefined) {
return false;
}
next.click();
});
}
function showMoreIntro() {
new ElementGetter().get('.toggle-btn', document).then((btn) => {
btn.click();
});
}
function showMoreTag() {
new ElementGetter().get('.show-more-btn', document).then((btn) => {
btn.click();
});
}
function hideVideoList() {
new ElementGetter().get('.video-sections-head', document).then((head) => {
var flag = true;
var body = head.nextElementSibling
head.onclick = function() {
body.style = flag ? 'display:none' : '';
flag = !flag;
}
});
}
const mainPage = window.location.href == 'https://www.bilibili.com/';
const dynamic = window.location.host == 't.bilibili.com';
const liveRoom = window.location.href.match(/https:\/\/live\.bilibili\.com\/[0-9]+/) != null;
const space = window.location.href.match(/https:\/\/space\.bilibili\.com\/[0-9]+/) != null;
const video = window.location.href.match(/https:\/\/www\.bilibili\.com\/(list)|(video)/) != null;
const funcList = [
{
name: 'autoHide',
menu: '页面变窄时隐藏活动和栏目',
match: mainPage,
func: autoHide,
},
{
name: 'sidebarAdjust',
menu: '侧栏调整',
match: dynamic,
func: sidebarAdjust,
},
{
name: 'animeHide',
menu: '隐藏其他分组的番剧',
match: dynamic,
func: animeHide,
},
{
name: 'autoRefresh',
menu: '无显示动态时自动刷新',
match: dynamic,
func: autoRefresh,
},
{
name: 'liveRoomClean',
menu: '页面清理',
match: liveRoom,
func: liveRoomClean,
},
{
name: 'settingTop',
menu: '弹幕设置弹窗置顶',
match: liveRoom,
func: settingTop,
},
{
name: 'showPayUser',
menu: '显示高能用户数',
match: liveRoom,
func: showPayUser,
},
{
name: 'bottomHeightAdjust',
menu: '底栏高度对齐',
match: liveRoom,
func: bottomHeightAdjust,
},
{
name: 'showFullName',
menu: '顶栏UP主名字全部显示',
match: liveRoom,
func: showFullName,
},
{
name: 'showShip',
menu: '显示舰长数',
match: space,
func: showShip,
},
{
name: 'videoClean',
menu: '播放页清理',
match: video,
func: videoClean,
},
{
name: 'videoCleanN',
menu: '播放页清理(新播放页)',
match: video,
func: videoCleanN,
},
{
name: 'autoNextVideoN',
menu: '自动播放下一个视频(新播放页)',
match: video,
func: autoNextVideoN,
},
{
name: 'showMoreIntroN',
menu: '展开视频介绍(新播放页)',
match: video,
func: showMoreIntro,
},
{
name: 'showMoreTagN',
menu: '展开视频标签(新播放页)',
match: video,
func: showMoreTag,
},
{
name: 'hideVideoList',
menu: '选集列表展开与收起',
match: video,
func: hideVideoList,
},
];
funcList.forEach((item) => {
if (item.match) {
const name = item.name
const menu = item.menu
if (GM_getValue(name) == undefined) {
GM_setValue(name, true)
}
const open = GM_getValue(name)
GM_registerMenuCommand(`${ open ? '✅' : '❌' }${ menu }`, function () {
GM_setValue(name, !open)
window.location.reload()
})
if (open) {
item.func()
console.log(`${ name } - ${ menu } - 已开启`)
}
}
})