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

HTML:Youtube-count

来自Vocawiki
<script type="module">
(window.RLQ??=[]).push([[`moment`],async()=>{await $.ready;let e=mw.config.get(`wgUserId`)===69859,t=[`publishedAt`,`title`,`privacyStatus`,`publicStatsViewable`,`viewCount`,`likeCount`,`commentCount`],n=[`toFixed`,`plain`,`separate`],r={},i={sendError:e=>{console.error(`widget:YoutubeCount`,e.type,`occurred:`,e.information);let t=``;for(let n in e)t+=`\n${n}: ${JSON.stringify(e[n],void 0,4)}`;e.type===`network`&&e.information.status===429?$(`.youtubeCount`).html(`${wgUVS(`YoutubeCount 运行错误:非常抱歉,但由于过多的请求,现已触发数据统计服务器的临时封禁措施。`,`YoutubeCount 執行錯誤:非常抱歉,但由於過多的請求,現已觸發資料統計伺服器的臨時封鎖措施。`)}\n${wgUVS(`这可能是因为您短时间内打开了多个页面进而产生大量请求导致的,请等待1分钟后刷新本页面,并建议您打开相关数据统计页面时每次间隔1分钟,感谢您的合作!`,`這可能是因為您短時間內打开了多個頁面進而產生大量請求導致的,請等待1分鐘後重新整理本頁面,並建議您開啟相關資料統計頁面時每次間隔1分鐘,感謝您的合作!`)}`):$(`.youtubeCount`).html(`YoutubeCount ${wgUVS(`运行错误`,`執行錯誤`)}:${t}`)},format:(e,t,n,r=2)=>{let i=String(e),a;switch(t){case`value`:switch(n){case`toFixed`:if(/\D/u.test(i))a=i;else{let e=Number(i);a=e>10**8?`${(e/10**8).toFixed(Number.isInteger(r)?r:2)}${wgUVS(`亿`,`億`)}`:e>1e4?`${(e/1e4).toFixed(Number.isInteger(r)?r:2)}${wgUVS(`万`,`萬`)}`:i}break;case`plain`:a=i;break;case`separate`:a=i.split(``).reverse().map((e,t)=>t>0&&t%3==0?`${e},`:e).reverse().join(``);break;default:a=i}break;case`date`:a=moment(/^\d{12,}$/u.test(i)?Number(i):i).format(n);break;default:a=i}return a},clear:()=>{$(`.youtubeCount.done[data-youtube-count-onlyTime="false"][data-youtube-count-noTime="true"] sub`).remove(),$(`.youtubeCount.done[data-time]:not([data-time=""])[data-youtube-count-onlyTime="false"][data-youtube-count-noTime="false"]`).each((e,t)=>{$(t).find(`sub`).text(`(${i.format(t.dataset.time,`date`,t.dataset.dateFormat||`LLL`)})`)}),$(`.youtubeCount.done[data-time]:not([data-time=""])[data-youtube-count-onlyTime="true"]`).each((e,t)=>{$(t).text(i.format(t.dataset.time,`date`,t.dataset.dateFormat||`LLL`))}),$(`.youtubeCount.done`).removeClass(`done`)},get:t=>$.ajax({url:`https://cors.funce.dev/https://moegirlpedia.annangela.cn/youtubeCollector/video?target=${t.join(`|`)}`,type:`GET`,timeout:6e4,success:t=>{for(let a in t.query.videos){let o=t.query.videos[a];for(let s in r[a]){let c=r[a][s];t.error||t.query.code!==0?c.empty().text(`(${wgUVS(`请求数据出错`,`請求資料出錯`)}${t.requestId?`,requestId ${t.requestId}`:``})`).css(`font-style`,`italic`):o.data?(s!==`publishedAt`&&/\D/u.test(String(o.data[s]))&&(o.data[s]=wgUVS(`无数据`,`無資料`)),c.empty().each((e,t)=>{let r=t.dataset.format,a=t.dataset.dateFormat||`LLL`;n.includes(r)||(r=`toFixed`);let c=parseInt(t.dataset.decimalLength,10);(!Number.isInteger(c)||c<1)&&(c=2),$(t).append(`<span>${i.format(o.data[s],s===`publishedAt`?`date`:`value`,s===`publishedAt`?a:s.endsWith(`Count`)?r:`plain`,c)}</span><sub></sub>`).attr(`data-time`,o.time)}),c.addClass(`done`),o.status!==`ok`&&(c.css(`text-decoration`,`underline`),e||c.attr(`title`,`${wgUVS(`无法获取最新数据`,`無法獲取最新資料`)}:${o.status} - ${o.message}`)),e&&c.attr(`title`,`onlineResult[${a}]:\n${JSON.stringify({...o,requestId:t.requestId},void 0,4)}`).addClass(`done`)):c.empty().append(`<span>(${a} ${wgUVS(`无数据`,`無資料`)}${t.requestId?`,requestId ${t.requestId}`:``})</span>`).css(`font-style`,`italic`)}}(t.error||t.query.code!==0)&&console.error(`WidgetYoutubeCount`,t)},error:e=>{i.sendError({type:`network`,information:{readyState:e.readyState,state:e.state(),responseText:e.responseText,status:e.status,statusText:e.statusText}})}})};try{$(`.youtubeCount`).each((e,n)=>{let i=$(n),a=n.dataset.youtubeCountId,o=n.dataset.youtubeCountType;if(!/^[0-9A-Za-z_-]{10}[048AEIMQUYcgkosw]$/u.test(a||``)){i.empty().text(wgUVS(`(参数 id 错误)`,`(引數 id 錯誤)`)).css(`font-style`,`italic`);return}if(t.includes(o)||(o=void 0),!o){i.empty().text(wgUVS(`(参数 type 错误)`,`(引數 type 錯誤)`)).css(`font-style`,`italic`);return}$.isPlainObject(r[a])||(r[a]={});let s=r[a];s[o]&&s[o].jquery===$.fn.jquery||(s[o]=$()),s[o].push(n),i.html(`<i>${wgUVS(`加载中`,`載入中`)}……</i>`)}),i.clear();let e=Object.keys(r).filter(e=>Object.entries(r[e]).some(([,{length:e}])=>e>0));for(let t=0;t*20<e.length;t++)await i.get(e.slice(t*20,t*20+20))}catch(e){i.sendError({type:`throw_error`,information:{name:e.name,message:e.message,stack:e.stack?.split(`
`)[1].trim()}})}}]);
</script>