X Trans Flag Merger

Merge split transgender flag images into a single emoji on X.com

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         X Trans Flag Merger
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Merge split transgender flag images into a single emoji on X.com
// @author       Yumeka
// @match        https://twitter.com/*
// @match        https://x.com/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function () {
  'use strict';

  // SVG identifiers based on Twitter's Twemoji filenames
  // 1f3f3 = White Flag, 26a7 = Male with Stroke etc (Trans Symbol part)
  const SEL_FLAG = 'img[src*="1f3f3.svg"]';
  const SEL_SYMBOL = 'src*="26a7.svg"';

  let pendingFrame = null;

  function mergeFlags() {
    const flags = document.querySelectorAll(SEL_FLAG);

    for (const flag of flags) {
      // Check adjacent elements for the broken sequence
      // Sequence: [Flag Img] + [Span/Text (ZWJ)] + [Symbol Img]
      const spacer = flag.nextElementSibling;
      if (!spacer) continue;

      const symbol = spacer.nextElementSibling;
      if (!symbol || symbol.tagName !== 'IMG' || !symbol.src.includes('26a7')) continue;

      // Verify structure matches the split emoji pattern
      // Replace the entire sequence with the standard emoji
      const emojiNode = document.createTextNode('🏳️‍⚧️');

      // Insert emoji before the flag
      flag.parentNode.insertBefore(emojiNode, flag);

      // Remove the broken pieces
      flag.remove();
      spacer.remove();
      symbol.remove();
    }
    pendingFrame = null;
  }

  function scheduleMerge() {
    if (pendingFrame) return;
    pendingFrame = requestAnimationFrame(mergeFlags);
  }

  // Observe DOM changes to handle dynamic content loading
  const observer = new MutationObserver(scheduleMerge);
  observer.observe(document.body, { childList: true, subtree: true });

  // Initial run
  scheduleMerge();
})();