Skip to content

Instantly share code, notes, and snippets.

@macloo
Created November 24, 2020 16:28
Show Gist options
  • Save macloo/f9c2570efc39c98ab3dd6fb4687ab743 to your computer and use it in GitHub Desktop.
Save macloo/f9c2570efc39c98ab3dd6fb4687ab743 to your computer and use it in GitHub Desktop.

Revisions

  1. macloo created this gist Nov 24, 2020.
    14 changes: 14 additions & 0 deletions detect_404.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title> Detect 404 </title>
    </head>

    <body>
    <p>Hello.</p>

    <script src="detect_404.js"></script>
    </body>
    </html>
    29 changes: 29 additions & 0 deletions detect_404.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    // check if one URL is good or not
    function urlExists(url, callback) {
    fetch(url, { method: 'head' })
    .then(function(status) {
    callback(status.ok)
    });
    }

    // URLs in an array
    // bad - BlZ57nzj6xZ
    // good - BlafBtHniQQ
    const url_list = [
    'https://www.instagram.com/p/BlZ57nzj6xZ/',
    'https://www.instagram.com/p/BlafBtHniQQ/'
    ];

    // loop over all URLs in list
    for (let i = 0; i < url_list.length; i++ ) {
    url = url_list[i];
    urlExists(url, function(exists) {
    if (exists) {
    // it exists, do something
    console.log("It is good.");
    } else {
    // it doesn't exist, do something else
    console.log("It is bad.");
    }
    });
    }