Skip to content

Commit

Permalink
Cleanup Errors & TS Flow
Browse files Browse the repository at this point in the history
  • Loading branch information
devinbaeten committed Mar 9, 2023
1 parent 929f594 commit 52bac0a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bereal-time-history",
"private": true,
"version": "2.0.4",
"version": "2.0.5",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
18 changes: 11 additions & 7 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

gtag('config', 'G-9ZECMCE1K5');
</script>
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" defer></script>
</head>
<body>
<main>
Expand All @@ -38,10 +38,10 @@
</nav>
<div class="container mt-3 mb-5">
<div class="alert bg-warning" id="turnstileClearance">
<h2 class="mt-1">
One Moment...
</h2>
<span class="">In an effort to deter bots, we now require automatic validation of your browser when visiting this site. You may be required to complete a challenge as part of this process.</span>
<h4 class="mt-1">
Browser Check
</h4>
<span class="d-none">In an effort to deter bots, we now require automatic validation of your browser when visiting this site. You may be required to complete a challenge as part of this process.</span>
<div class="cf-turnstile mt-3" data-sitekey="0x4AAAAAAADDviGXS3cvoFLE" data-callback="tsComplete"></div>
</div>
<div class="alert alert-danger d-none">
Expand All @@ -50,7 +50,7 @@ <h2 class="mt-1">
This site is actively being worked on at this very moment. Please excuse any issues as I work to improve your experience.
</span>
</div>
<div class="alert alert-primary">
<div class="alert alert-primary d-none">
<span>
<b>NEW:</b>
Introducing the BeReal Time History API. You can now request an API key which enables access the full extent of my historical data, on-demand! Select the "API" tab below to get started.
Expand Down Expand Up @@ -738,13 +738,17 @@ <h2>Contact The Developer</h2>
</ul>
<p class="text-center fw-bold mb-0">This site is NOT officially affiliated with BeReal</p>
<p class="text-center text-secondary">Data is collected and provided for educational purposes only</p>
<p class="text-center text-muted">© 2023 Devin Baeten</p>
<p class="text-center text-muted mb-0">© 2023 Devin Baeten</p>
<p class="text-center text-muted mt-0" id="version"></p>
</footer>
</div>
<script type="module" src="./js/main.js"></script>
<script>
function tsComplete() {
setToken(turnstile.getResponse());
setTimeout(function() {
turnstile.reset();
}, 1800000);
}
</script>
</body>
Expand Down
33 changes: 24 additions & 9 deletions src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@
import $ from 'jquery';
import moment from 'moment-timezone';
import Chart from 'chart.js/auto';
import { version } from '../../package.json';

// Turnstile
// Display version
$("#version").html("v" + version + " &middot; <a class=\"text-muted\" target=\"blank\" href=\"https://github.com/devinbaeten/bereal-time-history/releases/tag/v" + version + "\">View on GitHub</a>");

// Turnstile
var cftsr = "NONE";

function setToken(token) {
$("#dashboard").removeClass("opacity-25");
setTimeout(function() {
$("#turnstileClearance").addClass("d-none");
}, 1000);
cftsr = token;
setTimeout(function() {
$("#dashboard").addClass("opacity-25");
$("#turnstileClearance").removeClass("d-none");
}, 1800000);
$("#dashboard").removeClass("opacity-25");
$("#turnstileClearance").addClass("d-none");
begin();
}

// Attach the function to the window object
Expand Down Expand Up @@ -568,17 +574,27 @@ function refresh() {

function failed(xhr, ajaxOptions, thrownError) {
if (cftsr !== "NONE") {
showError('bg-danger', 'Connection failed (Error ' + xhr.status + ')');
switch (xhr.status) {
case 0:
showError('bg-danger', 'Network Error', 'Check your internet connection');
case 403:
showError('bg-danger', 'Access Denied', 'The server was unable to verify your request. Please refresh the page if this issue persists.');
break;
default:
showError('bg-danger', 'Server Error', 'An unknown error has occured. Please try again later. (' + xhr.status + ')');
break;
}
}
}

}

function showError(css, text) {
function showError(css, title, text) {

$("#reqError").removeClass("d-none");
$("#reqError").addClass(css);
$("#reqError").text(text);
$("#reqError").prepend("<b>" + title + "</b><br/>");

retries++;

Expand Down Expand Up @@ -776,5 +792,4 @@ function refreshHistory() {
// window.location.reload();
}

}
begin();
}

0 comments on commit 52bac0a

Please sign in to comment.