屏蔽链滴用户

屏蔽指定链滴用户的帖子

  1. // ==UserScript==
  2. // @name 屏蔽链滴用户
  3. // @namespace Violentmonkey Scripts
  4. // @version 0.1.5
  5. // @description 屏蔽指定链滴用户的帖子
  6. // @author zxkmm
  7. // @author frostime
  8. // @author TCOTC
  9. // @homepage https://github.com/zxkmm/ld246_blacklist
  10. // @supportURL https://github.com/zxkmm/ld246_blacklist/issues
  11. // @match https://ld246.com/*
  12. // @grant GM_setValue
  13. // @grant GM_getValue
  14. // @grant GM_deleteValue
  15. // @grant GM_addStyle
  16. // ==/UserScript==
  17.  
  18. /*notes
  19. * 头像区块 style class:article-list__user fn__flex fn__flex-center
  20. * 帖子作者div style class:avatar-small tooltipped__user
  21. * 帖子协作人 style class:avatar-small tooltipped__user article-list__participant (!!!!!query不article-list__participant
  22. *
  23. *
  24. * */
  25.  
  26. (function () {
  27. "use strict";
  28.  
  29. const blockedUsersKey = "blockedUsers";
  30. const remindWayKey = "remindWay";
  31. let blockedUsers = GM_getValue(blockedUsersKey, []);
  32. let remindWay = GM_getValue(remindWayKey, "opacity"); // init var aka default as opa
  33.  
  34. //public shame list
  35. const publicShameUser = [];
  36. // const publicShameUser = ["science"];
  37. //public shame end
  38. //Main style
  39. const customStyle = `
  40. .block-it.block-it__hide {
  41. display: none;
  42. }
  43.  
  44. .block-it.block-it__opacity {
  45. opacity: 0.1;
  46. }
  47. .block-it.block-it__opacity .article-list__abstract {
  48. display: none;
  49. }
  50.  
  51. .block-it.block-it__blur {
  52. filter: blur(5px);
  53. }
  54. .block-it.block-it__blur:hover {
  55. filter: none;
  56. }
  57.  
  58. .block-it .article-list__panel {
  59. padding: 5px 15px;
  60. }
  61. .block-it .article-list__title--view, .block-it .article-list__title>a {
  62. font-size: 14px;
  63. }
  64. .block-it .article-list__abstract {
  65. font-size: 12px;
  66. }
  67. .block-it .tooltipped__user {
  68. height: 12px;
  69. width: 12px;
  70. }
  71. .blocked-users-list {
  72. max-height: 400px;
  73. overflow-y: auto;
  74. mask-image: linear-gradient(to bottom, transparent, black 10%, black 90%, transparent);
  75. -webkit-mask-image: linear-gradient(to bottom, transparent, black 10%, black 90%, transparent);
  76. }
  77. `;
  78. GM_addStyle(customStyle);
  79.  
  80. // 创建用户界面
  81. const createUI = () => {
  82. const styles = `
  83. .modern-ui {
  84. background-color: #000000;
  85. border: 1px solid #e3e3e3;
  86. border-radius: 5px;
  87. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  88. padding: 15px;
  89. width: 280px;
  90. }
  91. .modern-ui input {
  92. width: 100%;
  93. padding: 8px;
  94. margin-bottom: 10px;
  95. border: 1px solid #000000;
  96. border-radius: 3px;
  97. box-sizing: border-box;
  98. background-color: #333333 !important;
  99. color: #e0e0e0 !important;
  100. }
  101. .modern-ui button, .modern-ui select {
  102. width: 100%;
  103. padding: 8px;
  104. margin-bottom: 10px;
  105. border: 1px solid #000000;
  106. border-radius: 3px;
  107. box-sizing: border-box;
  108. }
  109. .modern-ui select {
  110. background-color: #333333;
  111. color: #e0e0e0;
  112. }
  113. .modern-ui button {
  114. background-color: #FFA500;
  115. color: #000000;
  116. border: none;
  117. cursor: pointer;
  118. transition: background-color 0.3s;
  119. }
  120. .modern-ui button:hover {
  121. background-color: #FF8C00;
  122. }
  123. .modern-ui ul {
  124. list-style-type: none;
  125. padding: 0;
  126. max-height: 200px;
  127. overflow-y: auto;
  128. border: 1px solid #000000;
  129. border-radius: 3px;
  130. }
  131. .modern-ui li {
  132. background-color: #505050;
  133. border-bottom: 1px solid #e0e0e0;
  134. padding: 8px;
  135. display: flex;
  136. justify-content: space-between;
  137. align-items: center;
  138. color: #e0e0e0;
  139. }
  140. .modern-ui li:last-child {
  141. border-bottom: none;
  142. }
  143. .modern-ui li button {
  144. width: auto;
  145. padding: 3px 8px;
  146. margin: 0;
  147. background-color: #FFA500;
  148. color: #000000;
  149. }
  150. .modern-ui li button:hover {
  151. background-color: #FF8C00;
  152. }
  153. .toggle-button {
  154. position: fixed;
  155. bottom: 20px;
  156. right: 20px;
  157. background-color: #FFA500;
  158. color: #000000;
  159. border: none;
  160. padding: 8px 15px;
  161. border-radius: 3px;
  162. cursor: pointer;
  163. z-index: 1001;
  164. }
  165. .toggle-button:hover {
  166. background-color: #FF8C00;
  167. }
  168. .modern-ui label {
  169. color: #e0e0e0;
  170. }
  171. `;
  172.  
  173. const styleElement = document.createElement("style");
  174. styleElement.textContent = styles;
  175. document.head.appendChild(styleElement);
  176.  
  177. const uiContainer = document.createElement("div");
  178. uiContainer.className = "modern-ui";
  179. uiContainer.style.position = "fixed";
  180. uiContainer.style.bottom = "80px";
  181. uiContainer.style.right = "20px";
  182. uiContainer.style.zIndex = "1000";
  183. uiContainer.style.display = "none";
  184.  
  185. const toggleButton = document.createElement("button");
  186. toggleButton.textContent = "黑名单管理";
  187. toggleButton.className = "toggle-button";
  188.  
  189. toggleButton.addEventListener("click", () => {
  190. uiContainer.style.display =
  191. uiContainer.style.display === "none" ? "block" : "none";
  192. });
  193.  
  194. const input = document.createElement("input");
  195. input.type = "text";
  196. input.placeholder = "留空自动加当前人";
  197.  
  198. const addButton = document.createElement("button");
  199. addButton.textContent = "添加到黑名单";
  200. addButton.addEventListener("click", () => {
  201. var username = input.value.trim();
  202. if (!username) {
  203. username = autoFetchUsername();
  204. }
  205. if (username && !blockedUsers.includes(username)) {
  206. blockedUsers.push(username);
  207. GM_setValue(blockedUsersKey, blockedUsers);
  208. updateBlockedUsersList();
  209. input.value = "";
  210. }
  211. });
  212.  
  213. const blockedUsersList = document.createElement("ul");
  214.  
  215. const updateBlockedUsersList = () => {
  216. blockedUsersList.innerHTML = "";
  217.  
  218. publicShameUser.forEach((user) => {
  219. const listItem = document.createElement("li");
  220. listItem.innerHTML = `${user} <span style="color: #888;">(这位是🤡,无法删除)</span>`;
  221. blockedUsersList.appendChild(listItem);
  222. });
  223.  
  224. blockedUsers.forEach((user, index) => {
  225. const listItem = document.createElement("li");
  226. listItem.innerHTML = `
  227. <span>${user}</span>
  228. <button class="delete-button">删除</button>
  229. `;
  230. const deleteButton = listItem.querySelector(".delete-button");
  231. deleteButton.addEventListener("click", () => {
  232. blockedUsers.splice(index, 1);
  233. GM_setValue(blockedUsersKey, blockedUsers);
  234. updateBlockedUsersList();
  235. });
  236. blockedUsersList.appendChild(listItem);
  237. });
  238. };
  239.  
  240. const remindWaySelect = document.createElement("select");
  241. const remindWays = [
  242. { value: "hide", text: "隐藏" },
  243. { value: "blur", text: "模糊(悬浮时取消)" },
  244. { value: "opacity", text: "白雾" },
  245. ];
  246. remindWays.forEach((way) => {
  247. const option = document.createElement("option");
  248. option.value = way.value;
  249. option.text = way.text;
  250. if (way.value === remindWay) {
  251. option.selected = true;
  252. }
  253. remindWaySelect.appendChild(option);
  254. });
  255.  
  256. remindWaySelect.addEventListener("change", () => {
  257. remindWay = remindWaySelect.value;
  258. GM_setValue(remindWayKey, remindWay);
  259. });
  260.  
  261. const label = document.createElement("label");
  262. label.textContent = "标记帖子方式: ";
  263. label.appendChild(remindWaySelect);
  264. label.style.color = "#e0e0e0";
  265.  
  266. uiContainer.appendChild(input);
  267. uiContainer.appendChild(addButton);
  268. uiContainer.appendChild(label);
  269. uiContainer.appendChild(blockedUsersList);
  270. document.body.appendChild(uiContainer);
  271. document.body.appendChild(toggleButton);
  272.  
  273. updateBlockedUsersList();
  274. };
  275.  
  276. createUI();
  277.  
  278. const autoFetchUsername = () => {
  279. /**
  280. * notes
  281.  
  282. *
  283. *
  284. * style class `article__sideuser`
  285. * string elem `a`
  286. *
  287. */
  288. const sideuserElement = document.querySelector(".article__sideuser");
  289.  
  290. if (sideuserElement) {
  291. const linkElement = sideuserElement.querySelector("a");
  292.  
  293. if (linkElement) {
  294. const username = linkElement.textContent.trim();
  295.  
  296. const overlay = document.createElement("div");
  297. overlay.style.position = "fixed";
  298. overlay.style.top = "50%";
  299. overlay.style.left = "50%";
  300. overlay.style.backgroundColor = "rgba(0, 0, 0)";
  301. overlay.style.color = "white";
  302. overlay.style.padding = "10px";
  303. overlay.style.borderRadius = "5px";
  304. overlay.style.zIndex = "9999";
  305. overlay.style.fontSize = "32px";
  306. overlay.style.textAlign = "center";
  307. overlay.textContent = `自动获取到这位用户: ${username},请核实,已添加`;
  308.  
  309. document.body.appendChild(overlay);
  310.  
  311. setTimeout(() => {
  312. document.body.removeChild(overlay);
  313. }, 1000);
  314.  
  315. //^ overlay
  316.  
  317. return username;
  318. }
  319. }
  320.  
  321. return null;
  322. };
  323.  
  324. const blockPosts = () => {
  325. const posts = document.querySelectorAll(".article-list__item");
  326. // console.log(!posts);
  327. if (!posts) return;
  328. posts.forEach((post) => {
  329. const authorElement = post.querySelector(
  330. ".article-list__user .tooltipped__user",
  331. );
  332. if (!authorElement) return;
  333.  
  334. const authorName = authorElement.getAttribute("aria-name"); //fetch username
  335. if (!authorName) return;
  336.  
  337. if (
  338. blockedUsers.includes(authorName) ||
  339. publicShameUser.includes(authorName)
  340. ) {
  341. post.classList.toggle("block-it", true);
  342. switch (remindWay) {
  343. case "hide":
  344. post.classList.toggle("block-it__hide", true);
  345. break;
  346. case "blur":
  347. post.classList.toggle("block-it__blur", true);
  348. /*
  349. post.style.filter = "blur(5px)";
  350. post.addEventListener("mouseenter", () => {
  351. post.style.filter = "none";
  352. });
  353. post.addEventListener("mouseleave", () => {
  354. post.style.filter = "blur(5px)";
  355. });*/
  356. break;
  357. case "opacity":
  358. post.classList.toggle("block-it__opacity", true);
  359. }
  360. }
  361. });
  362. };
  363.  
  364. // 使用 MutationObserver 监听页面变化
  365. const observer = new MutationObserver((mutationsList, observer) => {
  366. for (const mutation of mutationsList) {
  367. if (mutation.type === "childList") {
  368. blockPosts();
  369. // console.log("------blocked------");
  370. }
  371. }
  372. });
  373.  
  374. observer.observe(document.body, { childList: true, subtree: true });
  375.  
  376. // 初始执行一次
  377. blockPosts();
  378. })();

QingJ © 2025

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