mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
9 lines
5.9 KiB
JavaScript
9 lines
5.9 KiB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["utils/subscribe-time-show"]=t():e["utils/subscribe-time-show"]=t()}(globalThis,(()=>(()=>{var e,t,o={523:(e,t,o)=>{var n=o(955)((function(e){return e[1]}));n.push([e.id,".space-head-follow.b-follow {\n position: relative;\n}\n.space-head-follow.b-follow .subscribe-time-text {\n position: absolute;\n top: -20px;\n left: 50%;\n transform: translateX(-50%);\n font-size: 12px;\n color: #fff;\n line-height: 16px;\n -webkit-user-select: none;\n user-select: none;\n pointer-events: none;\n white-space: nowrap;\n font-weight: 500;\n text-shadow: 0 0 3px rgba(0, 0, 0, 0.7);\n}\n\n.relation-card-info__time {\n color: #888;\n font-size: 12px;\n margin-bottom: 4px;\n -webkit-user-select: none;\n user-select: none;\n}",""]),e.exports=n},955:e=>{"use strict";
|
||
// eslint-disable-next-line func-names
|
||
e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var o=e(t);return t[2]?"@media ".concat(t[2]," {").concat(o,"}"):o})).join("")},
|
||
// eslint-disable-next-line func-names
|
||
t.i=function(e,o,n){"string"==typeof e&&(
|
||
// eslint-disable-next-line no-param-reassign
|
||
e=[[null,e,""]]);var r={};if(n)for(var i=0;i<this.length;i++){
|
||
// eslint-disable-next-line prefer-destructuring
|
||
var a=this[i][0];null!=a&&(r[a]=!0)}for(var s=0;s<e.length;s++){var c=[].concat(e[s]);n&&r[c[0]]||(o&&(c[2]?c[2]="".concat(o," and ").concat(c[2]):c[2]=o),t.push(c))}},t}},337:(e,t,o)=>{var n=o(523);n&&n.__esModule&&(n=n.default),e.exports="string"==typeof n?n:n.toString()},479:e=>{"use strict";if("undefined"==typeof coreApis){var t=new Error("Cannot find module 'coreApis.style'");throw t.code="MODULE_NOT_FOUND",t}e.exports=coreApis.style}},n={};function r(e){var t=n[e];if(void 0!==t)return t.exports;var i=n[e]={id:e,exports:{}};return o[e](i,i.exports,r),i.exports}t=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,r.t=function(o,n){if(1&n&&(o=this(o)),8&n)return o;if("object"==typeof o&&o){if(4&n&&o.__esModule)return o;if(16&n&&"function"==typeof o.then)return o}var i=Object.create(null);r.r(i);var a={};e=e||[null,t({}),t([]),t(t)];for(var s=2&n&&o;"object"==typeof s&&!~e.indexOf(s);s=t(s))Object.getOwnPropertyNames(s).forEach((e=>a[e]=()=>o[e]));return a.default=()=>o,r.d(i,a),i},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{"use strict";r.d(i,{component:()=>y});const e=coreApis.componentApis.define,t=coreApis.utils.log,o=coreApis.ajax,n=(0,t.useScopedConsole)("关注时间显示"),a=".space-head-follow.b-follow",s="subscribe-time-text",c=".relation-card-info__uname",l=".relation-card-info",f="relation-card-info__time",u=".relation-card-info__sign",p={},d=(e,t,o)=>{const n=document.querySelector(`${c}[href*="/${e}"]`),r=n?.closest(l);if(!r)return;if(r.querySelector(`.${f}`))return;const i=document.createElement("div");i.className=f,i.textContent=`${o}:${t}`;const a=r.querySelector(u);a?.parentNode&&a.parentNode.insertBefore(i,a.nextSibling)};let m=!1,b=!1;const h=()=>{b||(b=!0,requestAnimationFrame((()=>{b=!1;Array.from(document.querySelectorAll(c)).map((e=>e.href.match(/\/(\d+)/)?.[1])).filter(Boolean).map(Number).forEach((e=>{const t=p[e];if(t){const o=new Date(1e3*t.mtime).toLocaleString();d(e,o,t.label)}}))})))},y=(0,e.defineComponentMetadata)({name:"subscribeTimeShow",displayName:"关注时间显示",author:{name:"CNOCM",link:"https://github.com/CNOCM"},tags:[componentsTags.utils],urlInclude:[/^https:\/\/space\.bilibili\.com\/\d+\/(relation|fans)\/(fans|follow)/,/https:\/\/space\.bilibili\.com\/\d+/],entry:async()=>{try{const{addImportantStyle:e}=await Promise.resolve().then(r.t.bind(r,479,23)),{default:t}=await Promise.resolve().then(r.t.bind(r,337,23));e(t,"subscribe-time-style")}catch(e){n.error("样式加载失败:",e)}if(new MutationObserver(h).observe(document.body,{childList:!0,subtree:!0}),!m){m=!0;const e=unsafeWindow.fetch;unsafeWindow.fetch=new Proxy(e,{apply(e,t,o){const r="string"==typeof o[0]?o[0]:o[0].url;return r.includes("/x/relation/fans")||r.includes("/x/relation/followings")?e.apply(t,o).then((e=>(e.clone().json().then((e=>{const t=e?.data?.list;Array.isArray(t)?t.forEach((e=>{if("number"==typeof e.mid&&"number"==typeof e.mtime){const t=r.includes("/x/relation/fans")?"Ta 关注你的时间":"你关注 Ta 的时间";p[e.mid]={mtime:e.mtime,label:t},d(e.mid,new Date(1e3*e.mtime).toLocaleString(),t)}})):n.warn("接口数据结构异常:",e)})).catch((e=>n.warn("JSON 解析失败:",e))),e))):e.apply(t,o)}})}const e=location.href.match(/space\.bilibili\.com\/(\d+)/);if(!e)return void n.warn("无法提取 mid");const t=Number(e[1]),i=await(0,o.bilibiliApi)((0,o.getJsonWithCredentials)(`https://api.bilibili.com/x/web-interface/relation?mid=${t}`));if(i?.relation)if(i.relation.mtime){try{await new Promise((e=>{const t=()=>document.querySelector(a);let o=t();if(o)e(o);else{const n=new MutationObserver((()=>{o=t(),o&&(n.disconnect(),e(o))}));n.observe(document.body,{childList:!0,subtree:!0})}}))}catch(e){return void n.warn("等待关注容器超时,跳过插入关注时间")}(e=>{const t=document.querySelector(a);if(!t)return;if(t.querySelector(`.${s}`))return;"static"===getComputedStyle(t).position&&(t.style.position="relative");const o=document.createElement("div");o.className=s,o.textContent=`关注于 ${e}`,t.appendChild(o)})(new Date(1e3*i.relation.mtime).toLocaleString())}else n.log("当前未关注或关注时间无效");else n.warn("未获取到 relation 信息")},description:{"zh-CN":"在粉丝/关注列表及用户主页显示关注的具体时间。"},commitHash:"af2906e6411c4a1b26e4ef2d5cf981620e6e3ac2",coreVersion:"2.10.2"})})(),i=i.component})())); |