Created
May 31, 2025 13:45
-
-
Save amiresp/3899f27ed12cbe4336339b87f628f67d to your computer and use it in GitHub Desktop.
404 detector in console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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