跳转到内容
打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
登录后可编辑和发表评论。

HTML:Bilibili-count

来自Vocawiki
<script type="module">
(window.RLQ??=[]).push([[`moment`,`ext.gadget.site-lib`],async()=>{let e=mw.config.get(`wgUserId`)===69859,t=[void 0,`view`,`danmaku`,`reply`,`favorite`,`coin`,`share`,`his_rank`,`like`,`dislike`,`title`],n=[`toFixed`,`plain`,`separate`],r={aid:{},bvid:{}},i=()=>[...document.querySelectorAll(`.bilibiliCount`)],a=e=>{console.error(`widget:BilibiliCount`,e.type,`occurred:`,e.information);let t=i();for(let e of t)e.innerHTML=`BilibiliCount ${wgUVS(`运行错误`,`執行錯誤`)}`;if(e.type===`network`&&e.information.status===429){t[0].innerHTML+=[wgUVS(`:非常抱歉,但由于过多的请求,现已触发数据统计服务器的临时封禁措施。`,`:非常抱歉,但由於過多的請求,現已觸發資料統計伺服器的臨時封鎖措施。`),wgUVS(`这可能是因为您短时间内打开了多个页面进而产生大量请求导致的,请等待1分钟后刷新本页面,并建议您打开相关数据统计页面时每次间隔1分钟,感谢您的合作!`,`這可能是因為您短時間內打开了多個頁面進而產生大量請求導致的,請等待1分鐘後重新整理本頁面,並建議您開啟相關資料統計頁面時每次間隔1分鐘,感謝您的合作!`)].join(`
`);return}if(t[0].innerHTML+=`:`,e.type===`networkException`)switch(e.information.name){case`NetworkError`:t[0].innerHTML+=wgUVS(`发生网络错误,请检查你的网络。`);return;case`AbortError`:case`TimeoutError`:t[0].innerHTML+=wgUVS(`请求超时,请检查你的网络,或等待一段时间后再试。`);return;default:t[0].innerHTML+=`发生网络错误:${e.information.name} - ${e.information.message}`;return}let n={type:e.type};if(e.type===`network`)n.information={status:e.information.status,statusText:e.information.statusText};else if(n.information={name:e.information.name,message:e.information.message},e.information.stack){let[,t]=e.information.stack.split(`
`);n.information.stack=t}for(let[e,r]of Object.entries(n))t[0].innerHTML+=`\n${e}: ${JSON.stringify(r,void 0,4)}`},o=()=>{for(let e of document.querySelectorAll(`.bilibiliCount.done[data-bilibili-count-onlyTime="false"][data-bilibili-count-noTime="true"] sub`))e.remove();for(let e of document.querySelectorAll(`.bilibiliCount.done[data-time]:not([data-time=""])[data-bilibili-count-onlyTime="false"][data-bilibili-count-noTime="false"]`)){let t=e.querySelector(`sub`);t&&(t.innerText=`(${moment(/^\d{12,}$/u.test(e.dataset.time)?Number(e.dataset.time):e.dataset.time).format(e.dataset.dateFormat||`LLL`)})`)}for(let e of document.querySelectorAll(`.bilibiliCount.done[data-time]:not([data-time=""])[data-bilibili-count-onlyTime="true"]`))e.innerText=moment(/^\d{12,}$/u.test(e.dataset.time)?Number(e.dataset.time):e.dataset.time).format(e.dataset.dateFormat||`LLL`);for(let e of document.querySelectorAll(`.bilibiliCount.done`))e.classList.remove(`done`)},s=(e,...t)=>{e.innerText=``,e.append(...t),e.style.fontStyle=`italic`},c=async(e,t)=>{let n=Number.isSafeInteger(t?.timeout)&&t.timeout>0?t.timeout:6e4,r=new AbortController,i=setTimeout(()=>r.abort(),n),a=await fetch(e,{...t??{},signal:r.signal}).catch(e=>e instanceof DOMException?e:new DOMException(JSON.stringify(e,null,4),`UnknownError`));return clearTimeout(i),a},l=async(t,i)=>{let o=new URL(` https://cors.funce.dev/https://moegirlpedia.annangela.cn/bilibiliCollector/video`);o.searchParams.set(t,i.join(`|`));let l=await c(o,{method:`GET`});if(l instanceof DOMException)throw a({type:`networkException`,information:l}),!1;if(!l.ok)throw a({type:`network`,information:l}),!1;let u=await l.json();for(let[t,i]of Object.entries(u.query.videos))for(let[a,o]of Object.entries(i))for(let[i,c]of Object.entries(r[t][a]))for(let r of c){if(u.error||u.query.code!==0){s(r,`(${wgUVS(`请求数据出错`,`請求資料出錯`)}${u.requestId?`,requestId ${u.requestId}`:``})`),e&&(r.title=`[${t}${a}]:\n${JSON.stringify(o,void 0,4)}`);continue}let c=o.data[i];if(c===void 0||c===``){s(r,`(${t}${a}[${i}] ${wgUVS(`无数据`,`無資料`)}${u.requestId?`,requestId ${u.requestId}`:``})`);continue}let l=r.dataset.format,d;n.includes(l)||(l=`toFixed`);let f=parseInt(r.dataset.decimalLength,10);switch((!Number.isInteger(f)||f<1)&&(f=2),l){case`toFixed`:d=!/\D/u.test(`${c}`)&&c>1e4?`${(c/1e4).toFixed(Number.isInteger(f)?f:2)}${wgUVS(`万`,`萬`)}`:c;break;case`plain`:d=c;break;case`separate`:d=`${c}`.split(``).reverse().map((e,t)=>t>0&&t%3==0?`${e},`:e).reverse().join(``)}r.innerHTML=`<span>${d}</span><sub></sub>`,r.dataset.time=o.time,r.classList.add(`done`),o.status!==`ok`&&(r.style.textDecoration=`underline`,e||(r.title=`${wgUVS(`无法获取最新数据`,`無法獲取最新資料`)}:${o.status} - ${o.message}`)),e&&(r.title=`onlineResult[${a}]:\n${JSON.stringify({...o,requestId:u.requestId},void 0,4)}`)}(u.error||u.query.code!==0)&&console.error(`WidgetBilibiliCount`,u)};try{let e=new URL(`https://zh.moegirl.org.cn/Template:BilibiliCount`);e.hash=`参数说明`;for(let n of i()){let i=n.dataset.bilibiliCountId,a=i.replace(/^[ab]v/iu,``),o=n.dataset.bilibiliCountType||`1`,c;if(/^(?:av)?[1-9]\d{0,8}$/iu.test(i))c=`aid`;else if(/(?:(?:[bB][vV])?1)?[fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF]{9}/iu.test(i))c=`bvid`;else{s(n,wgUVS(`(参数 id 错误)`,`(引數 id 錯誤)`));continue}if(/^\d+$/u.test(o)&&(o=t[Number(o)]),!t.includes(o)||!o){s(n,wgUVS(`(参数 type 错误)`,`(引數 type 錯誤)`));continue}if(o===`dislike`){let t=document.createElement(`a`);t.href=`${e}`,t.target=`_blank`,t.classList.add(`external`,`free`),t.innerText=wgUVS(`dislike(差评)参数已被停用,详情请见模板说明页`,`dislike(差評)引數已被停用,詳情請見模板說明頁`),s(n,t);continue}Reflect.has(r[c],a)||(r[c][a]={});let l=r[c][a];Array.isArray(l[o])||(l[o]=[]),l[o].push(n),n.innerHTML=`<i>${wgUVS(`加载中`,`載入中`)}……</i>`}o();for(let[e,t]of Object.entries(r).map(([e,t])=>[e,Object.keys(t)]).filter(([,{length:e}])=>e>0))for(let n=0;n*30<t.length;n++)await l(e,t.slice(n*30,n*30+30))}catch(e){e!==!1&&a({type:`error`,information:e})}}]);
</script>