X.com to Twitter.com Embedded Tweet in Voz

Replace x.com links with embedded tweets

  1. // ==UserScript==
  2. // @name X.com to Twitter.com Embedded Tweet in Voz
  3. // @namespace Embedded Tweet in Voz
  4. // @version 2.1
  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 addTwitterWidgetsScript() {
  19. if (!document.querySelector('script[src="//platform.twitter.com/widgets.js"]')) {
  20. const script = document.createElement('script');
  21. script.src = "//platform.twitter.com/widgets.js";
  22. script.charset = "utf-8";
  23. document.head.appendChild(script);
  24. }
  25. }
  26. function replaceDivWithBlockquote() {
  27. const divs = document.querySelectorAll('div.bbCodeBlock--unfurl');
  28. divs.forEach(div => {
  29. const anchor = div.querySelector('a[href^="https://x.com"]');
  30. if (anchor) {
  31. const href = anchor.getAttribute('href');
  32. const postIdMatch = href.match(/status\/(\d+)/);
  33. if (postIdMatch && postIdMatch[1]) {
  34. const postId = postIdMatch[1];
  35. const blockquote = document.createElement('blockquote');
  36. blockquote.className = "twitter-tweet";
  37. const link = document.createElement('a');
  38. link.href = `https://twitter.com/twitterapi/status/${postId}`;
  39. link.target = "_blank";
  40. link.textContent = `https://twitter.com/twitterapi/status/${postId}`;
  41. blockquote.appendChild(link);
  42. div.parentNode.replaceChild(blockquote, div);
  43. addTwitterWidgetsScript();
  44. }
  45. }
  46. });
  47. }
  48.  
  49. window.addEventListener('load', replaceDivWithBlockquote);
  50. const observer = new MutationObserver(replaceDivWithBlockquote);
  51. observer.observe(document.body, { childList: true, subtree: true });
  52. })();