Skip to content

Instantly share code, notes, and snippets.

@lyo
Last active August 5, 2025 16:00
Show Gist options
  • Select an option

  • Save lyo/310aca8bbcad6c1efb5e289a9772d83c to your computer and use it in GitHub Desktop.

Select an option

Save lyo/310aca8bbcad6c1efb5e289a9772d83c to your computer and use it in GitHub Desktop.
X archiveのログ検索にて、投稿日リンクをクリックするとその日postしたのに絞るやつ
/*
* This script is provided for personal use only and must be used in compliance with X's Terms of Service
* (https://x.com/en/tos) and Developer Agreement (https://developer.x.com/en/developer-terms).
* Do not share, publish, or use X archive data for commercial purposes.
*/
(function() {
// タイム日付のリンクを押したときだけ処理する
document.addEventListener("click", function(e) {
const target = e.target.closest("a.Tweet-timestamp");
if (target) {
e.preventDefault(); // ← リンク先に飛ぶのをやめる
const rawDateStr = target.textContent.trim();
const convertedDate = convertJapaneseDateToISO(rawDateStr);
updateHash(convertedDate)
}
});
// 日本語日付を yyyy-mm-dd に変換
function convertJapaneseDateToISO(japaneseDateStr) {
const datePattern = /(\d{4})年(\d{1,2})月(\d{1,2})日/;
const match = japaneseDateStr.match(datePattern);
if (!match) return null;
const year = match[1];
const month = match[2].padStart(2, '0');
const day = match[3].padStart(2, '0');
return `${year}-${month}-${day}`;
}
//翌日をyyyy-mm-ddで取得
function getNextDay(dateStr) {
const date = new Date(dateStr);
date.setDate(date.getDate() + 1);
return date.toISOString().slice(0, 10); // "YYYY-MM-DD"
}
// URL欄の更新
function updateHash(newSinceDateStr) {
// 翌日を自動計算
const newUntilDateStr = getNextDay(newSinceDateStr);
// 現在のハッシュを取得
let currentHash = window.location.hash;
// URLSearchParamsを使うために、疑似的に '?' 部分から取得
const queryPart = currentHash.split("?")[1];
const searchParams = new URLSearchParams(queryPart);
// 不要な 'q' を削除
searchParams.delete("q");
// 'since' を新しい日付に更新
searchParams.set("since", newSinceDateStr);
// 'until' を翌日に更新
searchParams.set("until", newUntilDateStr);
// 新しいハッシュを組み立て
const basePath = currentHash.split("?")[0]; // 例: "#/tweets/tweets"
const newHash = `${basePath}?${searchParams.toString()}`;
// 更新
window.location.hash = newHash;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment