\n`;
generatedMetaTags += `\n`;
}
if (description) {
generatedMetaTags += `\n`;
}
if (keywords) {
generatedMetaTags += `\n`;
}
if (author) {
generatedMetaTags += `\n`;
}
generatedMetaTags += `\n`;
generatedMetaTags += `\n\n`;// Open Graph Tags
if (ogTitle) {
generatedMetaTags += `\n`;
generatedMetaTags += `\n`;
}
if (ogDescription) {
generatedMetaTags += `\n`;
}
if (ogType) {
generatedMetaTags += `\n`;
}
if (ogUrl) {
generatedMetaTags += `\n`;
}
if (ogImage) {
generatedMetaTags += `\n`;
}
if (ogSiteName) {
generatedMetaTags += `\n`;
}
if (ogTitle || ogDescription || ogImage || ogUrl || ogSiteName ) generatedMetaTags += `\n`;// Twitter Card Tags
if (twitterCard) { // twitter:card is mandatory for twitter cards to work
generatedMetaTags += `\n`;
generatedMetaTags += `\n`;
if (twitterSite) {
generatedMetaTags += `\n`;
}
if (twitterCreator) {
generatedMetaTags += `\n`;
}
if (twitterTitle) {
generatedMetaTags += `\n`;
}
if (twitterDescription) {
generatedMetaTags += `\n`;
}
if (twitterImage) {
generatedMetaTags += `\n`;
}
if (twitterUrl) { // Though og:url is often used by Twitter, twitter:url can be specified
generatedMetaTags += `\n`;
} else if (ogUrl) {
// Twitter will fall back to og:url if twitter:url is not set
// No need to explicitly add it again if og:url is already there and twitter:url is not specified.
}
}
outputCodeElement.textContent = generatedMetaTags.trim() ? generatedMetaTags.trim() : '';
copyFeedbackElement.textContent = ''; // Clear previous feedback
});
}if (resetButton) {
resetButton.addEventListener('click', function() {
const inputs = document.querySelectorAll('.meta-tag-generator-container input[type="text"], .meta-tag-generator-container input[type="url"], .meta-tag-generator-container textarea');
inputs.forEach(input => input.value = '');
const selects = document.querySelectorAll('.meta-tag-generator-container select');
selects.forEach(select => {
if (select.id === 'mtg-og-type') select.value = 'website';
else if (select.id === 'mtg-twitter-card') select.value = 'summary';
else select.selectedIndex = 0;
});
outputCodeElement.textContent = '';
copyFeedbackElement.textContent = '';
autoFillSocialFields(); // Reset placeholders
});
}if (copyButton) {
copyButton.addEventListener('click', function() {
const codeToCopy = outputCodeElement.textContent;
if (codeToCopy && codeToCopy !== '' && codeToCopy !== '') {
navigator.clipboard.writeText(codeToCopy).then(function() {
copyFeedbackElement.textContent = 'Đã sao chép!';
copyButton.textContent = 'Đã sao chép!';
setTimeout(() => {
copyFeedbackElement.textContent = '';
copyButton.textContent = 'Sao chép vào Clipboard';
}, 2000);
}, function(err) {
copyFeedbackElement.textContent = 'Lỗi khi sao chép!';
console.error('Không thể sao chép: ', err);
// Fallback for older browsers (less reliable)
try {
const textArea = document.createElement("textarea");
textArea.value = codeToCopy;
textArea.style.position = "fixed"; //avoid scrolling to bottom
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
copyFeedbackElement.textContent = 'Đã sao chép! (fallback)';
copyButton.textContent = 'Đã sao chép!';
setTimeout(() => {
copyFeedbackElement.textContent = '';
copyButton.textContent = 'Sao chép vào Clipboard';
}, 2000);
} catch (e) {
copyFeedbackElement.textContent = 'Không thể sao chép.';
}
});
} else {
copyFeedbackElement.textContent = 'Không có gì để sao chép.';
setTimeout(() => {
copyFeedbackElement.textContent = '';
}, 2000);
}
});
}
});