Twitter/X Status to Embed Link Converter

Convert Twitter/X status links to embedded tweet links

  1. // ==UserScript==
  2. // @name Twitter/X Status to Embed Link Converter
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description Convert Twitter/X status links to embedded tweet links
  6. // @author w4t3r1ily
  7. // @match *://*/*
  8. // @include *
  9. // @grant none
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Function to create the new embed tweet link element with an arrow sign
  17. function createEmbedLink(tweetId) {
  18. const embedLink = document.createElement('a');
  19. embedLink.href = `https://platform.twitter.com/embed/Tweet.html?id=${tweetId}`; // Construct the embed URL using the tweet ID
  20. embedLink.textContent = `⇒ https://platform.twitter.com/embed/Tweet.html?id=${tweetId}`; // Set the text content of the link with an arrow sign
  21. return embedLink; // Return the newly created link element
  22. }
  23.  
  24. // Get all anchor elements on the page
  25. const links = document.querySelectorAll('a');
  26.  
  27. // Iterate over each link
  28. links.forEach(link => {
  29. // Match the URL against the specific Twitter/X status pattern and extract the tweet ID
  30. const match = link.href.match(/https:\/\/(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/);
  31. if (match) {
  32. const tweetId = match[1]; // Extract the tweet ID from the matched pattern
  33. const embedLink = createEmbedLink(tweetId); // Create an embed link using the extracted tweet ID
  34.  
  35. // Create a line break element
  36. const lineBreak = document.createElement('br');
  37.  
  38. // Insert the line break and then the new link below the original link
  39. link.insertAdjacentElement('afterend', lineBreak); // Insert the line break after the original link
  40. lineBreak.insertAdjacentElement('afterend', embedLink); // Insert the new embed link after the line break
  41. }
  42. });
  43. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址