/*
* @title TwitterユーザーID取得
* @description Twitterユーザーのscreen_nameからユーザーIDを取得する
* @include https://twitter.com/*
* @license MIT License
* @require
* @javascript_url
*/
( () => {
'use strict';
let screen_name = prompt( 'screen_name', '' );
if ( screen_name === null ) return;
fetch( 'https://api.twitter.com/1.1/users/show.json?screen_name=twitter', {
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',
} )
.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' );
}
navigator.clipboard.writeText( user_id )
.then( () => {
} )
.catch( error => {
console.error( 'copy result to the clipboard failre:', error );
} )
.finally( () => {
prompt( screen_name, user_id );
} );
} )
.catch( error => {
console.error( screen_name, error );
alert( '"' + screen_name + '" is not found: ' + error );
} );
} )();