[Bilibili] MarkAsRead

Mark all sessions as read with one click!

目前為 2021-07-10 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name [Bilibili] MarkAsRead
  3. // @name:zh-CN [Bilibili] 一键已读
  4. // @namespace ckylin-script-bilibili-mark-as-read
  5. // @version 0.1
  6. // @description Mark all sessions as read with one click!
  7. // @description:zh-CN 一键设置所有会话已读!
  8. // @author CKylinMC
  9. // @match https://message.bilibili.com/*
  10. // @grant unsafeWindow
  11. // @supportURL https://github.com/CKylinMC/UserJS
  12. // @license GPL-3.0-only
  13. // ==/UserScript==
  14.  
  15. if(typeof(unsafeWindow)==="undefined") var unsafeWindow = window;
  16. (function() {
  17. 'use strict';
  18. const wait = t => new Promise(r => setTimeout(r, t));
  19. const touch = async el=>{el.click();await wait(100)};
  20. const touchList = async div=>{let active = div.querySelector(".active");for(let el of [...div.children].splice(1)){if(el.classList.contains("list-item"))await touch(el)};if(active) await touch(active)};
  21. const msgList = () =>document.querySelector("div.list");
  22. const asRead = async ()=>await touchList(msgList());
  23. const settingList = () => document.querySelector("ul.list");
  24. const waitFor = async (func, waitt=100, retries = 100) => {
  25. while(--retries>0){
  26. try{
  27. const val = await func();
  28. if(val) return val;
  29. await wait(waitt);
  30. }catch(e){console.log(e);await wait(100);}
  31. }
  32. return false;
  33. };
  34. const injectBtn = async ()=>{
  35. if(await waitFor(()=>settingList())){
  36. let old;
  37. if(old = document.querySelector("#CKMARKREAD-BTN"))old.remove();
  38. const a = document.createElement("a");
  39. a.href="javascript:void(0)";
  40. a.innerHTML = "💬 全部标为已读";
  41. a.onclick = async (e)=>{
  42. e.target.innerHTML = "🕓 请稍等...";
  43. await waitFor(()=>msgList());
  44. await asRead();
  45. e.target.innerHTML = "✔ 已标为已读";
  46. e.target.onclick = ()=>alert("请勿重复、频繁操作!\n反复执行可能导致B站暂停你的消息发送功能数分钟!");
  47. };
  48. const item = document.createElement("li");
  49. item.classList.add("item");
  50. item.id = "CKMARKREAD-BTN";
  51. item.style.margin = "15px 0";
  52. item.appendChild(a);
  53. settingList().appendChild(item);
  54. }
  55. };
  56. const delayedInjectTask = async ()=>{await wait(1000);injectBtn()};
  57. delayedInjectTask();
  58. })();// ==UserScript==
  59. // @name [Bilibili] MarkAsRead
  60. // @name:cn [Bilibili] 一键已读
  61. // @namespace ckylin-script-bilibili-mark-as-read
  62. // @version 0.1
  63. // @description Mark all sessions as read with one click!
  64. // @description:cn 一键设置所有会话已读!
  65. // @author CKylinMC
  66. // @match https://message.bilibili.com/*
  67. // @grant unsafeWindow
  68. // ==/UserScript==
  69.  
  70. (function() {
  71. 'use strict';
  72. if(typeof(unsafeWindow)==="undefined") var unsafeWindow = window;
  73. const wait = t => new Promise(r => setTimeout(r, t));
  74. const touch = async el=>{el.click();await wait(100)};
  75. const touchList = async div=>{let active = div.querySelector(".active");for(let el of [...div.children].splice(1)){if(el.classList.contains("list-item"))await touch(el)};if(active) await touch(active)};
  76. const msgList = () =>document.querySelector("div.list");
  77. const asRead = async ()=>await touchList(msgList());
  78. const settingList = () => document.querySelector("ul.list");
  79. const waitFor = async (func, waitt=100, retries = 100) => {
  80. while(--retries>0){
  81. try{
  82. const val = await func();
  83. if(val) return val;
  84. await wait(waitt);
  85. }catch(e){console.log(e);await wait(100);}
  86. }
  87. return false;
  88. };
  89. const injectBtn = async ()=>{
  90. if(await waitFor(()=>settingList())){
  91. let old;
  92. if(old = document.querySelector("#CKMARKREAD-BTN"))old.remove();
  93. const a = document.createElement("a");
  94. a.href="javascript:void(0)";
  95. a.innerHTML = "💬 全部标为已读";
  96. a.onclick = async (e)=>{
  97. e.target.innerHTML = "🕓 请稍等...";
  98. await waitFor(()=>msgList());
  99. await asRead();
  100. e.target.innerHTML = "✔ 已标为已读";
  101. e.target.onclick = ()=>alert("请勿重复、频繁操作!\n反复执行可能导致B站暂停你的消息发送功能数分钟!");
  102. };
  103. const item = document.createElement("li");
  104. item.classList.add("item");
  105. item.id = "CKMARKREAD-BTN";
  106. item.style.margin = "15px 0";
  107. item.appendChild(a);
  108. settingList().appendChild(item);
  109. }
  110. };
  111. const delayedInjectTask = async ()=>{await wait(1000);injectBtn()};
  112. delayedInjectTask();
  113. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址