Skip to content

JimLiu/baoyu-skills / skills/baoyu-danger-x-to-markdown

baoyu-danger-x-to-markdown

Verified

Converts X (Twitter) tweets and articles to markdown with YAML front matter. Uses reverse-engineered API requiring user consent. Use when user mentions "X to markdown", "tweet to markdown", "save tweet", or provides x.com/twitter.com URLs for conversion.

scripts/referenced-tweets.ts

View on GitHub
import { fetchXTweet } from "./graphql.js";
import {
  extractReferencedTweetIds,
  type ReferencedTweetInfo,
} from "./markdown.js";

type ResolveReferencedTweetsOptions = {
  log?: (message: string) => void;
};

function extractReferencedTweetInfo(tweet: any, fallbackTweetId: string): ReferencedTweetInfo {
  const userCore = tweet?.core?.user_results?.result?.core;
  const userLegacy = tweet?.core?.user_results?.result?.legacy;

  const authorName =
    typeof userCore?.name === "string"
      ? userCore.name
      : typeof userLegacy?.name === "string"
        ? userLegacy.name
        : undefined;

  const authorUsername =
    typeof userCore?.screen_name === "string"
      ? userCore.screen_name
      : typeof userLegacy?.screen_name === "string"
        ? userLegacy.screen_name
        : undefined;

  const text =
    tweet?.note_tweet?.note_tweet_results?.result?.text ??
    tweet?.legacy?.full_text ??
    tweet?.legacy?.text ??
    undefined;

  const tweetId =
    typeof tweet?.rest_id === "string" && tweet.rest_id.length > 0
      ? tweet.rest_id
      : fallbackTweetId;

  const url = authorUsername
    ? `https://x.com/${authorUsername}/status/${tweetId}`
    : `https://x.com/i/web/status/${tweetId}`;

  return {
    id: tweetId,
    url,
    authorName,
    authorUsername,
    text: typeof text === "string" ? text : undefined,
  };
}

export async function resolveReferencedTweetsFromArticle(
  article: unknown,
  cookieMap: Record<string, string>,
  options: ResolveReferencedTweetsOptions = {}
): Promise<Map<string, ReferencedTweetInfo>> {
  const log = options.log ?? (() => {});
  const ids = extractReferencedTweetIds(article);
  const referencedTweets = new Map<string, ReferencedTweetInfo>();

  for (const id of ids) {
    try {
      const tweet = await fetchXTweet(id, cookieMap, false);
      const info = extractReferencedTweetInfo(tweet, id);
      referencedTweets.set(id, info);
    } catch (error) {
      log(
        `[x-to-markdown] Failed to fetch referenced tweet ${id}: ${
          error instanceof Error ? error.message : String(error)
        }`
      );
      referencedTweets.set(id, {
        id,
        url: `https://x.com/i/web/status/${id}`,
      });
    }
  }

  return referencedTweets;
}
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 323kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 323kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 323kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 323kUpdated Claude CodeCodexVerifiedInstall