/*
* @title メディア検索画面に遷移
* @description Twitter(X)のユーザープロフィールからメディア検索画面に遷移する
* @include https://twitter.com/*
* @include https://x.com/*
* @license MIT License
* @javascript_url
*/
(() => {
'use strict';
const
media_tab = document.querySelector('[role="presentation"] a[href$="/media"][role="tab"]');
if (! media_tab) {
return;
}
const
username = media_tab.href.match(/([^/]*)\/media$/)[1],
query = `from:${username} (filter:media OR card_name:animated_gif)`,
search_url = `/search?q=${encodeURIComponent(query)}&src=typed_query&f=live`,
url_object = new URL(search_url, location.href);
try {
const
previous_url_object = new URL(location.href),
state = {
key: 'r80bpk',
state: {
fromApp: true,
previousPath: previous_url_object.pathname + previous_url_object.search,
},
},
pop_state_event = new PopStateEvent('popstate', {state: state});
history.pushState(state, '', url_object.pathname + url_object.search);
dispatchEvent(pop_state_event);
}
catch (error) {
location.href = search_url;
}
})();