将以下步骤作为工作清单,并根据项目的证据、范围和限制进行调整。
实用步骤
- 打开要检查的页面和浏览器开发者控制台。检查移动端溢出时,先使用响应式模式。
- 审查代码,将完整代码片段粘贴到控制台并按 Enter。脚本读取当前页面;只有 sitemap 元数据工具和同源检查工具会在有限范围内发出请求。
- 查看控制台输出或下载的 CSV/JSON。浏览器策略、身份验证和服务器不支持的方法可能导致部分检查无法得出结论。
(() => {
const MAX_LINKS = 5000;
const allLinks = document.links;
const links = Array.from({ length: Math.min(allLinks.length, MAX_LINKS) }, (_, index) => allLinks[index]).map((link) => {
const url = new URL(link.href, location.href);
const text = [link.innerText, link.getAttribute('aria-label'), link.title]
.map((value) => (value || '').trim().replace(/\s+/g, ' '))
.find(Boolean) || '';
return {
text,
url: url.href,
type: url.origin === location.origin ? 'internal' : 'external',
target: link.target || '',
rel: link.rel || '',
nofollow: link.relList.contains('nofollow'),
ariaLabel: link.getAttribute('aria-label') || '',
};
});
console.table(links);
const quote = (value) => '"' + String(value).replace(/[\u0000-\u0020]*[=+\-@]/, (match) => "'" + match).replace(/"/g, '""') + '"';
const columns = ['text', 'url', 'type', 'target', 'rel', 'nofollow', 'ariaLabel'];
const csv = '\uFEFF' + [columns, ...links.map((row) => columns.map((column) => row[column] ?? ''))].map((row) => row.map(quote).join(',')).join('\r\n');
const a = document.createElement('a'); a.href = URL.createObjectURL(new Blob([csv], { type: 'text/csv;charset=utf-8' })); a.download = 'page-links.csv'; a.click(); setTimeout(() => URL.revokeObjectURL(a.href), 1000);
console.info('Exported ' + links.length + ' links from the current page.');
if (allLinks.length > MAX_LINKS) console.warn('Only the first ' + MAX_LINKS + ' of ' + allLinks.length + ' links were exported.');
})();运行前请先审查代码。脚本读取当前页面;只有 sitemap 和链接审查工具会在有限范围内发出同源请求。请求不携带 cookies;脚本不会更改网站内容。