const container = document.querySelector(".lang_seletor"); let isShow = false; function showSelector() { document.querySelector('.lang_seletor').style.display = isShow ? "none" : "flex"; isShow = !isShow; updateSpacing() } async function langPageSkip(lang) { const newUrl = window.location.href.replace( /(https?:\/\/)(?:www\.)?((?:[a-z]{2}\.)?[^/]+)/, (match, protocol, domain) => { // 移除主域名的前缀(如 kr.) const domainParts = domain.split('.'); if (domainParts.length > 2) { domainParts.shift(); } const cleanDomain = domainParts.join('.'); if (cleanDomain.startsWith('test.')) { return `${protocol}test${lang}.${cleanDomain.slice(5)}`; } else { return `${protocol}${lang}.${cleanDomain}`; } } ); window.location.href = newUrl; } const updateSpacing = () => { const cards = [...container.children]; if (cards.length === 0) return; const containerWidth = container.clientWidth; const cardWidth = cards[0].offsetWidth; let maxPerRow = Math.floor(containerWidth / (cardWidth + 10)); let spacing = (containerWidth - maxPerRow * cardWidth) / (maxPerRow - 1); container.style.columnGap = `${spacing}px`; }; window.addEventListener("resize", updateSpacing); updateSpacing();