Created
November 24, 2020 16:28
-
-
Save macloo/f9c2570efc39c98ab3dd6fb4687ab743 to your computer and use it in GitHub Desktop.
Revisions
-
macloo created this gist
Nov 24, 2020 .There are no files selected for viewing
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 charactersOriginal 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> 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 charactersOriginal 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."); } }); }