|
2 | 2 | // @name [Bilibili] MarkAsRead |
3 | 3 | // @name:zh-CN [Bilibili] 一键已读 |
4 | 4 | // @namespace ckylin-script-bilibili-mark-as-read |
5 | | -// @version 0.6 |
| 5 | +// @version 0.7 |
6 | 6 | // @description Mark all sessions as read with one click! |
7 | 7 | // @description:zh-CN 一键设置所有会话已读! |
8 | 8 | // @author CKylinMC |
9 | 9 | // @match https://message.bilibili.com/* |
10 | 10 | // @grant unsafeWindow |
11 | | -// @updateURL https://cdn.jsdelivr.net/gh/CKylinMC/UserJS/scripts/ckylin-script-bilibili-mark-as-read.user.js |
12 | 11 | // @supportURL https://github.com/CKylinMC/UserJS |
13 | 12 | // @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 |
14 | 15 | // ==/UserScript== |
15 | 16 |
|
| 17 | +/* |
| 18 | +提示:若你的功能现在还正常,请先不要更新。否则,你可能需要去脚本页面下载 0.6 旧版本。 |
| 19 | +0.7版本仅适配新页面。 |
| 20 | +*/ |
| 21 | + |
16 | 22 | if (typeof (unsafeWindow) === "undefined") var unsafeWindow = window; |
17 | 23 | (function () { |
18 | 24 | 'use strict'; |
19 | 25 | const blacklist_elTitle = ["我的应援团","未关注人消息","疑似不良消息"]; |
20 | 26 | 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); |
35 | 33 | } |
36 | | - if (active) await touch(active) |
37 | | - else location.hash = "#/whisper"; |
| 34 | + //document.querySelector("._SessionItem_dnmx0_1").click(); |
| 35 | + location.hash = "#/whisper"; |
38 | 36 | }; |
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"); |
42 | 40 | const intervalLog = { |
43 | 41 | intervalId: null, |
44 | 42 | lastHash: location.hash, |
@@ -82,40 +80,30 @@ if (typeof (unsafeWindow) === "undefined") var unsafeWindow = window; |
82 | 80 | } |
83 | 81 | return false; |
84 | 82 | }; |
| 83 | + const settingsBtn = (icon, text)=>{ |
| 84 | + return `<div class="message-sidebar__item-icon">${icon}</div><div class="message-sidebar__item-name">${text}</div>` |
| 85 | + } |
85 | 86 | const injectBtn = async () => { |
86 | 87 | if (await waitFor(() => settingList())) { |
87 | 88 | let old; |
88 | 89 | 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('🕓', '请稍等...'); |
94 | 95 | await waitFor(() => msgList()); |
95 | 96 | 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('✔', '无需操作'); |
98 | 99 | setTimeout(()=>{ |
99 | 100 | e.target.parentElement.style.transition = "margin .3s .2s, opacity .5s"; |
100 | 101 | e.target.parentElement.style.opacity = "0"; |
101 | 102 | e.target.parentElement.style.margin = "0px 0px"; |
102 | 103 | setTimeout(()=>e.target.parentElement.remove(),300); |
103 | 104 | },3000); |
104 | 105 | }; |
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); |
112 | 106 | settingList().appendChild(item); |
113 | | - setTimeout(()=>{ |
114 | | - if(item){ |
115 | | - item.style.margin = "15px 0"; |
116 | | - item.style.opacity = "1"; |
117 | | - } |
118 | | - },50) |
119 | 107 | } |
120 | 108 | }; |
121 | 109 | const delayedInjectTask = async () => { |
|
0 commit comments