UTT

Unroll the twitter thread

  1. // ==UserScript==
  2. // @name UTT
  3. // @license MIT
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.4
  6. // @description Unroll the twitter thread
  7. // @author fabsOU
  8. // @match *://x.com/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com/
  10. // @grant GM_xmlhttpRequest
  11. // @grant GM_openInTab
  12. // @grant window.onurlchange
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Your code here...
  19.  
  20. var href = document.location.href;
  21. //alert('当前页面地址为:' + href);
  22. let url = href;
  23. let statusId = url.match(/status\/(\d+)/);
  24. if (statusId) {
  25. btn.style.display = 'block';
  26. }
  27. else{
  28. btn.style.display = 'none';
  29. }
  30.  
  31.  
  32.  
  33. if (window.onurlchange === null) {
  34. // feature is supported
  35. window.addEventListener('urlchange', (info) => {
  36. console.log("urlchange:",info);
  37. //alert(info.url)
  38. url = info.url
  39. statusId = url.match(/status\/(\d+)/);
  40. console.log(statusId)
  41. if (statusId) {
  42. btn.style.display = 'block';
  43. }else{
  44. btn.style.display = 'none';
  45. }
  46.  
  47.  
  48.  
  49. });
  50. }
  51.  
  52. const btn = document.createElement('div');
  53.  
  54. btn.innerHTML = `<?xml version="1.0" encoding="UTF-8"?>
  55. <svg width="48" height="48" clip-rule="evenodd" fill-rule="evenodd" image-rendering="optimizeQuality" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" version="1.1" viewBox="0 0 9144 9144" xmlns="http://www.w3.org/2000/svg">
  56. <defs>
  57. <style type="text/css">.fil1 {fill:white;fill-rule:nonzero} .fil0 {fill:url(#a)}</style>
  58. <linearGradient id="a" x1="8595.4" x2="548.64" y1="8595.4" y2="548.63" gradientUnits="userSpaceOnUse">
  59. <stop stop-color="#48CFAE" offset="0"/>
  60. <stop stop-color="#4FC0E8" offset="1"/>
  61. </linearGradient>
  62. </defs>
  63. <polygon class="fil0" points="0 0 9144 0 9144 9144 0 9144"/>
  64. <path class="fil1" d="m4523 3967h-456c-6 0-12 0-17-1-335-40-642-166-898-316-300-175-535-393-670-543-17 84-22 194-5 318 21 158 79 337 194 516 5 9 9 15 13 20 13 17 22 29 28 52 22 85-6 110-108 137l-4 1c-49 12-107 17-166 13h-7c32 106 83 214 151 319 98 151 231 296 391 424l2 2c5 3 10 7 14 10 25 18 41 29 50 66 21 87-11 103-99 125-59 14-117 21-170 21h-7c35 56 89 119 153 183 173 173 407 338 536 407l18 9c47 23 71 34 71 96v1c-1 51-20 65-60 94l-18 13c-211 157-454 239-684 281-79 15-156 24-229 31 223 97 448 166 671 208 566 105 1119 36 1602-187s897-599 1184-1107c166-294 290-633 361-1012 99-533 126-562 344-799l52-56h-143c-51 0-93-42-93-94 0-18 5-35 14-49l155-245c-133 20-238 28-324 27-137-1-226-24-292-59-7-4-13-9-19-14-192-143-388-211-570-217-170-6-329 42-462 130-133 89-240 218-306 376-75 180-96 397-42 631v4c2 7 6 19 8 29l1 4c13 49 19 75-17 116-33 38-59 37-111 35h-36zm-452-187h416c-51-259-24-500 61-703 80-193 211-351 375-460s361-168 571-161c218 7 451 86 675 254 42 21 103 35 201 36 113 1 271-17 497-61v1c22-5 46-1 67 12 44 28 57 85 29 129l-177 280h175c23-1 47 6 66 22 39 34 43 93 10 132-79 92-141 160-192 215-186 202-208 226-298 706-74 399-206 757-382 1069-307 544-750 947-1268 1185-517 239-1109 314-1714 201-347-65-698-192-1042-385-33-14-56-47-56-85 0-52 42-94 93-94 152 0 355-3 564-41 179-33 365-92 532-197-144-90-342-237-494-390-138-138-242-286-248-414-1-10 0-21 3-32 13-50 64-80 113-67 21 6 48 10 78 12-120-112-223-234-304-359-112-173-184-353-210-529-2-15-1-32 5-48 19-47 74-71 121-52 32 13 69 20 107 22 10 0 20 1 30 1-106-184-161-366-183-529-33-245 10-453 72-562 15-29 44-49 78-52 52-3 96 36 99 88 2 26 277 316 704 565 238 138 520 255 826 291z"/>
  65. </svg>`;
  66. btn.style.position = 'fixed';
  67. btn.style.right = '650px';
  68. btn.style.top = '15px';
  69.  
  70. btn.style.cursor = 'pointer';
  71.  
  72. btn.style.display = 'none';
  73.  
  74.  
  75.  
  76. document.body.appendChild(btn);
  77.  
  78.  
  79.  
  80. btn.addEventListener('click', () => {
  81. //var href = document.location.href;
  82. //alert('当前页面地址为:' + href);
  83. //let url = href;
  84. // 使用正则表达式提取 status ID
  85. //let statusId = url.match(/status\/(\d+)/);
  86. // 生成 unroll page
  87. let unroll_url = "https://twitter-thread.com/api/unroll-thread?id=" + statusId[1];
  88. console.log(unroll_url);
  89.  
  90. GM_xmlhttpRequest({
  91. responseType: 'json',
  92. url: unroll_url,
  93. onreadystatechange: (res) => {
  94. if (res.readyState === 4) {
  95. console.log(res.response.statusCode)
  96. if( 200 == res.response.statusCode){
  97. let str = statusId[1];
  98. console.log(`https://twitter-thread.com/api/unroll-thread/${str}`)
  99. GM_openInTab(`https:twitter-thread.com/t/${str}`, { active: true });
  100. }
  101. }
  102. },
  103. })
  104.  
  105.  
  106. });
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117. })();