' +
'
' + data.sign + ' ' + data.en + '
' +
'
' + data.date_range + '
' +
'
' +
'';
resultMeta.textContent = '查询成功';
}
form.addEventListener('submit', function(e) {
e.preventDefault();
var birthdate = document.getElementById('birthdate').value;
if (!birthdate) {
showError('请选择出生日期');
return;
}
btnQuery.textContent = '查询中...';
btnQuery.disabled = true;
fetch('/api/xingzuo/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ birthdate: birthdate })
})
.then(function(res) { return res.json(); })
.then(function(data) {
if (data.error) {
showError(data.error);
} else {
showResult(data);
}
})
.catch(function(err) {
showError('请求失败:' + err.message);
})
.finally(function() {
btnQuery.textContent = '查询星座';
btnQuery.disabled = false;
});
});
btnCopy.addEventListener('click', function() {
var text = resultContent.textContent;
if (!text) return;
navigator.clipboard.writeText(text).then(function() {
var orig = btnCopy.textContent;
btnCopy.textContent = '已复制';
setTimeout(function() { btnCopy.textContent = '复制结果'; }, 1500);
}).catch(function() {
var ta = document.createElement('textarea');
ta.value = text;
document.body.appendChild(ta);
ta.select();
document.execCommand('copy');
document.body.removeChild(ta);
btnCopy.textContent = '已复制';
setTimeout(function() { btnCopy.textContent = '复制结果'; }, 1500);
});
});
})();