Something went wrong. Try again.
this post sux
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114/* * sux page-world interceptor — runs in the bsky.app page context (injected by the * content script, declared web_accessible in the manifest). Wraps window.fetch, * parses Bluesky xrpc feed responses, and postMessages the extracted posts to the * content script. Everything is best-effort: a failure here must never break the page. */(function () { "use strict"; if (window.__suxInterceptor) return; window.__suxInterceptor = true;
var FEED_METHODS = [ "app.bsky.feed.getTimeline", "app.bsky.feed.getAuthorFeed", "app.bsky.feed.getFeed", "app.bsky.feed.searchPosts", "app.bsky.feed.getPostThread", ];
function matchedMethod(url) { if (typeof url !== "string" || url.indexOf("/xrpc/") === -1) return null; for (var i = 0; i < FEED_METHODS.length; i++) { if (url.indexOf(FEED_METHODS[i]) !== -1) return FEED_METHODS[i]; } return null; }
// Pull alt text out of an embed record wherever it lives (images, external...). function altOf(record) { try { var embed = record && record.embed; if (!embed) return ""; var parts = []; (function walk(node) { if (!node || typeof node !== "object") return; if (typeof node.alt === "string" && node.alt) parts.push(node.alt); for (var k in node) { if (node[k] && typeof node[k] === "object") walk(node[k]); } })(embed); return parts.join("\n"); } catch (e) { return ""; } }
function fromPostView(pv) { if (!pv || !pv.uri || !pv.record) return null; return { id: pv.uri, did: (pv.author && pv.author.did) || "", handle: (pv.author && pv.author.handle) || "", text: typeof pv.record.text === "string" ? pv.record.text : "", alt: altOf(pv.record), }; }
function extract(method, json) { var out = []; function pushItem(item) { var p = fromPostView(item && item.post ? item.post : item); if (p) out.push(p); } if (method === "app.bsky.feed.searchPosts") { (json.posts || []).forEach(pushItem); } else if (method === "app.bsky.feed.getPostThread") { (function walk(node) { if (!node || typeof node !== "object") return; var p = fromPostView(node.post); if (p) out.push(p); (node.replies || []).forEach(walk); walk(node.parent); })(json.thread); } else { (json.feed || []).forEach(pushItem); } var seen = {}; return out.filter(function (p) { if (seen[p.id]) return false; seen[p.id] = true; return true; }); }
function emit(posts, method) { console.debug("[sux] intercepted " + method + " → " + posts.length + " posts"); if (posts.length) { window.postMessage({ source: "sux-interceptor", posts: posts }, "*"); } }
var originalFetch = window.fetch; window.fetch = function (input, init) { var url = typeof input === "string" ? input : (input && input.url) || ""; var method = matchedMethod(url); var promise = originalFetch.apply(this, arguments); if (!method) return promise; return promise.then(function (response) { try { response .clone() .json() .then(function (json) { try { emit(extract(method, json || {}), method); } catch (e) { /* ignore */ } }) .catch(function () { /* non-JSON or already consumed — ignore */ }); } catch (e) { /* ignore */ } return response; }); };})();