Skip to content

Commit 6604dfa

Browse files
authored
fix(markAsRead): adapt for new bilibili notification center and drop old support.
1 parent 4cb3df9 commit 6604dfa

File tree

1 file changed

+29
-41
lines changed

1 file changed

+29
-41
lines changed

scripts/ckylin-script-bilibili-mark-as-read.user.js

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,41 @@
22
// @name [Bilibili] MarkAsRead
33
// @name:zh-CN [Bilibili] 一键已读
44
// @namespace ckylin-script-bilibili-mark-as-read
5-
// @version 0.6
5+
// @version 0.7
66
// @description Mark all sessions as read with one click!
77
// @description:zh-CN 一键设置所有会话已读!
88
// @author CKylinMC
99
// @match https://message.bilibili.com/*
1010
// @grant unsafeWindow
11-
// @updateURL https://cdn.jsdelivr.net/gh/CKylinMC/UserJS/scripts/ckylin-script-bilibili-mark-as-read.user.js
1211
// @supportURL https://github.com/CKylinMC/UserJS
1312
// @license GPL-3.0-only
13+
// @downloadURL https://update.greasyfork.org/scripts/429152/%5BBilibili%5D%20MarkAsRead.user.js
14+
// @updateURL https://update.greasyfork.org/scripts/429152/%5BBilibili%5D%20MarkAsRead.meta.js
1415
// ==/UserScript==
1516

17+
/*
18+
提示:若你的功能现在还正常,请先不要更新。否则,你可能需要去脚本页面下载 0.6 旧版本。
19+
0.7版本仅适配新页面。
20+
*/
21+
1622
if (typeof (unsafeWindow) === "undefined") var unsafeWindow = window;
1723
(function () {
1824
'use strict';
1925
const blacklist_elTitle = ["我的应援团","未关注人消息","疑似不良消息"];
2026
const wait = t => new Promise(r => setTimeout(r, t));
21-
const inBlacklist = el=>{
22-
for(let titleItem of blacklist_elTitle){
23-
if(el.querySelector(`[title='${titleItem}']`)) return true;
24-
}
25-
return false;
26-
}
27-
const touch = async el => {
28-
el.click();
29-
await wait(100)
30-
};
31-
const touchList = async div => {
32-
let active = div.querySelector(".active");
33-
for (let el of [...div.children].splice(1)) {
34-
if (el.classList.contains("list-item") && el.querySelector(".notify") && !inBlacklist(el)) await touch(el)
27+
const touchList = async () => {
28+
for(const item of [...document.querySelectorAll("._SessionItem_dnmx0_1")]){
29+
if(item.getAttribute("data-id")?.startsWith("group")) continue;
30+
if(blacklist_elTitle.includes(item.querySelector("._SessionItem__Name_dnmx0_67")?.textContent.trim())) continue;
31+
item.click();
32+
await wait(100);
3533
}
36-
if (active) await touch(active)
37-
else location.hash = "#/whisper";
34+
//document.querySelector("._SessionItem_dnmx0_1").click();
35+
location.hash = "#/whisper";
3836
};
39-
const msgList = () => document.querySelector("div.list");
40-
const asRead = async () => await touchList(msgList());
41-
const settingList = () => document.querySelector("ul.list");
37+
const asRead = async () => await touchList();
38+
const settingList = () => document.querySelector("ul.message-sidebar__settings");
39+
const msgList = () => document.querySelector("._SessionList_1im8i_1");
4240
const intervalLog = {
4341
intervalId: null,
4442
lastHash: location.hash,
@@ -82,40 +80,30 @@ if (typeof (unsafeWindow) === "undefined") var unsafeWindow = window;
8280
}
8381
return false;
8482
};
83+
const settingsBtn = (icon, text)=>{
84+
return `<div class="message-sidebar__item-icon">${icon}</div><div class="message-sidebar__item-name">${text}</div>`
85+
}
8586
const injectBtn = async () => {
8687
if (await waitFor(() => settingList())) {
8788
let old;
8889
if (old = document.querySelector("#CKMARKREAD-BTN")) old.remove();
89-
const a = document.createElement("a");
90-
a.href = "javascript:void(0)";
91-
a.innerHTML = "💬 全部标为已读";
92-
a.onclick = async (e) => {
93-
e.target.innerHTML = "🕓 请稍等...";
90+
const item = document.createElement("li");
91+
item.classList.add("message-sidebar__item");
92+
item.innerHTML = settingsBtn('💬', '全部标为已读');
93+
item.onclick = async (e) => {
94+
e.target.innerHTML = settingsBtn('🕓', '请稍等...');
9495
await waitFor(() => msgList());
9596
await asRead();
96-
e.target.innerHTML = "✔ 已标为已读";
97-
e.target.onclick = e => e.target.innerHTML = "✔ 无需操作";
97+
e.target.innerHTML = settingsBtn('✔', '已标为已读');
98+
e.target.onclick = ev => ev.target.innerHTML = settingsBtn('✔', '无需操作');
9899
setTimeout(()=>{
99100
e.target.parentElement.style.transition = "margin .3s .2s, opacity .5s";
100101
e.target.parentElement.style.opacity = "0";
101102
e.target.parentElement.style.margin = "0px 0px";
102103
setTimeout(()=>e.target.parentElement.remove(),300);
103104
},3000);
104105
};
105-
const item = document.createElement("li");
106-
item.classList.add("item");
107-
item.id = "CKMARKREAD-BTN";
108-
item.style.opacity = "0";
109-
item.style.margin = "0px 0";
110-
item.style.transition = "all .3s";
111-
item.appendChild(a);
112106
settingList().appendChild(item);
113-
setTimeout(()=>{
114-
if(item){
115-
item.style.margin = "15px 0";
116-
item.style.opacity = "1";
117-
}
118-
},50)
119107
}
120108
};
121109
const delayedInjectTask = async () => {

0 commit comments

Comments
 (0)