( () => {
'use strict';
const
fetch_api = ( api_url ) => {
return fetch( api_url, {
method: 'GET',
headers: {
'authorization' : 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
'x-csrf-token' : document.cookie.match( /ct0=(.*?)(?:;|$)/ )[ 1 ],
'x-twitter-active-user' : 'yes',
'x-twitter-auth-type' : 'OAuth2Session',
'x-twitter-client-language' : 'en',
},
mode: 'cors',
credentials : 'include',
} );
};
let screen_name = ( document.title.match( /\(@(.+)\)/ ) || [] )[ 1 ] || prompt( 'Input screen name of user', '' );
if ( screen_name === null ) return;
screen_name = screen_name.trim().replace( /^@/, '' );
if ( ! screen_name ) return;
fetch_api( 'https://api.twitter.com/1.1/users/show.json?screen_name=' + encodeURIComponent( screen_name ) )
.then( response => {
if ( ! response.ok ) {
throw new Error( 'Network response was not ok' );
}
return response.json()
} )
.then( user_info => {
let user_id = user_info.id_str;
if ( ! user_id ) {
throw new Error( 'Response does not include the ID of the user' );
}
fetch_api( 'https://api.twitter.com/fleets/v1/user_fleets?user_id=' + encodeURIComponent( user_id ) )
.then( response => {
if ( ! response.ok ) {
throw new Error( 'Network response was not ok' );
}
return response.json()
} )
.then( fleet_info => {
try {
let fleets = fleet_info.fleet_threads[ 0 ].fleets;
if ( fleets.length < 1 ) {
throw new Error( 'no fleet' );
}
fleets.map( fleet => {
window.open( fleet.media_entity.media_url_https );
} );
}
catch ( error ) {
alert( 'No fleet found.' );
}
} )
.catch( error => {
console.error( screen_name, error );
alert( 'Fleet information of "' + screen_name + '" is not found: ' + error );
} );
} )
.catch( error => {
console.error( screen_name, error );
alert( '"' + screen_name + '" is not found: ' + error );
} );
} )();