Last active
January 3, 2026 14:52
-
-
Save silver-mixer/ba6f5fb1e1eda9822988a56e2c9dceca to your computer and use it in GitHub Desktop.
[UserScript] Extract and display user unique id in twitter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Twitter User ID Extractor | |
| // @namespace https://estar-lab.net/ | |
| // @version 5.1 | |
| // @description ユーザの固有IDを抽出します。 | |
| // @author silver-mixer | |
| // @match https://x.com/* | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com | |
| // @grant none | |
| // ==/UserScript== | |
| (() => { | |
| 'use strict'; | |
| const userMap = new Map(); // <screen_name:string, userId:string> | |
| const updateUserIDElement = () => { | |
| const screenName = location.href.match(/x\.com\/([a-zA-Z0-9_]+)/)[1] ?? null; | |
| const userId = userMap.get(screenName) ?? null; | |
| if(screenName === null || userId === null){ | |
| console.log('failed to get screen_name or userId', screenName, userId); | |
| return; | |
| } | |
| const linkTag = document.getElementById('_tuie_link'); | |
| if(linkTag !== null){ | |
| console.log('update link'); | |
| linkTag.href = `https://x.com/intent/user?user_id=${userId}`; | |
| linkTag.textContent = `@${screenName} (${userId})`; | |
| }else{ | |
| console.log('create link'); | |
| const infoPane = document.querySelectorAll('.css-175oi2r.r-1adg3ll.r-6gpygo')[2]; | |
| infoPane.insertAdjacentHTML('beforeend', `<div><a id="_tuie_link" style="color: rgb(139, 152, 165);" href="https://x.com/intent/user?user_id=${userId}">@${screenName} (${userId})</a></div>`); | |
| } | |
| }; | |
| // Extract UserID from UserByScreenName | |
| const oXHROpen = XMLHttpRequest.prototype.open; | |
| XMLHttpRequest.prototype.open = function(){ | |
| const openURL = arguments[1]; | |
| if(/\/UserByScreenName/.test(openURL)){ | |
| this.addEventListener('load', () => { | |
| const data = JSON.parse(this.responseText); | |
| const screenName = data?.data?.user?.result?.core?.screen_name; | |
| const userId = data?.data?.user?.result?.rest_id; | |
| if(screenName !== null && userId !== null){ | |
| userMap.set(screenName, userId); | |
| updateUserIDElement(); | |
| } | |
| }); | |
| } | |
| oXHROpen.apply(this, arguments); | |
| }; | |
| const oPushState = history.pushState.bind(history); | |
| history.pushState = function(){ | |
| oPushState(...arguments); | |
| setTimeout(() => { | |
| updateUserIDElement(); | |
| }, 500); | |
| }; | |
| })(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Twitter User ID Extractor
簡易バージョン履歴