以下の手順を作業用チェックリストとして使い、プロジェクトで確認できた根拠、対象範囲、制約に合わせて調整してください。
実務的な手順
- 確認対象のページとブラウザーの開発者コンソールを開きます。モバイルのはみ出し確認では、先にレスポンシブモードにします。
- コードを確認し、スクリプト全体をコンソールへ貼り付けてEnterを押します。現在のページを読み取ります。サイトマップメタデータツールと同一オリジンのチェッカーだけが、回数を制限してリクエストを送ります。
- コンソールの出力またはダウンロードした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.');
})();実行前に内容を確認してください。このスクリプトは現在のページを読み取ります。リクエストを送るのはサイトマップとリンクの監査だけで、回数は制限されています。cookieは送信せず、サイトの内容も変更しません。