Flatlogic Bot 1fafa67d4f kei
2026-04-14 13:52:40 +00:00

65 lines
2.8 KiB
JavaScript

document.addEventListener('DOMContentLoaded', () => {
const langToggle = document.querySelector('[data-lang-toggle]');
const langCurrent = document.querySelector('[data-lang-current]');
const toastElement = document.getElementById('keiToast');
const toastBody = toastElement ? toastElement.querySelector('.toast-body') : null;
const toast = toastElement && window.bootstrap ? new bootstrap.Toast(toastElement, { delay: 1600 }) : null;
const applyLanguage = (lang) => {
document.documentElement.lang = lang === 'jp' ? 'ja' : 'id';
document.querySelectorAll('[data-copy-id][data-copy-jp]').forEach((el) => {
const content = lang === 'jp' ? el.dataset.copyJp : el.dataset.copyId;
if (el.dataset.copyHtml === '1') {
el.innerHTML = content || '';
} else {
el.textContent = content || '';
}
});
document.querySelectorAll('[data-placeholder-id][data-placeholder-jp]').forEach((el) => {
el.setAttribute('placeholder', lang === 'jp' ? el.dataset.placeholderJp : el.dataset.placeholderId);
});
if (langCurrent) {
langCurrent.textContent = lang.toUpperCase();
}
localStorage.setItem('kei_lang', lang);
};
const showToast = (message) => {
if (!toastBody || !toast) return;
toastBody.textContent = message;
toast.show();
};
const initialLang = localStorage.getItem('kei_lang') || 'id';
applyLanguage(initialLang);
if (langToggle) {
langToggle.addEventListener('click', () => {
const nextLang = (localStorage.getItem('kei_lang') || 'id') === 'id' ? 'jp' : 'id';
applyLanguage(nextLang);
showToast(nextLang === 'jp' ? '日本語に切り替えました。' : 'Bahasa Indonesia aktif.');
});
}
document.querySelectorAll('[data-file-target]').forEach((input) => {
input.addEventListener('change', (event) => {
const target = document.getElementById(event.currentTarget.dataset.fileTarget);
if (!target) return;
const fileName = event.currentTarget.files && event.currentTarget.files[0] ? event.currentTarget.files[0].name : target.dataset.defaultLabel || target.textContent;
if (!target.dataset.defaultLabel) {
target.dataset.defaultLabel = target.textContent;
}
target.textContent = fileName;
});
});
document.querySelectorAll('[data-submit-state]').forEach((form) => {
form.addEventListener('submit', () => {
const submit = form.querySelector('button[type="submit"]');
if (!submit) return;
submit.disabled = true;
submit.textContent = 'Processing...';
});
});
});