Skip to content

Instantly share code, notes, and snippets.

@ksasao
Last active August 31, 2025 04:52
Show Gist options
  • Save ksasao/f2121028b2a56d24eb7bdfcea3ec0f76 to your computer and use it in GitHub Desktop.
Save ksasao/f2121028b2a56d24eb7bdfcea3ec0f76 to your computer and use it in GitHub Desktop.
あるポストの±2日を表示するブックマークレット
<!doctype html>
<meta charset="utf-8">
<title>X ±2日 bookmarklet</title>
<style>
body { font: 16px/1.6 system-ui, sans-serif; padding: 24px; }
a.btn { display:inline-block; padding:10px 14px; border-radius:9999px;
text-decoration:none; border:1px solid #ccc }
code { background:#f6f8fa; padding:2px 6px; border-radius:6px }
</style>
<h1>「X ±2日」ブックマークレット</h1>
<p><a href="https://x.com/ksasao">@ksasao</a></p>
<p>
Xの特定のポストの前後2日のポストを表示するブックマークレットです。
</p>
<h2>1. ブックマークへの登録</h2>
<p>↓このボタンを <b>ブックマークバーへドラッグ</b> してください。</p>
<p>
<a class="btn" href="javascript:(()=>{try{const iso=(sel)=>document.querySelector(sel)?.getAttribute('datetime');const dtStr=iso('article time')||iso('time');if(!dtStr)throw new Error('日時が読めませんでした');const dt=new Date(dtStr);const path=location.pathname.split('/').filter(Boolean);const user=(path[0]||'').replace(/^@/,'');if(!user||!path.includes('status'))throw new Error('ステータスページではありません');const d=(n)=>{const t=new Date(dt);t.setDate(t.getDate()+n);const y=t.getUTCFullYear();const m=String(t.getUTCMonth()+1).padStart(2,'0');const da=String(t.getUTCDate()).padStart(2,'0');return `${y}-${m}-${da}`};const since=d(-2),until=d(3);const q=encodeURIComponent(`from:${user} since:${since} until:${until}`);const url=`https://x.com/search?q=${q}&src=typed_query&f=live`;open(url,'_blank');}catch(e){alert('X ±2日 検索に失敗: '+e.message)}})();">X ±2日</a>
</p>
<p>モバイルの方は下の<b>手動登録</b>を参照。</p>
<h3>手動登録(コピペ)</h3>
<ol>
<li>ブックマークを新規作成(名前はお好みで)。</li>
<li>URL欄に下のコードを貼り付けて保存:</li>
</ol>
<pre><code>javascript:(()=>{try{const iso=(sel)=>document.querySelector(sel)?.getAttribute('datetime');const dtStr=iso('article time')||iso('time');if(!dtStr)throw new Error('日時が読めませんでした');const dt=new Date(dtStr);const path=location.pathname.split('/').filter(Boolean);const user=(path[0]||'').replace(/^@/,'');if(!user||!path.includes('status'))throw new Error('ステータスページではありません');const d=(n)=>{const t=new Date(dt);t.setDate(t.getDate()+n);const y=t.getUTCFullYear();const m=String(t.getUTCMonth()+1).padStart(2,'0');const da=String(t.getUTCDate()).padStart(2,'0');return `${y}-${m}-${da}`};const since=d(-2),until=d(3);const q=encodeURIComponent(`from:${user} since:${since} until:${until}`);const url=`https://x.com/search?q=${q}&src=typed_query&f=live`;open(url,'_blank');}catch(e){alert('X ±2日 検索に失敗: '+e.message)}})();</code></pre>
<h2>2. 使い方</h2>
Xの特定のポストを表示した後、上で追加したブックマークをクリックしてください。
javascript:(()=>{try{const iso=(sel)=>document.querySelector(sel)?.getAttribute('datetime');const dtStr=iso('article time')||iso('time');if(!dtStr)throw new Error('日時が読めませんでした');const dt=new Date(dtStr);const path=location.pathname.split('/').filter(Boolean);const user=(path[0]||'').replace(/^@/,'');if(!user||!path.includes('status'))throw new Error('ステータスページではありません');const d=(n)=>{const t=new Date(dt);t.setDate(t.getDate()+n);const y=t.getUTCFullYear();const m=String(t.getUTCMonth()+1).padStart(2,'0');const da=String(t.getUTCDate()).padStart(2,'0');return `${y}-${m}-${da}`};const since=d(-2),until=d(3);const q=encodeURIComponent(`from:${user} since:${since} until:${until}`);const url=`https://x.com/search?q=${q}&src=typed_query&f=live`;open(url,'_blank');}catch(e){alert('X ±2日 検索に失敗: '+e.message)}})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment