// ==UserScript== // @name Bilibili 显示视频分区、av号等 // @namespace https://space.bilibili.com/517723/ // @version 0.06 // @description 在视频下方显示 分区、av 号、bv 号、cid、分P标题、动态,点击cid可打开弹幕文件,并醒目显示tag中的分区。也可安装为 Bilibili Evolved v2 组件。 // @author 僠儖僲 // @include https://www.bilibili.com/video/* // @icon https://www.bilibili.com/favicon.ico // @compatible firefox Firefox91-esr // @compatible edge Edge98 // @noframes // @grant GM_addStyle // @run-at document-start // @downloadURL none // ==/UserScript== (()=>{ 'use strict'; const options={ isAppend:{ displayName:'在简介下方', defaultValue:!1 }, tname_color:{ displayName:'分区TAG颜色', defaultValue:'#00a1d6',color:true } } const root=typeof unsafeWindow==="undefined"?window:unsafeWindow,etp=EventTarget.prototype const _on=etp.addEventListener,_off=etp.removeEventListener const once=(t,s,o=!1,cb)=>new Promise(ok=>{_on.call(t,s,cb=e=>{_off.call(t,s,cb,o);ok(e)},o)}) const ready=once(document,'DOMContentLoaded') var addStyle const main=({ isAppend=options.isAppend.defaultValue, tname_color=options.tname_color.defaultValue })=>{ const list=['详细信息','分P标题','动态'] const tick0_5=cb=>setTimeout(cb,500) const wait=(cb,tick=requestAnimationFrame,next)=>new Promise((ok,reject)=>{ (next=v=>{try{(v=cb())?ok(v):tick(next)}catch(e){reject(e)}})() }),waitElem=select=>wait(()=>document.querySelector(select),tick0_5) const eventStopPropagation=Function.prototype.call.bind(Event.prototype.stopPropagation) const vmp=ready.then(e=>waitElem('#app')).then(el=>wait(()=>el.__vue__)) vmp.then(vm=>{root.__BILIBILI_VIDEO_GLOBAL_VIEWMODEL__=vm}) const getEl=(value,key='title',el)=>{ el=document.querySelector(`.video-desc>.desc-info[${key}="${value}"]`) if(!el){ el=document.createElement('div') el.className='desc-info desc-v2 open' el.setAttribute(key,value) el.setAttribute('data-old',location.href) el.addEventListener('click',eventStopPropagation,!0) document.querySelector('.video-desc')[isAppend?'append':'prepend'](el) } return el } var curPart=null,curPartQuery='',curPartData const tnameSelect=[ '[href^="//www.bilibili.com/v/"]:not([href^="//www.bilibili.com/v/channel/"])', '[href^="//www.bilibili.com/anime/"]', '[href^="//www.bilibili.com/guochuang/"]', '[href^="//www.bilibili.com/movie/"]', '[href^="//www.bilibili.com/documentary/"]' ].map(s=>`.s_tag .tag-area>li .tag-link${s}`).join(',') const copyrightMap=new Map([[1,'自制'],[2,'转载']]) const map={ ['详细信息'](el,{tname,aid,bvid,copyright}){ var tnames=Array.from(document.querySelectorAll(tnameSelect),a=>a.innerText) var cid=curPartData&&curPartData.cid,cmap=copyrightMap copyright=cmap.has(copyright)?cmap.get(copyright):'未知' var list=[ `${tnames[1]===tname?tnames.join('>'):tname}`, `${copyright}`, `av${aid}`, `${bvid}`, cid?`cid:${cid}`:'' ] el.innerHTML=list.join('\u3000') }, ['分P标题'](el,{title}){ var partTitle=curPartData&&curPartData.part el.title=`分P标题${partTitle!==title?partTitle?'':'为空':'与标题相同'}` el.innerText=partTitle||'\ufe0f' }, ['动态'](el,{dynamic}){ el.style.cssText='border-top:1px solid #e5e9f0;margin-top:15px;padding-top:15px;' el.title=dynamic?'动态':'动态为空' el.innerText=dynamic||'\ufe0f' } } const inject=(data)=>{ data||(data=root.__INITIAL_STATE__.videoData) curPart=location.search.match(/[?&]p=(\d+)/) curPartQuery=curPart?`?p=${curPart[1]}`:'' var {pages}=data curPartData=pages[curPart?curPart[1]-1:0]||pages[0] getEl('分割线','data-title').style.cssText='height:1px;background-color:#e5e9f0;margin:15px 0px;' list[isAppend?'reduce':'reduceRight']((acc,cur)=>{map[cur](getEl(cur,'data-title'),data)},void 0) } vmp.then(vm=>{ vm.$store.watch(state=>state.videoData,data=>{setTimeout(()=>{inject(data)},0)}) inject() tname_color&&addStyle&&addStyle(`${tnameSelect}{color:${tname_color} !important;}`) }) } const name='show-video-division-aid' const evolved=()=>({ author:{ name:'僠儖僲', link:'https://space.bilibili.com/517723/' }, name,displayName:"显示视频分区、av号等", description:{ "zh-CN":"在视频下方显示 分区、av 号、bv 号、cid、分P标题、动态,点击cid可打开弹幕文件,并醒目显示tag中的分区" }, entry({coreApis,metadata,settings:{options}}){ addStyle=coreApis.style.addStyle main(options) }, tags:[componentsTags.utils], urlInclude:['https://www.bilibili.com/video/'], options, }) "object"==typeof exports?"object"==typeof module? module.exports=evolved():exports[name]=evolved():(addStyle=GM_addStyle,main({})) })()