this repo has no description
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: dont set depth 0 post in thread view when applying writes

dusk 6f2f49e3 de5e0962

+54 -39
+33 -9
src/entrypoints/content.ts
··· 1 1 import { expect } from "@/lib/result"; 2 - import { Fronter, fronterGetSocialAppHref } from "@/lib/utils"; 2 + import { 3 + Fronter, 4 + fronterGetSocialAppHref, 5 + parseSocialAppPostUrl, 6 + } from "@/lib/utils"; 3 7 import { parseResourceUri, ResourceUri } from "@atcute/lexicons"; 4 8 5 9 const getAuthHeader = (headers: any): string | null => { ··· 113 117 el.setAttribute("data-fronter", s); 114 118 }; 115 119 const applyFrontersToPage = (fronters: Map<string, any>) => { 120 + // console.log("applyFrontersToPage", fronters); 121 + const match = parseSocialAppPostUrl(document.URL); 116 122 for (const el of document.getElementsByTagName("a")) { 117 123 const path = `/${el.href.split("/").slice(3).join("/")}`; 118 124 const fronter = fronters.get(path); 119 125 if (!fronter) continue; 120 126 const isFocusedPost = fronter.depth === 0; 127 + if (isFocusedPost && match && match.rkey !== fronter.rkey) continue; 121 128 if (isFocusedPost && el.ariaLabel !== fronter.displayName) continue; 122 129 const displayNameElement = isFocusedPost 123 130 ? (el.firstElementChild?.firstElementChild?.firstElementChild ··· 125 132 : (el.parentElement?.firstElementChild?.firstElementChild 126 133 ?.firstElementChild?.firstElementChild ?? null); 127 134 if (!displayNameElement) continue; 135 + // console.log(path, fronter, displayNameElement); 128 136 applyFronterName(displayNameElement, fronter.names); 129 137 } 130 138 }; 139 + let postTabObserver: MutationObserver | null = null; 131 140 window.addEventListener("message", (event) => { 132 141 if (event.data.type !== "CACHED_FRONTERS") return; 133 - const fronters = event.data.fronters as Map<string, Fronter | null>; 134 - const updated = new Map( 135 - fronters.entries().flatMap(([uri, fronter]) => { 136 - if (!fronter) return []; 137 - const rkey = expect(parseResourceUri(uri)).rkey!; 138 - return [[fronterGetSocialAppHref(fronter, rkey), fronter]]; 139 - }), 142 + const applyFronters = () => { 143 + const fronters = event.data.fronters as Map<string, Fronter | null>; 144 + const updated = new Map( 145 + fronters.entries().flatMap(([uri, fronter]) => { 146 + if (!fronter) return []; 147 + const rkey = expect(parseResourceUri(uri)).rkey!; 148 + return [[fronterGetSocialAppHref(fronter, rkey), fronter]]; 149 + }), 150 + ); 151 + applyFrontersToPage(updated); 152 + }; 153 + // check if we are on profile so we can update fronters if the post tab is clicked on 154 + const postTabElement = document.querySelector( 155 + '[data-testid="profilePager-Posts"]', 140 156 ); 141 - applyFrontersToPage(updated); 157 + if (postTabElement) { 158 + postTabObserver = new MutationObserver(applyFronters); 159 + postTabObserver.observe(postTabElement, { attributes: true }); 160 + } else if (postTabObserver) { 161 + postTabObserver.disconnect(); 162 + postTabObserver = null; 163 + } 164 + // update fronters on page 165 + applyFronters(); 142 166 }); 143 167 window.addEventListener("message", (event) => { 144 168 if (!["TIMELINE_FRONTER", "THREAD_FRONTER"].includes(event.data.type))
+3 -20
src/entrypoints/isolated.content.ts
··· 1 - import { Fronter } from "@/lib/utils"; 1 + import { Fronter, parseSocialAppPostUrl } from "@/lib/utils"; 2 2 import { ResourceUri } from "@atcute/lexicons"; 3 3 4 4 export default defineContentScript({ ··· 10 10 11 11 const checkFronter = (url: string) => { 12 12 // match https://*/profile/<actor_identifier>/post/<rkey> regex with named params to extract actor_identifier and rkey 13 - const match = url.match( 14 - /https:\/\/[^/]+\/profile\/([^/]+)\/post\/([^/]+)/, 15 - ); 13 + const match = parseSocialAppPostUrl(url); 16 14 if (!match) return false; 17 - const [website, actorIdentifier, rkey] = match; 18 15 const recordUri = 19 - `at://${actorIdentifier}/app.bsky.feed.post/${rkey}` as ResourceUri; 16 + `at://${match.actorIdentifier}/app.bsky.feed.post/${match.rkey}` as ResourceUri; 20 17 const fronter = fronters.get(recordUri); 21 18 if (!fronter) return false; 22 19 browser.runtime.sendMessage({ ··· 49 46 } 50 47 window.postMessage(message); 51 48 }); 52 - let postTabObserver: MutationObserver | null = null; 53 49 ctx.addEventListener(window, "wxt:locationchange", (event) => { 54 50 window.postMessage({ type: "CACHED_FRONTERS", fronters }); 55 - // check if we are on profile so we can update fronters if the post tab is clicked on 56 - const postTabElement = document.querySelector( 57 - '[data-testid="profilePager-Posts"]', 58 - ); 59 - if (postTabElement) { 60 - postTabObserver = new MutationObserver(() => { 61 - window.postMessage({ type: "CACHED_FRONTERS", fronters }); 62 - }); 63 - postTabObserver.observe(postTabElement, { attributes: true }); 64 - } else if (postTabObserver) { 65 - postTabObserver.disconnect(); 66 - postTabObserver = null; 67 - } 68 51 // check for tab fronter for the current "post" 69 52 checkFronter(event.newUrl.toString()); 70 53 });
+18 -10
src/lib/utils.ts
··· 33 33 did: AtprotoDid; 34 34 }; 35 35 36 - export const fronterGetSocialAppHref = ( 37 - fronter: Fronter, 38 - rkey: RecordKey, 39 - depth?: number, 40 - ) => { 41 - return depth === 0 42 - ? `/profile/${fronter.handle ?? fronter.did}` 43 - : `/profile/${fronter.handle ?? fronter.did}/post/${rkey}`; 44 - }; 45 - 46 36 const fronterSchema = v.record( 47 37 v.string(), 48 38 v.object({ ··· 274 264 systemId: fronter.content.uid, 275 265 })); 276 266 }; 267 + 268 + export const fronterGetSocialAppHref = ( 269 + fronter: Fronter, 270 + rkey: RecordKey, 271 + depth?: number, 272 + ) => { 273 + // console.log("fronterGetSocialAppHref", fronter, rkey, depth); 274 + return depth === 0 275 + ? `/profile/${fronter.handle ?? fronter.did}` 276 + : `/profile/${fronter.handle ?? fronter.did}/post/${rkey}`; 277 + }; 278 + 279 + export const parseSocialAppPostUrl = (url: string) => { 280 + const match = url.match(/https:\/\/[^/]+\/profile\/([^/]+)\/post\/([^/]+)/); 281 + if (!match) return; 282 + const [website, actorIdentifier, rkey] = match; 283 + return { actorIdentifier, rkey }; 284 + };