(function($) {
$(document).ready(function() {
// Проверяем, заданы ли настройки в HTML низ
if (!window.GuestResConfig || !window.GuestResConfig.ids) return;
const TARGET_TOPIC_IDS = window.GuestResConfig.ids;
function showToast(message, isError = false) {
const $container = $('#res_toast_container');
$container.empty();
const $toast = $('
', {
class: 'role-res-toast-item' + (isError ? ' error' : '')
}).html(message.replace(/\n/g, '
'));
$container.append($toast);
setTimeout(() => $toast.css('opacity', 1), 10);
setTimeout(() => {
$toast.css('opacity', 0);
setTimeout(() => $toast.remove(), 300);
}, 3000);
}
// Определяем ID темы
let topicId = new URLSearchParams(window.location.search).get('id');
if (!topicId) {
const $topicContainer = $('div[id^="topic_t"]');
if ($topicContainer.length) {
topicId = $topicContainer.attr('id').replace('topic_t', '');
}
}
// Если тема не в списке — выходим
if (!topicId || !TARGET_TOPIC_IDS.includes(topicId)) return;
// Генерация формы
const formHTML = `
`;
let $targetPost = $('.firstpost .post-content').first();
if (!$targetPost.length) $targetPost = $('.post .post-content').first();
if ($targetPost.length) $targetPost.append(formHTML);
// Работа с профилем юзера
const isGuest = (!window.UserID || window.UserID === 1);
let profileUrl = '';
if (!isGuest) {
profileUrl = (window.BoardURL || window.location.origin) + '/profile.php?id=' + window.UserID;
if (window.UserLogin) $('#res_nick').val(window.UserLogin);
}
// Клик по кнопке
$('#res_btn').click(function() {
// ДОБАВЛЕН toLowerCase() СЮДА 👇
const charName = $('#res_char').val().trim().toLowerCase();
const nick = $('#res_nick').val().trim().toLowerCase();
if (!charName || !nick) {
showToast('Пожалуйста, заполните все поля!', true);
return;
}
let finalNick = nick;
if (!isGuest && profileUrl) {
finalNick = '[url=' + profileUrl + ']' + nick + '[/url]';
}
const resultString = `[code][b]${charName}[/b] — ${finalNick}[/code]`;
const $replyBox = $('#main-reply');
if ($replyBox.length) {
let val = $replyBox.val();
$replyBox.val(val + (val && !val.endsWith('\n') ? '\n' : '') + resultString);
$('html, body').animate({ scrollTop: $replyBox.offset().top - 50 }, 500);
} else {
navigator.clipboard.writeText(resultString).then(() => {
showToast('Форма ответа не найдена. Текст скопирован!');
}).catch(() => showToast('Ошибка при копировании.', true));
}
});
});
})(jQuery);