// ==UserScript== // @name bilibili - 查看历史评论 // @description 文明交流,人人有责。必须正当对待别人公开发表的言论。 // @version 1.0.0 // @author 会飞的蛋蛋面 // @license All Rights Reserved - 未经授权禁止使用、复制、修改或分发 // @match https://www.bilibili.com/video/* // @grant GM_xmlhttpRequest // @grant GM_addStyle // @connect api.aicu.cc // @run-at document-idle // @namespace https://greasyfork.org/users/751952 // @downloadURL none // ==/UserScript== (() => { // 防止滥用 'use strict';const a0a='history-reply-panel',a0b=new Map();GM_addStyle('\x0a\x20\x20\x20\x20\x20\x20\x20\x20#'+a0a+'\x20{\x20position:\x20absolute;\x20width:\x20360px;\x20max-height:\x2070vh;\x20overflow:\x20auto;\x20background:\x20#fff;\x20color:\x20#333;\x20border:\x201px\x20solid\x20#ddd;\x20border-radius:\x208px;\x20box-shadow:\x200\x206px\x2024px\x20rgba(0,0,0,.18);\x20z-index:\x2099999;\x20padding:\x2012px;\x20display:\x20none;\x20font-family:\x20inherit;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20body.dark\x20#'+a0a+'\x20{\x20background:\x20#1f1f1f;\x20color:\x20#e9eaec;\x20border-color:\x20#333;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20#'+a0a+'\x20.header\x20{\x20display:\x20flex;\x20justify-content:\x20space-between;\x20align-items:\x20center;\x20font-weight:\x20700;\x20margin-bottom:\x208px;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20#'+a0a+'\x20.close\x20{\x20padding:\x204px\x208px;\x20border:\x200;\x20background:\x20#bbb;\x20color:\x20#fff;\x20border-radius:\x204px;\x20cursor:\x20pointer;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20body.dark\x20#'+a0a+'\x20.close\x20{\x20background:\x20#444;\x20color:\x20#e9eaec;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20#'+a0a+'\x20.item\x20{\x20margin-bottom:\x208px;\x20padding-bottom:\x208px;\x20border-bottom:\x201px\x20solid\x20#f2f2f2;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20body.dark\x20#'+a0a+'\x20.item\x20{\x20border-color:\x20#2c2c2c;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20#'+a0a+'\x20.meta\x20{\x20font-size:\x2012px;\x20color:\x20#666;\x20margin-bottom:\x204px;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20#'+a0a+'\x20.meta\x20a\x20{\x20color:\x20#00a1d6;\x20text-decoration:\x20none;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20body.dark\x20#'+a0a+'\x20.meta\x20{\x20color:\x20#9ca3af;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20#'+a0a+'\x20.text\x20{\x20font-size:\x2014px;\x20white-space:\x20pre-wrap;\x20word-break:\x20break-all;\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20#'+a0a+'\x20.count\x20{\x20font-size:\x2012px;\x20color:\x20#999;\x20margin-bottom:\x208px;\x20}\x0a\x20\x20\x20\x20'),a0c();async function a0c(){await a0d(),a0f();}async function a0d(){const a=await a0e(document,'bili-comments'),b=await a0e(a['shadowRoot'],'bili-comment-thread-renderer'),c=await a0e(b['shadowRoot'],'bili-comment-renderer');await a0e(c['shadowRoot'],'#body');}function a0e(a,b){return new Promise(c=>{const d=()=>{const e=a['querySelector'](b);e?c(e):setTimeout(d,0x1f4);};d();});}function a0f(){const a=document['querySelector']('bili-comments'),b=a['shadowRoot']['querySelectorAll']('bili-comment-thread-renderer');for(const c of b){const d=c['shadowRoot']['querySelector']('bili-comment-renderer');a0g(d);const e=c['shadowRoot']['querySelector']('bili-comment-replies-renderer'),f=e?.['shadowRoot']?.['querySelectorAll']('bili-comment-reply-renderer')||[];f['forEach'](a0g);}}function a0g(a){const b=a['shadowRoot']['querySelector']('#body'),c=a['shadowRoot']['querySelector']('bili-comment-action-buttons-renderer'),d=c['shadowRoot']['querySelector']('#reply'),e=b['querySelector']('a#user-avatar[href*=\x22space.bilibili.com\x22]'),f=e?.['href']['match'](/space\.bilibili\.com\/(\d+)/)?.[0x1],g=b['querySelector']('#user-name\x20a')?.['textContent']?.['trim']()||'UID'+f;a0h(d,f,g);}function a0h(a,b,c){const d=document['createElement']('div'),e=document['createElement']('button');e['textContent']='查看成分',e['onclick']=f=>a0i(f,b,c),d['appendChild'](e),a['after'](d);}async function a0i(a,b,c){let d=document['getElementById'](a0a);!d&&(d=document['createElement']('div'),d['id']=a0a,document['body']['appendChild'](d));const f=a['target']['getBoundingClientRect']();d['style']['left']=f['left']+window['scrollX']+'px',d['style']['top']=f['bottom']+window['scrollY']+0x5+'px',d['innerHTML']='历史评论\x20-\x20'+c+'关闭加载中...',d['style']['display']='block',d['querySelector']('.close')['onclick']=()=>d['style']['display']='none';try{const {list:g,total:h}=await a0j(b);a0m(d['querySelector']('.body'),g,h);}catch(i){d['querySelector']('.body')['textContent']='获取失败:'+i['message'];}}async function a0j(a){if(a0b['has'](a))return a0b['get'](a);try{const b=await a0k(a);return a0b['set'](a,b),b;}catch(c){throw c;}}async function a0k(a){let b=0x1;const c=[];let d=0x0;while(!![]){const e=await a0l(a,b),f=e?.['data']?.['replies']||[];d=e?.['data']?.['cursor']?.['all_count']||d,c['push'](...f);if(e?.['data']?.['cursor']?.['is_end']||!f['length'])break;b++,await new Promise(g=>setTimeout(g,0xc8));}return{'list':c,'total':d};}function a0l(a,b){return new Promise((c,d)=>{GM_xmlhttpRequest({'method':'GET','url':'https://api.aicu.cc/api/v3/search/getreply?uid='+a+'&pn='+b+'&ps=100&mode=0&keyword=','headers':{'Origin':'https://www.aicu.cc','Referer':'https://www.aicu.cc/'},'responseType':'json','onload':e=>{e['response']?.['code']===0x0?c(e['response']):d(new Error('接口异常:\x20code='+e['response']?.['code']+',\x20msg='+(e['response']?.['msg']||e['response']?.['message']||'未知')));},'onerror':()=>d(new Error('网络错误'))});});}function a0m(a,b,c){if(!b['length']){a['textContent']='暂无记录';return;}const d='共\x20'+c+'\x20条历史评论',e=b['map'](f=>{const g=f['time']?new Date(f['time']*0x3e8)['toLocaleString']():'',h=f['dyn']?.['oid'],i=f['rpid'],j=h?'https://www.bilibili.com/video/av'+h+'/#reply'+i:'',k=j?'跳转':'';return''+g+'\x20'+k+''+a0n(f['message']||'')+'';})['join']('');a['innerHTML']=d+e;}function a0n(a){return a['replace'](/[&<>"']/g,b=>({'&':'&','<':'<','>':'>','\x22':'"','\x27':'''}[b]));} })();