X.com to Twitter.com Embedded Tweet in Voz

Replace x.com links with embedded tweets

当前为 2024-07-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name X.com to Twitter.com Embedded Tweet in Voz
  3. // @namespace Embedded Tweet in Voz
  4. // @version 1.3
  5. // @description Replace x.com links with embedded tweets
  6. // @icon https://www.google.com/s2/favicons?sz=64&domain=voz.vn
  7. // @author kylyte
  8. // @match https://voz.vn/t/*
  9. // @match https://voz.vn/conversations/*
  10. // @match https://voz.vn/whats-new/profile-posts/*
  11. // @match https://voz.vn/u/*
  12. // @run-at document-start
  13. // @license GPL-3.0
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. function replaceDivWithIframe() {
  19. const divs = document.querySelectorAll('div.bbCodeBlock--unfurl');
  20. divs.forEach(div => {
  21. const anchor = div.querySelector('a[href^="https://x.com"]');
  22. if (anchor) {
  23. const href = anchor.getAttribute('href');
  24. const postIdMatch = href.match(/status\/(\d+)/);
  25. if (postIdMatch && postIdMatch[1]) {
  26. const postId = postIdMatch[1];
  27. const iframe = document.createElement('iframe');
  28. iframe.id = "twitter-widget-0";
  29. iframe.scrolling = "no";
  30. iframe.frameBorder = "0";
  31. iframe.allowTransparency = "true";
  32. iframe.allowFullscreen = "true";
  33. iframe.style.position = "static";
  34. iframe.style.visibility = "visible";
  35. iframe.style.width = "550px";
  36. iframe.style.height = "1410px";
  37. iframe.style.display = "block";
  38. iframe.style.flexGrow = "1";
  39. iframe.title = "X Post";
  40. iframe.dataset.tweetId = postId;
  41. iframe.src = `https://platform.twitter.com/embed/Tweet.html?id=${postId}&width=550px`;
  42. div.parentNode.replaceChild(iframe, div);
  43. }
  44. }
  45. });
  46. }
  47.  
  48. window.addEventListener('load', replaceDivWithIframe);
  49. const observer = new MutationObserver(replaceDivWithIframe);
  50. observer.observe(document.body, { childList: true, subtree: true });
  51. })();