Skip to content

Commit 1266661

Browse files
authored
Merge pull request #106 from lvdongyi/main
feat(unfollow): sort by latest feed
2 parents 6604dfa + 230f301 commit 1266661

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

scripts/ckylin-bilibili-unfollow.user.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
const getUnfolURL = () => `https://api.bilibili.com/x/relation/modify`;
203203
const getFollowURL = () => `https://api.bilibili.com/x/relation/batch/modify`;
204204
const getLatestVidURL = () => `https://api.bilibili.com/x/space/wbi/arc/search`;//wbi,?mid=${uid}&ps=1&pn=1`;
205+
const getLatestFeedURL = () => `https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space`;//wbi,?host_mid=${uid}`;
205206
const getSubInfoURL = uid => `https://api.bilibili.com/x/relation/stat?vmid=${uid}`;
206207
const getCreateGroupURL = () => `https://api.bilibili.com/x/relation/tag/create`;
207208
const getRenameGroupURL = () => `https://api.bilibili.com/x/relation/tag/update`;
@@ -386,6 +387,47 @@
386387
return null;
387388
}
388389
}
390+
const getLatestFeedDate = async uid => {
391+
try {
392+
const url = getLatestFeedURL() + "?offset=&host_mid=" + uid + "&features=itemOpusStyle,listOnlyfans,opusBigCover,onlyfansVote,forwardListHidden,decorationCard,commentsNewVersion,onlyfansAssetsV2,ugcDelete,onlyfansQaCard";
393+
console.log(url)
394+
const res = await fetch(getRequest(url));
395+
const jsonData = await res.json();
396+
console.log(jsonData)
397+
if (jsonData && jsonData.code === -352) {
398+
await alertModal(
399+
"风控提醒",
400+
"检测到风控,请打开任一用户动态页,完成验证码后点击确认继续获取。",
401+
"确认"
402+
);
403+
while (isModalShowing()) {
404+
await wait(200);
405+
}
406+
return await getLatestFeedDate(uid);
407+
}
408+
409+
if (!(jsonData && jsonData.code === 0 && jsonData.data && Array.isArray(jsonData.data.items))) {
410+
return { ok: false };
411+
}
412+
const items = jsonData.data.items;
413+
const count = items.length;
414+
if (count === 0) {
415+
return { ok: false };
416+
}
417+
const getTs = item => item?.modules?.module_author?.pub_ts || 0;
418+
if (count === 1) {
419+
const ts = getTs(items[0]);
420+
return { ok: true, value: ts };
421+
}
422+
const ts0 = getTs(items[0]);
423+
const ts1 = getTs(items[1]);
424+
const latestTs = Math.max(ts0, ts1);
425+
return { ok: true, value: latestTs };
426+
} catch (e) {
427+
log(uid, e);
428+
return { ok: false };
429+
}
430+
};
389431
const getLatestVideoPublishDate = async uid => {
390432
try {
391433
const jsonData = await (await fetch(getRequest(getLatestVidURL() + "?" + await getWbiSignedParams({
@@ -559,6 +601,10 @@
559601
resetInfoBar();
560602
return datas.mappings[uid];
561603
}
604+
let feedsInfo = await getLatestFeedDate(uid);
605+
if (feedsInfo.ok) {
606+
datas.mappings[uid].latestFeed = feedsInfo.value;
607+
}
562608
let userinfo = await getUserStats(uid, refresh, fast);
563609
if (userinfo.ok) {
564610
if (refresh) datas.mappings[uid] = userinfo;
@@ -3167,6 +3213,30 @@
31673213
hideModal();
31683214
}
31693215
}),
3216+
datas.settings.enableExpermentals &&
3217+
await makeDom("button", btn => {
3218+
btn.className = "CKFOMAN-toolbar-btns CKFOMAN-sortbtns";
3219+
btn.innerHTML = "按最新动态日期排序 (实验)";
3220+
btn.onclick = async e => {
3221+
setInfoBar("正在按最新动态日期排序...");
3222+
await alertModal("正在排序...", "请稍等...");
3223+
refreshChecked();
3224+
datas.followings.sort((a, b)=>{
3225+
const upA = a.latestFeed || 0;
3226+
const upB = b.latestFeed || 0;
3227+
3228+
if (upA > upB) {
3229+
return -1;
3230+
} else if (upA < upB) {
3231+
return 1;
3232+
} else {
3233+
return 0;
3234+
}
3235+
});
3236+
await renderListTo(get("#CKFOMAN-MAINLIST"), datas.followings, true);
3237+
hideModal();
3238+
}
3239+
}),
31703240
await makeDom("button", btn => {
31713241
btn.className = "CKFOMAN-toolbar-btns CKFOMAN-sortbtns";
31723242
btn.innerHTML = "反向当前排序";

0 commit comments

Comments
 (0)