You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.3 KiB

4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
  1. {% extends "bootstrap/base.html" %}
  2. {% block title %}Technical Incompetence Link Shortener{% endblock %}
  3. {% block styles %}
  4. {{super()}}
  5. <link rel="stylesheet" href="{{url_for('.static', filename='style.css')}}">
  6. {% endblock %}
  7. {% block navbar %}
  8. {% include "fragments/navbar.j2" %}
  9. {% endblock %}
  10. {% block content %}
  11. <iframe id="apps" src="https://technicalincompetence.club/frame" width="305" height="400" class="shadow-lg overlay-frame" style="display: none;"></iframe>
  12. <div id="overlay" style="display: none;" onclick="showApps();"></div>
  13. <div class="container" style="margin-top: 15px">
  14. <div id="success-alert" class="alert alert-success" role="alert" style="display: none;">
  15. This is a success alert—check it out!
  16. </div>
  17. <div id="error-alert" class="alert alert-danger" role="alert" style="display: none;">
  18. This is a danger alert—check it out!
  19. </div>
  20. <form>
  21. <div class="row justify-content-center">
  22. <div class="col-lg-6">
  23. <label for="formGroupExampleInput4">URL</label>
  24. <input id="link-form" type="text" class="form-control" placeholder="https://example.com">
  25. <br>
  26. <button type="button" class="btn btn-primary" onclick="shortenUrl();">Shorten Link</button>
  27. <br>
  28. </div>
  29. </div>
  30. </form>
  31. </div>
  32. {% endblock %}
  33. {% block scripts %}
  34. {{ super() }}
  35. <script>
  36. function shortenUrl() {
  37. url = $('#link-form').val();
  38. if (url.trim().length === 0) {
  39. showError('URL is required');
  40. return false;
  41. }
  42. $.ajax({
  43. url: '/shorten',
  44. method: 'POST',
  45. data: { "url": url },
  46. success: function(data) {
  47. if (data !== 'Error')
  48. showSuccess(data);
  49. else
  50. showError('URL cannot be empty');
  51. }
  52. });
  53. }
  54. function showError(error) {
  55. hideSuccess();
  56. $('#error-alert').text(error);
  57. $('#error-alert').show();
  58. }
  59. function showSuccess(message) {
  60. hideError();
  61. $('#success-alert').html(message);
  62. $('#success-alert').show();
  63. }
  64. function hideError(error) {
  65. $('#error-alert').hide();
  66. }
  67. function hideSuccess(error) {
  68. $('#success-alert').hide();
  69. }
  70. function showApps () {
  71. $("#apps").toggle();
  72. $("#overlay").toggle();
  73. }
  74. </script>
  75. {% endblock %}