/* Keep short Russian prepositions with the following word in displayed UI text. */ (function () { 'use strict'; if (window.fiRussianTypography) return; window.fiRussianTypography = true; var excluded = 'script,style,textarea,input,select,option,pre,code,svg,math,[contenteditable]:not([contenteditable="false"]),[data-no-typography]'; var pattern = /(^|[^\p{L}\p{N}_])(в|во|к|ко|с|со|у|о|об|обо|на|по|из|от|до|за|без|для|при|под|над|из-за|из-под)[ \t]+(?=[\p{L}\p{N}])/giu; function format(value) { // Repeat once to handle adjacent prepositions without leaving a hanging one. return value.replace(pattern, '$1$2\u00a0').replace(pattern, '$1$2\u00a0'); } function visit(root) { if (!root || !root.isConnected) return; if (root.nodeType === 3) { if (root.parentElement && !root.parentElement.closest(excluded)) { var value = format(root.nodeValue); if (value !== root.nodeValue) root.nodeValue = value; } return; } if (root.nodeType !== 1 || root.closest(excluded)) return; var walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT); var node; while ((node = walker.nextNode())) visit(node); } function start() { visit(document.body); new MutationObserver(function (changes) { changes.forEach(function (change) { if (change.type === 'characterData') visit(change.target); else change.addedNodes.forEach(visit); }); }).observe(document.body, {childList:true,subtree:true,characterData:true}); } if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', start); else start(); })();