Код:
<script>
(function() {
const targetForums = [1]; // свои ID
const currentForumId = window.FORUM
? parseInt(FORUM.get('topic.forum_id'))
: null;
if (targetForums.length && (!currentForumId || !targetForums.includes(currentForumId))) {
return;
}
function fixCase(text) {
text = text.toLowerCase();
return text.replace(/(^\s*|[.!?]\s+|\n\s*)([a-zа-яё])/gi,
function(match, sep, letter) {
return sep + letter.toUpperCase();
}
);
}
function processTextNodes(container, restore) {
const walker = document.createTreeWalker(
container,
NodeFilter.SHOW_TEXT,
null,
false
);
let node;
while (node = walker.nextNode()) {
if (!node.nodeValue.trim()) continue;
if (!restore) {
node._original = node.nodeValue;
node.nodeValue = fixCase(node.nodeValue);
} else if (node._original !== undefined) {
node.nodeValue = node._original;
}
}
}
$(window).on('load', function() {
const panel = $('#form-buttons');
if (!panel.length) return;
if ($('#btn-caps-fix').length) return;
const btn = $('<a>', {
id: 'btn-caps-fix',
href: '#',
title: 'Нормализовать регистр',
html: '<i class="fas fa-font"></i>',
css: {
display: 'inline-block',
marginLeft: '0px',
verticalAlign: 'middle',
cursor: 'pointer'
}
});
panel.after(btn);
btn.on('click', function(e) {
e.preventDefault();
const isActive = btn.hasClass('is-fixed');
$('.post-content').each(function() {
processTextNodes(this, isActive);
});
btn.toggleClass('is-fixed')
.css('color', isActive ? '' : '#4caf50');
});
});
})();
</script>
