// ==UserScript== // @name B站 周姐 // @namespace https://space.bilibili.com/15516023 // @version 1.2.2 // @description B站首页看各个分区! // @author You // @match https://www.bilibili.com/* // @icon https://www.google.com/s2/favicons?domain=bilibili.com // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/436110/B%E7%AB%99%20%E5%91%A8%E5%A7%90.user.js // @updateURL https://update.greasyfork.icu/scripts/436110/B%E7%AB%99%20%E5%91%A8%E5%A7%90.meta.js // ==/UserScript== ;(function () { 'use strict' GM_addStyle(` #bili_custom .popover-video-card { display: none; } #bili_custom a:hover+.popover-video-card { display: block; } .pgc-rank-dropdown { position: relative; display: inline-block; vertical-align: middle; background-color: #fff; font-size: 12px; cursor: default; padding: 0 7px; height: 22px; line-height: 22px; border: 1px solid #ccd0d7; border-radius: 4px; margin-right: 12px; } .pgc-rank-dropdown:hover { border-radius: 4px 4px 0 0; -webkit-box-shadow: rgba(0,0,0,.16) 0 2px 4px; box-shadow: 0 2px 4px rgba(0,0,0,.16) } .pgc-rank-dropdown:hover .dropdown-list { display: block } .pgc-rank-dropdown .selected { display: inline-block; vertical-align: top } .pgc-rank-dropdown .icon-arrow-down { background-image: url(//static.hdslb.com/images/base/icons.png); background-position: -475px -157px; display: inline-block; vertical-align: middle; width: 12px; height: 6px; margin-left: 5px; margin-top: -1px } .pgc-rank-dropdown .dropdown-list { position: absolute; width: 100%; background: #fff; border: 1px solid #ccd0d7; border-top: 0; left: -1px; top: 22px; z-index: 10; display: none; border-radius: 0 0 4px 4px } .pgc-rank-dropdown .dropdown-list .dropdown-item { cursor: pointer; margin: 0; padding: 3px 7px } .pgc-rank-dropdown .dropdown-list .dropdown-item:hover { background-color: #e5e9ef } `) const USERS = [ { key_words: '周淑怡', channel_id: 780447, bigFans: [ 366314, //夕寒君 408794610, //周姐日常事 279220304, //米小莔 2662674, //不2不叫火龙果 30405149, //AA丶翼夜 178505026, //AA丶熊熊 1578665974, //全村最野的狗 65888156, //hy弘月 27330407, //拆城南宝 ], }, { key_words: 'A-SOUL', channel_id: 4429874, bigFans: [ 672328094, //嘉然今天吃什么 672346917, //向晚大魔王 672353429, //贝拉kira 351609538, //珈乐Carol 672342685, //乃琳Queen ], } ] let currentUserIndex = 0 let currentPage = 1 let page = 0 let videoList = [] const API = { getDetail: async (bvid) => { let res = await fetch( `https://api.bilibili.com/x/web-interface/archive/stat?bvid=${bvid}`, ) return (await res.json()).data }, getNewVideo: async () => { let res = await fetch( `https://api.bilibili.com/x/web-interface/search/type?context=&order=pubdate&keyword=${ USERS[currentUserIndex].key_words }&search_type=video&page=${currentPage++}`, ) videoList = videoList.concat((await res.json()).data.result) }, getHotVideo: async () => { let res = await fetch( `https://api.bilibili.com/x/web-interface/web/channel/multiple/list?channel_id=${USERS[currentUserIndex].channel_id}&sort_type=hot&offset=&page_size=10`, ) return (await res.json()).data.list[0].items }, } function bigNumber(num) { return num > 10000 ? `${(num / 10000).toFixed(2)}万` : num } function s2d(string) { return new DOMParser().parseFromString(string, 'text/html').body .childNodes[0] } function timeFormat(time) { let res = [] let [s = 0, m = 0, h = 0] = time.split(':').reverse() res.unshift(String(s).padStart(2, '0')) res.unshift(String(m % 60).padStart(2, '0')) res.unshift(String(h % 60).padStart(2, '0')) return res.join(':') } async function refresh() { console.log(`page:`, page, videoList.length) page++ if (videoList.length <= page * 10 + 10) { await API.getNewVideo() } drawVideos() } function drawVideos() { const VIDEO_DOM = document.querySelector('#bili_custom .zone-list-box') VIDEO_DOM.innerHTML = '' videoList .slice(page * 10, page * 10 + 10) .sort((a, b) => { return USERS[currentUserIndex].bigFans.includes(b.mid) ? 1 : -1 }) .forEach((item) => { let title = item.title.replace(/(.*?)<\/em>/g, '$1') let DOM = s2d(`
${title} ${item.author}
`) VIDEO_DOM.append(DOM) }) } async function drawFirst(item) { const RANK_DOM = document.querySelector('#bili_custom .rank-list') let firstDetail = await API.getDetail(item.bvid) let firstTitle = item.name.replace(/(.*?)<\/em>/g, '$1') let first = `
1

${firstTitle}

播放次数:${bigNumber(firstDetail.view)}
` RANK_DOM.append(s2d(first)) } async function drawHot() { const RANK_DOM = document.querySelector('#bili_custom .rank-list') let rankList = await API.getHotVideo() await drawFirst(rankList.shift()) rankList.forEach((item, index) => { let title = item.name.replace(/(.*?)<\/em>/g, '$1') let DOM = s2d(`
${ index + 2 }

${title}

${title}

${ item.author_name }·${timeFormat(item.duration)}

  • ${ item.view_count }
  • -
  • -
  • -
`) RANK_DOM.append(DOM) }) } const drawSelector = () => { const HEADER_DOM = document.querySelector('#bili_custom .exchange-btn') let DOM = s2d(`
${ USERS[currentUserIndex].key_words }
`) HEADER_DOM.prepend(DOM) document .querySelector('.dropdown-list') .addEventListener('click', injectDOM) } async function injectDOM(e) { currentUserIndex = e ? e.target.getAttribute('index') : 0 videoList = [] currentPage = 1 page = 0 const DOM = ` ` let content = document.querySelector('.first-screen') let anchor = document.querySelector('#reportFirst2') let init = s2d(DOM) document.querySelector('#bili_custom') && document.querySelector('#bili_custom').remove() // 插入初始模版 console.log(`init:`, currentUserIndex) content.insertBefore(init, anchor) // 插入选择器 drawSelector() // 插入最新视频 await API.getNewVideo() drawVideos() // 插入热门视频 drawHot() // 点击事件 document.querySelector('.custom-refresh').addEventListener('click', refresh) } window.addEventListener( 'load', async () => { await injectDOM() }, false, ) })()