Country Flag Fixer

Αντικαθιστά αυτόματα τους μυστηριώδεις κωδικούς χωρών με την αντίστοιχη σημαία. Η λύση για τους χρήστες του Chromium στα Windows!

  1. // ==UserScript==
  2. // @name Country Flag Fixer
  3. // @namespace https://github.com/matthijs110/chromium-country-flags/
  4. // @version 1.2.5
  5. // @license MIT
  6. // @description Replaces mysterious country codes automatically with the corresponding flag. The solution for Chromium users on Windows!
  7. // @description:ar يستبدل رموز البلد الغامضة تلقائيًا بالعلم المقابل. الحل لمستخدمي Chromium على Windows!
  8. // @description:bg Заменя автоматично мистериозните кодове на страните със съответния флаг. Решението за потребителите на Chromium в Windows!
  9. // @description:cs Automaticky nahradí záhadné kódy zemí odpovídající vlajkou. Řešení pro uživatele Chromu v systému Windows!
  10. // @description:da Erstatter automatisk mystiske landekoder med det tilsvarende flag. Løsningen for Chromium-brugere på Windows!
  11. // @description:de Ersetzt mysteriöse Ländercodes automatisch durch die entsprechende Flagge. Die Lösung für Chromium-Nutzer unter Windows!
  12. // @description:el Αντικαθιστά αυτόματα τους μυστηριώδεις κωδικούς χωρών με την αντίστοιχη σημαία. Η λύση για τους χρήστες του Chromium στα Windows!
  13. // @description:en-GB Replaces mysterious country codes automatically with the corresponding flag. The solution for Chromium users on Windows!
  14. // @description:es Sustituye automáticamente los códigos de país misteriosos por la bandera correspondiente. ¡La solución para los usuarios de Chromium en Windows!
  15. // @description:et Asendab salapärased riigikoodid automaatselt vastava lipuga. Lahendus Chromiumi kasutajatele Windowsis!
  16. // @description:fi Korvaa salaperäiset maakoodit automaattisesti vastaavalla lipulla. Ratkaisu Chromiumin käyttäjille Windowsissa!
  17. // @description:fr Remplace automatiquement les codes pays mystérieux par le drapeau correspondant. La solution pour les utilisateurs de Chromium sur Windows!
  18. // @description:he מחליף אוטומטית את קודי המדינה המסתוריים בדגל המתאים. הפתרון למשתמשי Chromium ב-Windows!
  19. // @description:hi रहस्यमय देश कोड को स्वचालित रूप से संबंधित ध्वज के साथ बदल देता है। विंडोज़ पर क्रोमियम उपयोगकर्ताओं के लिए समाधान!
  20. // @description:hu A rejtélyes országkódokat automatikusan helyettesíti a megfelelő zászlóval. A megoldás a Chromium felhasználók számára Windowson!
  21. // @description:id Mengganti kode negara misterius secara otomatis dengan bendera yang sesuai. Solusi untuk pengguna Chromium di Windows!
  22. // @description:it Sostituisce automaticamente i codici paese misteriosi con la bandiera corrispondente. La soluzione per gli utenti di Chromium su Windows!
  23. // @description:ja 謎の国番号を対応する国旗に自動的に置き換える。WindowsのChromiumユーザーのためのソリューション!
  24. // @description:ko 신비한 국가 코드를 해당 플래그로 자동 교체합니다. Windows의 Chromium 사용자를 위한 솔루션!
  25. // @description:lv Paslaptingus šalių kodus automatiškai pakeičia atitinkama vėliava. Sprendimas \"Chromium\" naudotojams \"Windows\" sistemoje!
  26. // @description:nl Vervangt mysterieuze landcodes automatisch door de overeenkomstige vlag. De oplossing voor Chromium gebruikers op Windows!
  27. // @description:no Erstatter mystiske landskoder automatisk med det tilsvarende flagget. Løsningen for Chromium-brukere på Windows!
  28. // @description:pl Automatycznie zastępuje tajemnicze kody krajów odpowiednią flagą. Rozwiązanie dla użytkowników Chromium w systemie Windows!
  29. // @description:pt-BR Substitui automaticamente os códigos misteriosos dos países pela bandeira correspondente. A solução para usuários do Chromium no Windows!
  30. // @description:pt-PT Substitui automaticamente os misteriosos códigos de países pela bandeira correspondente. A solução para os utilizadores de Crómio no Windows!
  31. // @description:ro Înlocuiește automat codurile de țară misterioase cu steagul corespunzător. Soluția pentru utilizatorii Chromium pe Windows!
  32. // @description:ru Автоматически заменяет загадочные коды стран на соответствующий флаг. Решение для пользователей Chromium под Windows!
  33. // @description:sk Záhadné kódy krajín automaticky nahradí príslušnou vlajkou. Riešenie pre používateľov Chromium v systéme Windows!
  34. // @description:sl Skrivnostne kode držav samodejno zamenja z ustrezno zastavo. Rešitev za uporabnike programa Chromium v operacijskem sistemu Windows!
  35. // @description:sv Ersätter mystiska landkoder automatiskt med motsvarande flagga. Lösningen för Chromium-användare i Windows!
  36. // @description:tr Gizemli ülke kodlarını otomatik olarak ilgili bayrakla değiştirir. Windows'ta Chromium kullanıcıları için çözüm!
  37. // @description:uk Автоматично замінює загадкові коди країн на відповідний прапор. Рішення для користувачів Chromium у Windows!
  38. // @description:vi Tự động thay thế mã quốc gia bí ẩn bằng cờ tương ứng. Giải pháp cho người dùng Chromium trên Windows!
  39. // @description:zh-CN 将神秘的国家代码自动替换为相应的国旗。为Windows上的Chromium用户提供解决方案!
  40. // @description:zh-TW 將神秘的國家代碼自動替換為相應的國旗。為Windows上的Chromium使用者提供解決方案!
  41. // @author matthijs110
  42. // @match *://*/*
  43. // @icon https://cdn.jsdelivr.net/gh/matthijs110/chromium-country-flags/src/assets/icons/icon48.png
  44. // @run-at document-start
  45. // ==/UserScript==
  46.  
  47. (function() {
  48. 'use strict';
  49.  
  50. // Source: https://github.com/talkjs/country-flag-emoji-polyfill
  51. const replacementFontName = "Twemoji Country Flags";
  52.  
  53. // Some elements can be ignored.
  54. const ignoredElements = ["style", "script", "svg"];
  55.  
  56. /**
  57. * Update all children of the given node.
  58. */
  59. const updateChildNodes = (startingPointNode) =>
  60. {
  61. startingPointNode.querySelectorAll('*').forEach((childNode) =>
  62. {
  63. const tagName = childNode.tagName.toLowerCase();
  64. if (ignoredElements.includes(tagName))
  65. return;
  66.  
  67. // Match any emoji within the Unicode range
  68. const regex = /[\uD83C][\uDDE6-\uDDFF][\uD83C][\uDDE6-\uDDFF]|[\uD83C]\uDDEC[\uD83C][\uDDA7\uDDAC\uDDA9\uDDAF\uDDA8\uDDB3\uDDB4]|\u200D?\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDCA7?\uFE0F?/g;
  69. const matches = childNode.innerHTML.match(regex);
  70. if (matches)
  71. {
  72. // Get the original fonts to append later as fallback
  73. const originalFont = window.getComputedStyle(childNode, null).fontFamily;
  74.  
  75. // Prevent any duplicated
  76. if (originalFont.toLowerCase().includes(replacementFontName.toLowerCase()))
  77. return;
  78.  
  79. // Override the font
  80. childNode.style.fontFamily = `${replacementFontName}, ${originalFont}`;
  81. }
  82. });
  83. }
  84.  
  85. /**
  86. * Observe the document for updated elements (e.g. scroll loading).
  87. */
  88. let observer = new MutationObserver(mutations =>
  89. {
  90. for (let mutation of mutations)
  91. {
  92. for (let addedNode of mutation.addedNodes)
  93. {
  94. if (addedNode != null && addedNode.tagName != null)
  95. {
  96. // Prevent searching within the ignored elements like SVG
  97. const tagName = addedNode.tagName.toLowerCase();
  98. if (ignoredElements.includes(tagName))
  99. continue;
  100.  
  101. updateChildNodes(addedNode);
  102. }
  103. }
  104. }
  105. });
  106.  
  107. // Observe the children of the document DOM-element and every newly added element (descendants)
  108. observer.observe(document, { childList: true, subtree: true });
  109.  
  110.  
  111. //document-idle
  112. // Source: https://github.com/talkjs/country-flag-emoji-polyfill
  113. const fontName = "Twemoji Country Flags";
  114. const fontUrl = "https://cdn.jsdelivr.net/gh/matthijs110/chromium-country-flags/src/assets/TwemojiCountryFlags.woff2";
  115.  
  116. /**
  117. * Register the custom font-face to load the emoji-font for certain unicodes
  118. */
  119. const style = document.createElement("style");
  120. style.setAttribute("type", "text/css");
  121. style.setAttribute("id", "country-flag-fixer-ext");
  122.  
  123. // Unicode range generated by: https://wakamaifondue.com/beta/
  124. style.textContent = `
  125. @font-face {
  126. font-family: "${fontName}";
  127. font-style: normal;
  128. src: url('${fontUrl}') format('woff2');
  129. unicode-range: U+1F1E6-1F1FF, U+1F3F4, U+E0062-E0063, U+E0065, U+E0067, U+E006C, U+E006E, U+E0073-E0074, U+E0077, U+E007F;
  130. }
  131.  
  132. @font-face {
  133. font-family: "${fontName}";
  134. font-style: italic; /* Defined to prevent italic styled flags */
  135. src: url('${fontUrl}') format('woff2');
  136. unicode-range: U+1F1E6-1F1FF, U+1F3F4, U+E0062-E0063, U+E0065, U+E0067, U+E006C, U+E006E, U+E0073-E0074, U+E0077, U+E007F;
  137. }
  138. `;
  139.  
  140. // Check for cases like SVG files that don't have a head element
  141. if (document.head != undefined)
  142. {
  143. document.head.appendChild(style);
  144. }
  145. })();