Skip to content

Instantly share code, notes, and snippets.

@ryuya0124
Last active November 23, 2025 08:28
Show Gist options
  • Select an option

  • Save ryuya0124/e6e59ceba8f03bf40f3b5accedc52e44 to your computer and use it in GitHub Desktop.

Select an option

Save ryuya0124/e6e59ceba8f03bf40f3b5accedc52e44 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Open X(Twitter) App
// @version 1.1.1
// @author ryuya
// @match https://x.com/*
// @downloadURL https://gist.github.com/ryuya0124/e6e59ceba8f03bf40f3b5accedc52e44/raw/Open%2520X(Twitter)%2520App.user.js
// @updateURL https://gist.github.com/ryuya0124/e6e59ceba8f03bf40f3b5accedc52e44/raw/Open%2520X(Twitter)%2520App.user.js
// @homepage https://gist.github.com/ryuya0124/e6e59ceba8f03bf40f3b5accedc52e44
// ==/UserScript==
const currentPath = window.location.pathname;
const currentSearch = window.location.search;
const timelinePaths = [
'/home',
'/i/communitynotes',
'/i/verified-orgs-signup',
];
const includePaths = ['/list'];
if (currentPath === '/i/timeline' || currentPath.startsWith('/notifications')) {
window.location.href = 'twitter://mentions';
} else if (currentPath === '/i/grok'){
window.location.href = 'twitter://grok';
} else if (timelinePaths.some(path => currentPath.startsWith(path)) || includePaths.some(path => currentPath.includes(path))) {
window.location.href = 'twitter://timeline';
} else if (currentPath === '/messages') {
window.location.href = 'twitter://messages';
} else if (currentPath.startsWith('/messages/')) {
const conversationId = currentPath.match(/\/messages\/([^/]+)/)[1];
window.location.href = `twitter://messages?id=${conversationId}`;
} else if (currentPath.match(/\/status\/\d+$/)) {
const statusId = currentPath.match(/\/status\/(\d+)/)[1];
window.location.href = `twitter://status?id=${statusId}`;
} else if (currentPath === '/compose/tweet' || currentPath === '/compose/post') {
window.location.href = 'twitter://post?message';
} else if (currentPath === '/intent/tweet' || currentPath === '/intent/post') {
// 'text=', 'url=', 'hashtags=' を取り除き、hashtags を %23 に置換
const param = currentSearch
.replace('?text=', '') // 'text=' を取り除く
.replace('&url=', '') // 'url=' を取り除く
.replace('&hashtags=', '%23'); // 'hashtags=' を %23 に置換
// messageUrl を生成
const messageUrl = `twitter://post?message=${param}`;
// 結果を表示して、リンク先にリダイレクト
alert(messageUrl);
window.location.href = messageUrl;
} else if (currentPath === '/explore') {
window.location.href = 'twitter://explore';
} else if (currentPath === '/search' && currentSearch.includes('?q=')) {
const searchTerm = currentSearch.match(/q=(.*?)&/)[1];
window.location.href = `twitter://search?query=${searchTerm}`;
} else if (currentPath.startsWith('/i/bookmarks')) {
window.location.href = 'twitter://bookmarks';
} else if (currentPath.includes('/communities')) {
const communityIdMatch = currentPath.match(/\/communities\/([^/]+)/);
const communityId = communityIdMatch ? communityIdMatch[1] : '';
window.location.href = `twitter://communities/${communityId}`;
} else if (currentPath.startsWith('/') && currentPath != '/oauth/authorize') {
const screenName = currentPath.match(/\/([^/]+)/)[1];
window.location.href = `twitter://user?screen_name=${encodeURIComponent(screenName)}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment