// ==UserScript== // @name UTT // @license MIT // @namespace http://tampermonkey.net/ // @version 0.4 // @description Unroll the twitter thread // @author fabsOU // @match *://x.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com/ // @grant GM_xmlhttpRequest // @grant GM_openInTab // @grant window.onurlchange // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Your code here... var href = document.location.href; //alert('当前页面地址为:' + href); let url = href; let statusId = url.match(/status\/(\d+)/); if (statusId) { btn.style.display = 'block'; } else{ btn.style.display = 'none'; } if (window.onurlchange === null) { // feature is supported window.addEventListener('urlchange', (info) => { console.log("urlchange:",info); //alert(info.url) url = info.url statusId = url.match(/status\/(\d+)/); console.log(statusId) if (statusId) { btn.style.display = 'block'; }else{ btn.style.display = 'none'; } }); } const btn = document.createElement('div'); btn.innerHTML = ` `; btn.style.position = 'fixed'; btn.style.right = '650px'; btn.style.top = '15px'; btn.style.cursor = 'pointer'; btn.style.display = 'none'; document.body.appendChild(btn); btn.addEventListener('click', () => { //var href = document.location.href; //alert('当前页面地址为:' + href); //let url = href; // 使用正则表达式提取 status ID //let statusId = url.match(/status\/(\d+)/); // 生成 unroll page let unroll_url = "https://twitter-thread.com/api/unroll-thread?id=" + statusId[1]; console.log(unroll_url); GM_xmlhttpRequest({ responseType: 'json', url: unroll_url, onreadystatechange: (res) => { if (res.readyState === 4) { console.log(res.response.statusCode) if( 200 == res.response.statusCode){ let str = statusId[1]; console.log(`https://twitter-thread.com/api/unroll-thread/${str}`) GM_openInTab(`https:twitter-thread.com/t/${str}`, { active: true }); } } }, }) }); })();