// 全局错误处理
window.addEventListener('error', function(e) {
if (e.message && e.message.includes('nextElementSibling')) {
e.preventDefault();
}
});
window.addEventListener('unhandledrejection', function(e) {
console.warn('[MetaPreview] Unhandled Promise rejection:', e.reason);
});
// 简易 i18n 框架(仅初始化,后续可扩展)
window.__locale = navigator.language || 'zh-CN';
window.__i18n = window.__i18n || {};
window.__i18n.zhCN = {
'app.title': 'MetaPreview · OG 标签预览检查器',
'app.desc': 'OG 标签预览检查器 · 模拟社交卡片 · SEO 完整性分析',
'input.label': '粘贴页面 HTML(包含 和 OG 标签)',
'input.placeholder': '\n\n\n \n ...',
'btn.parse': '解析预览',
'btn.sample': '加载示例',
'btn.clear': '清空历史',
'panel.social': '社交平台模拟预览',
'panel.seo': 'SEO 检查结果',
'panel.history': '历史记录',
'empty.social': '输入 HTML 后点击"解析预览"',
'empty.seo': '解析后将显示 SEO 完整性分析',
'empty.history': '暂无历史记录',
'footer.privacy': '隐私政策',
};
window.__i18n.en = {
'app.title': 'MetaPreview · OG Tag Preview Checker',
'app.desc': 'OG Tag Preview Checker · Social Card Simulator · SEO Audit',
'input.label': 'Paste page HTML (including and OG tags)',
'input.placeholder': '\n\n\n \n ...',
'btn.parse': 'Parse & Preview',
'btn.sample': 'Load Sample',
'btn.clear': 'Clear History',
'panel.social': 'Social Platform Preview',
'panel.seo': 'SEO Audit Results',
'panel.history': 'History',
'empty.social': 'Paste HTML and click "Parse & Preview"',
'empty.seo': 'SEO audit results will appear after parsing',
'empty.history': 'No history yet',
'footer.privacy': 'Privacy Policy',
};
function __(key) {
var lang = window.__locale.startsWith('zh') ? 'zhCN' : 'en';
return (window.__i18n[lang] && window.__i18n[lang][key]) || key;
}
// 挂载到页面元素的数据替换(仅做示例,未实际应用)
console.log('MetaPreview i18n ready, locale=' + window.__locale);
`;
parseAndPreview();
});
$('clearHistoryBtn').addEventListener('click', () => {
localStorage.removeItem('metapreview_history');
renderHistory();
showToast('历史已清空');
});
renderHistory();