Bluesky Repost Hider

"Hide Reposts" button for Bluesky

目前为 2024-11-24 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Bluesky Repost Hider
  3. // @description "Hide Reposts" button for Bluesky
  4. // @version 1.0
  5. // @namespace https://github.com/tmaster-terrarian/Userscripts/tree/main/Bluesky%20Repost%20Hider
  6. // @match https://bsky.app/profile/*
  7. // @author bscit
  8. // @license MIT
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=bsky.app
  10. // @grant GM_addStyle
  11. // ==/UserScript==
  12.  
  13. GM_addStyle(`
  14.  
  15. .__toggle-button-holder {
  16. background-color: #000000;
  17. }
  18.  
  19. .__toggle-button-holder .__toggle-button {
  20. flex-direction: row;
  21. align-items: center;
  22. justify-content: center;
  23. background-color: rgb(20, 27, 35);
  24. padding: 9px 12px;
  25. border-radius: 999px;
  26. gap: 6px;
  27.  
  28. width: fit-content;
  29. margin: 0.875em 0.875em 6px;
  30. }
  31.  
  32. .__toggle-button-holder .__toggle-button:hover {
  33. background-color: rgb(28, 39, 50);
  34. }
  35.  
  36. .__toggle-button-holder .__toggle-button div {
  37. font-size: 0.765625em;
  38. letter-spacing: 0px;
  39. color: rgb(169, 183, 197);
  40. font-weight: 600;
  41. text-align: center;
  42. line-height: 14px;
  43. font-family: InterVariable, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  44. font-variant: no-contextual;
  45. }
  46.  
  47. .__repost {
  48. overflow: hidden;
  49. transition-property: opacity, max-height;
  50. transition-duration: 0.25s;
  51. }
  52.  
  53. .__repost.__hide-repost {
  54. opacity: 0 !important;
  55. max-height: 0 !important;
  56. }
  57.  
  58. html.theme--dim .__toggle-button-holder {
  59. background-color: #ffffff !important;
  60. }
  61. html.theme--light .__toggle-button-holder .__toggle-button {
  62. background-color: rgb(241, 243, 245) !important;
  63. }
  64. html.theme--light .__toggle-button-holder .__toggle-button:hover {
  65. background-color: rgb(226, 231, 236) !important;
  66. }
  67. html.theme--light .__toggle-button-holder .__toggle-button div {
  68. color: rgb(66, 87, 108) !important;
  69. }
  70.  
  71. html.theme--dim .__toggle-button-holder {
  72. background-color: #161e27 !important;
  73. }
  74. html.theme--dim .__toggle-button-holder .__toggle-button {
  75. background-color: rgb(30, 41, 54) !important;
  76. }
  77. html.theme--dim .__toggle-button-holder .__toggle-button:hover {
  78. background-color: rgb(38, 53, 68) !important;
  79. }
  80. html.theme--dim .__toggle-button-holder .__toggle-button div {
  81. color: rgb(174, 187, 201) !important;
  82. }
  83.  
  84. `);
  85.  
  86. (function() {
  87. 'use strict';
  88.  
  89. // Your code here...
  90.  
  91. let hidden = null;
  92.  
  93. let feedItems = [];
  94. let lastFeedLength = 0;
  95.  
  96. let profileHandle = window.location.href.replace("https://bsky.app/profile/", "");
  97. const _extraPathIndex = profileHandle.indexOf("/");
  98. if(_extraPathIndex !== -1)
  99. {
  100. profileHandle = profileHandle.substring(0, _extraPathIndex);
  101. }
  102.  
  103. const toggleButtonContent = document.createElement("div");
  104. toggleButtonContent.innerText = hidden ? "Show Reposts" : "Hide Reposts";
  105.  
  106. const Apply = (changed = false) => {
  107. const arr = Array.from(feedItems);
  108. let scroll = 0;
  109. arr.forEach((element, i) => {
  110. if(i == 0 || i == arr.length - 1 || i == arr.length - 2) return;
  111.  
  112. if(!element.firstElementChild) return;
  113.  
  114. const childElement = element.firstElementChild.firstElementChild;
  115. if(!childElement) return;
  116.  
  117. const attribute = childElement.getAttribute("data-testid");
  118. if(attribute === null) return;
  119.  
  120. if(attribute.replace("feedItem-by-", "") == profileHandle) return;
  121.  
  122. childElement.classList.add("__repost");
  123.  
  124. const isAbove = (childElement.getBoundingClientRect().bottom < (window.innerHeight / 2));
  125.  
  126. if(hidden) {
  127. childElement.classList.add("__hide-repost");
  128. childElement.style.maxHeight = "0";
  129.  
  130. if(changed && isAbove) scroll -= childElement.scrollHeight;
  131. }
  132. else {
  133. childElement.classList.remove("__hide-repost");
  134. childElement.style.maxHeight = childElement.scrollHeight + "px";
  135.  
  136. if(changed && isAbove) scroll += childElement.scrollHeight;
  137. }
  138.  
  139. toggleButtonContent.innerText = hidden ? "Show Reposts" : "Hide Reposts";
  140. });
  141.  
  142. // if(changed)
  143. // {
  144. // window.scrollBy({
  145. // left: 0,
  146. // top: scroll,
  147. // behavior: "instant"
  148. // });
  149. // }
  150. };
  151.  
  152. setInterval(() => {
  153. if(lastFeedLength != feedItems.length)
  154. {
  155. Apply();
  156. }
  157. lastFeedLength = feedItems.length;
  158. }, 250);
  159.  
  160. let smallWindow = false;
  161. window.addEventListener("resize", (event) => {
  162. if(!smallWindow && window.innerWidth < 800)
  163. {
  164. smallWindow = true;
  165. Apply();
  166. }
  167. else if(smallWindow && window.innerWidth >= 800)
  168. {
  169. smallWindow = false;
  170. Apply();
  171. }
  172. });
  173.  
  174. const toggleElement = document.createElement("div");
  175. toggleElement.classList.add("css-175oi2r");
  176. toggleElement.classList.add("r-18u37iz");
  177. toggleElement.classList.add("__toggle-button-holder");
  178.  
  179. const toggleButton = document.createElement("button");
  180. toggleButton.classList.add("css-175oi2r");
  181. toggleButton.classList.add("r-1loqt21");
  182. toggleButton.classList.add("r-1otgn73");
  183. toggleButton.classList.add("__toggle-button");
  184. toggleButton.setAttribute("type", "button");
  185. toggleButton.setAttribute("role", "button");
  186. toggleButton.addEventListener("click", (event) => {
  187. if(hidden == null) return;
  188.  
  189. hidden = !hidden;
  190. Apply(true);
  191. });
  192.  
  193. toggleButtonContent.classList.add("css-146c3p1");
  194. toggleButton.appendChild(toggleButtonContent);
  195.  
  196. toggleElement.appendChild(toggleButton);
  197.  
  198. let attempts = 0;
  199. const TrySetup = () => {
  200. if(attempts >= 5) return false;
  201. setTimeout(() => {
  202. attempts++;
  203. try
  204. {
  205. feedItems = document.querySelector(".css-175oi2r.r-sa2ff0").children;
  206. }
  207. catch(err)
  208. {
  209. console.error(err);
  210. if(!TrySetup()) console.error("Too many failed attempts to initialize Bluesky Repost Hider; aborting");
  211. return;
  212. }
  213. lastFeedLength = feedItems.length;
  214. hidden = false;
  215.  
  216. const header = document.querySelector(".css-175oi2r.r-gtdqiz.r-ipm5af.r-184en5c").firstElementChild.parentNode;
  217. header.insertBefore(toggleElement, header.firstElementChild);
  218.  
  219. Apply();
  220. }, 1000);
  221. return true;
  222. };
  223. TrySetup();
  224. })();

QingJ © 2025

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