Xで特定日の自分の投稿だけを見る方法

HTML,JavaScript,SNS管理,Twitter運用,Web小物,X運用,スクリプト,ミニツール,ローカルツール,作業効率化,備忘録,投稿管理,日付検索,検索クエリ

Xで特定日の自分の投稿だけを一覧したい。しかも簡単に。

Xの検索はUTC基準のため、JSTで日付を指定しても対象日の投稿が1件抜けることがある。そこで、指定日の前日〜翌日を含めて検索パラメータを自動生成し、指定日(JST)の投稿だけを確実に一覧できるようにするための簡易ツールを用意した。

ローカルで使える1クリック検索ツール

以下のHTMLを保存し、ブラウザで開いて日付を選択 。ログイン済みなら即検索画面へ移動する。

「const user = “your_id";」の your_id は @ を除いた自分のXユーザー名に置き換え。(例:@hideto → hideto)

<!DOCTYPE html>
<html>
<body>
<input type="date" id="dateInput">
<button onclick="go()">Search</button>

<script>
function go() {
  const user = "your_id";
  const d = new Date(document.getElementById("dateInput").value);
  if (!d) return;

  const since = new Date(d);
  since.setDate(since.getDate() - 1);

  const until = new Date(d);
  until.setDate(until.getDate() + 1);

  const fmt = x => x.toISOString().slice(0,10);

  const url = `https://x.com/search?q=from:${user}%20since:${fmt(since)}%20until:${fmt(until)}`;
  location.href = url;
}
</script>
</body>
</html>