X.com to Twitter.com Embedded Tweet in Voz

Replace x.com links with embedded tweets

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

  1. // ==UserScript==
  2. // @name X.com to Twitter.com Embedded Tweet in Voz
  3. // @namespace Embedded Tweet in Voz
  4. // @version 2.0
  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-idle
  13. // @license GPL-3.0
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. function replaceDivWithBlockquote() {
  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 blockquote = document.createElement('blockquote');
  28. blockquote.className = "twitter-tweet";
  29. const link = document.createElement('a');
  30. link.href = `https://twitter.com/twitterapi/status/${postId}`;
  31. link.target = "_blank";
  32. link.textContent = `https://twitter.com/twitterapi/status/${postId}`;
  33. blockquote.appendChild(link);
  34. div.parentNode.replaceChild(blockquote, div);
  35. }
  36. }
  37. });
  38. }
  39.  
  40. window.addEventListener('load', replaceDivWithBlockquote);
  41. const observer = new MutationObserver(replaceDivWithBlockquote);
  42. observer.observe(document.body, { childList: true, subtree: true });
  43. })();