Skip to content

Instantly share code, notes, and snippets.

@amiresp
Created May 31, 2025 13:45
Show Gist options
  • Select an option

  • Save amiresp/3899f27ed12cbe4336339b87f628f67d to your computer and use it in GitHub Desktop.

Select an option

Save amiresp/3899f27ed12cbe4336339b87f628f67d to your computer and use it in GitHub Desktop.
404 detector in console
(async () => {
const links = Array.from(document.querySelectorAll('a'))
.map(a => a.href)
.filter(href => href.startsWith('http')); // فقط لینک‌های معتبر (نه # یا mailto)
console.log(`در حال بررسی ${links.length} لینک...`);
for (const url of links) {
try {
const response = await fetch(url, { method: 'HEAD' });
if (response.status === 404) {
console.warn(`❌ لینک 404: ${url}`);
} else {
console.log(`✅ ${response.status} - ${url}`);
}
} catch (err) {
console.error(`⚠️ خطا در دسترسی به ${url}`, err);
}
// تاخیر کوچک بین هر درخواست برای فشار نیاوردن به سرور
await new Promise(res => setTimeout(res, 300));
}
console.log('✅ بررسی همه لینک‌ها تمام شد.');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment