Благодарим за выбор нашего сервиса!
Тестовое сообщение
Страница: 1
Сообщений 1 страница 2 из 2
Поделиться22026-02-26 06:47:11
Код:
<!--------------------- РЕГУЛИРОВКА РАЗМЕРА ШРИФТА В ПОСТАХ ------------------------->
<script>
document.addEventListener('DOMContentLoaded', () => {
// --- НАЙСТРОЙКИ ---
const config = {
targets: [
'.post-content p',
'.html-content',
'.lore-disp',
'#messages .post-content'
],
injectionPoint: '.post:first-of-type h3 > span strong',
// Настройки размера шрифта
minSize: 10,
maxSize: 24,
defaultSize: 12,
step: 1,
storageKey: 'fontSizeSetting'
};
// --- КОНЕЦ НАСТРОЕК ---
const injectionTarget = document.querySelector(config.injectionPoint);
if (!injectionTarget) return;
const allTargetsSelector = config.targets.join(', ');
const applyFontSize = (size) => {
document.querySelectorAll(allTargetsSelector).forEach(el => {
el.style.fontSize = `${size}px`;
});
};
const getCurrentSize = () => {
const savedSize = localStorage.getItem(config.storageKey);
return savedSize ? parseFloat(savedSize) : config.defaultSize;
};
const init = () => {
const controlsContainer = document.createElement('div');
controlsContainer.className = 'font-controls';
controlsContainer.innerHTML = `
<button class="decrease-btn" title="Уменьшить шрифт">-</button>
<button class="reset-btn" title="Сбросить размер">A</button>
<button class="increase-btn" title="Увеличить шрифт">+</button>
`;
injectionTarget.after(controlsContainer);
const decreaseBtn = controlsContainer.querySelector('.decrease-btn');
const resetBtn = controlsContainer.querySelector('.reset-btn');
const increaseBtn = controlsContainer.querySelector('.increase-btn');
applyFontSize(getCurrentSize());
decreaseBtn.addEventListener('click', () => {
let currentSize = getCurrentSize();
currentSize = Math.max(config.minSize, currentSize - config.step);
applyFontSize(currentSize);
localStorage.setItem(config.storageKey, currentSize);
});
increaseBtn.addEventListener('click', () => {
let currentSize = getCurrentSize();
currentSize = Math.min(config.maxSize, currentSize + config.step);
applyFontSize(currentSize);
localStorage.setItem(config.storageKey, currentSize);
});
resetBtn.addEventListener('click', () => {
applyFontSize(config.defaultSize);
localStorage.removeItem(config.storageKey);
});
};
init();
});
</script>
<!-- КОНЕЦ -->Страница: 1








