url_checker.html 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <!DOCTYPE html>
  2. <html>
  3. <meta charset="UTF-8">
  4. <head>
  5. <title> URL Checker </title>
  6. </head>
  7. <script type="text/javascript">
  8. var lastCheck = Date.now()
  9. function check_link(x) {
  10. l = x.value
  11. if (!l.match(/^((https|ftp|http|git?):\/\/)?([w|W]{3}\.)+[a-zA-Z0-9\-\.]{3,}\.[a-zA-Z]{2,}(\.[a-zA-Z]{2,})?$/)) {
  12. document.getElementById('valid').innerHTML = "Invalid Link";
  13. document.getElementById('file').innerHTML = "";
  14. }
  15. else {
  16. document.getElementById('valid').innerHTML = "Valid Link format";
  17. setTimeout(function(){
  18. fetch(l)
  19. .then((response) => {
  20. if (response.ok) {
  21. let temp = response.json()
  22. document.getElementById('file').innerHTML = temp.fileOrFolder + "exists at this URL"
  23. }
  24. else {
  25. document.getElementById('file').innerHTML = "URL does not exist";
  26. }
  27. })
  28. .catch(error => console.error(error));
  29. }, Math.max( lastCheck-Date.now()+2000 , 0));
  30. lastCheck = Date.now();
  31. }
  32. }
  33. </script>
  34. <body>
  35. <br><h2> URL Checker </h2><br>
  36. <input id = "lin" type="text" placeholder="Enter valid URL" oninput="check_link(this)">
  37. <br><div id='valid'></div>
  38. <br><div id='file'></div>
  39. </body>
  40. </html>