// ==UserScript== // @name B站动态按照日期归类 // @namespace http://tampermonkey.net/ // @version 0.1 // @description B站动态按照日期归类。仅作为DD调研用,若有滥用等问题概不负责诶嘿。 // @author 太陽闇の力 // @include /https?:\/\/space\.bilibili\.com/ // @grant GM_addStyle // @grant GM_registerMenuCommand // @license MIT // @downloadURL none // ==/UserScript== (function() { let flag = true; let flag2 = true; GM_registerMenuCommand("启动归类",async()=>{ if(!flag)return; const relation = {"1": "转发","2": "图片","4": "文字","8": "视频","64": "专栏","256": "音频"}; let cardList={}; let dateList = []; const uid = /\d+/.exec(location.pathname)[0]; let offset_dynamic_id = 0; let has_more = 1; while(has_more){ let url = `https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?visitor_uid=0&host_uid=${uid}&offset_dynamic_id=${offset_dynamic_id}&platform=web` let res =await fetcher(url); if(res.data.cards){ offset_dynamic_id = res.data.cards[res.data.cards.length-1].desc.dynamic_id_str; for(let card of res.data.cards){ const cardType = relation[card.desc.type]||"未知"; const cardId = card.desc.dynamic_id_str; const cardTime = fmtDate(card.desc.timestamp*1000); const cardJson = JSON.parse(card.card); const content = cardJson?.item?.content||cardJson?.item?.description|| cardJson?.dynamic||cardJson?.title; if(!cardList[cardTime]){ cardList[cardTime] = []; } cardList[cardTime].push([cardId,content,cardType]); dateList.push(cardTime) } } has_more = res.data.has_more; } function fmtDate(obj){ var date = new Date(obj); var y = 1900+date.getYear(); var m = "0"+(date.getMonth()+1); var d = "0"+date.getDate(); return y+"-"+m.substring(m.length-2,m.length)+"-"+d.substring(d.length-2,d.length); } async function fetcher(url) { const res = await fetch(url) if (!res.ok) { throw new Error(res.statusText) } const data = await res.json() if (data.code != 0) { throw new Error("B站API请求错误:" + data.message) } return data } GM_addStyle(` * { margin: 0; padding: 0; } ul { list-style: none; } #schedule-box { width: 320px; margin-bottom: 10px; padding: 10px 20px; font-size: 13px; } .schedule-hd { display: flex; justify-content: space-between; padding: 0 15px; } .today { flex: 1; text-align: center; } .ul-box { overflow: hidden; } .ul-box>li { float: left; width: 14.28%; text-align: center; padding: 5px 0; } .other-month { color: #999999; } .disabled { pointer-events: none; background-color: #eeeeee; color: #999999; } .current-month { color: #333333; } .today-style { border-radius: 50%; background: #58d321; } .arrow { cursor: pointer; } .dayStyle { display: inline-block; width: 35px; height: 35px; border-radius: 50%; text-align: center; line-height: 35px; cursor: pointer; } .current-month>.dayStyle:hover { background: #ffba5a; color: #ffffff; } .today-flag { background: #00C2B1; color: #fff; } .boxshaw { box-shadow:2px -4px 15px 2px #e3e3e3; } .selected-style { background-color: #00BDFF; color: #ffffff; } .active-style { background: #ffba5a; color: #ffffff; } .today { text-align: center; color: #8ac6d1; padding: 5px 0 0; font-weight: bold; cursor: pointer; font-size: 15px; } @font-face {font-family: "iconfont"; } .iconfont { font-family:"iconfont" !important; font-size:16px; font-style:normal; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .icon-115rightarrowheads:before { content: "▶"; } .icon-111arrowheadright:before { content: "▷"; } .icon-116leftarrowheads:before { content: "◀"; } .icon-112leftarrowhead:before { content: "◁"; } table { font-family: arial, sans-serif; border: 1px solid #dddddd80; border-radius: 8px; border-collapse:separate; width: 100%; } td{ border: 0; text-align: left; padding: 8px; } #tdiv::-webkit-scrollbar{ display:none } ` ) var div = document.createElement('div'); div.style.cssText = 'max-width:360px;position:fixed;top:70px;left:200px;z-index:999;background-color:#ffffffc2;border-bottom-right-radius:8px;border-bottom-left-radius:8px;'; const closeButton = window.document.createElement('button'); closeButton.innerText = "ㄨ"; closeButton.style.cssText = 'float:right;border:none;cursor:pointer;background-color:#ffffffc2;border-radius:1px;color:red;'; const collapseButton = window.document.createElement('button'); collapseButton.innerText = "─"; collapseButton.style.cssText = 'width:13.34px;height:17px;float: right;margin-right:3px;border:none;cursor:pointer;background-color:#ffffffc2;border-radius:1px;'; var sb = document.createElement('div'); sb.id = 'schedule-box'; sb.classList.add('boxshaw'); var tb = document.createElement('table'); var tdiv = document.createElement('div'); tdiv.id = "tdiv"; tdiv.style.cssText ="max-height:200px;overflow-y:scroll;overflow-x:hidden;" tdiv.append(tb) div.append(closeButton); div.append(collapseButton); div.append(sb); tdiv.append(tb); div.append(tdiv); document.body.appendChild(div); closeButton.addEventListener("click",()=>{ div.remove(); flag = true; flag2 = true; }); collapseButton.addEventListener("click",()=>{ if(flag2){ sb.style.display = "none"; tdiv.style.display = "none"; closeButton.style.display = "none"; collapseButton.style.height = "20px"; collapseButton.style.width = "15.7px"; flag2 = false; }else{ sb.style.display = "block"; tdiv.style.display = "block"; closeButton.style.display = "block"; collapseButton.style.height = "17px"; collapseButton.style.width = "13.34px"; flag2 = true; } }); var mySchedule = new Schedule({ el: '#schedule-box', //容器元素 disabledBefore: dateList[dateList.length-1], //禁用此日期之前 disabledAfter: dateList[0], //禁用此日期之后 selectedDate: dateList, //选中的日期 showToday: true, //回到今天 clickCb: function (date) { tb.innerHTML=""; if(cardList[date]){ for(let i of cardList[date]){ const cardurl = `https://t.bilibili.com/${i[0]}?tab=2` tb.innerHTML += `