Evan Reichard
dc9f8cd9db
All checks were successful
continuous-integration/drone/push Build is passing
156 lines
4.8 KiB
HTML
156 lines
4.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, viewport-fit=cover">
|
|
<meta name="apple-mobile-web-app-capable" content="yes"/>
|
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
|
|
<meta name="theme-color" content="#E5E7EB" media="(prefers-color-scheme: light)">
|
|
<meta name="theme-color" content="#123636" media="(prefers-color-scheme: dark)">
|
|
|
|
<title>VReader - Home</title>
|
|
|
|
<link rel="manifest" href="/manifest.json" />
|
|
<link rel="stylesheet" href="/static/style.css">
|
|
<link rel="stylesheet" href="/static/tailwind.css">
|
|
</head>
|
|
<body class="text-ptext bg-secondary">
|
|
<header class="w-screen h-16 bg-secondary">
|
|
<div
|
|
class="flex px-2 h-16 w-11/12 md:w-5/6 mx-auto"
|
|
>
|
|
<a class="flex gap-2 justify-center items-center" href="/">
|
|
<img class="h-10 rounded items-center" src="/static/icons/icon512.png"></img>
|
|
<span class="font-bold flex justify-center items-center">VReader</span>
|
|
</a>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="relative overflow-hidden bg-primary">
|
|
<div id="container" class="h-[100dvh] flex flex-col gap-3 px-4 overflow-auto md:px-6 mt-3">
|
|
<div id="submit"
|
|
class="flex gap-4 items-center text-lg w-11/12 md:w-4/6 mx-auto rounded px-6 py-3 bg-secondary transition-all duration-200"
|
|
>
|
|
<input type="text" placeholder="YouTube URL" class="w-full px-2 py-1 bg-tertiary text-stext rounded">
|
|
<button class="px-2 py-1 bg-tertiary text-stext hover:bg-primary rounded">Generate</button>
|
|
</div>
|
|
|
|
{% for article in articles %}
|
|
<a
|
|
href="/articles/{{ article.video_id }}"
|
|
class="flex items-center text-lg w-11/12 md:w-4/6 mx-auto rounded px-6 py-3 bg-secondary hover:bg-tertiary transition-all duration-200"
|
|
>
|
|
<img class="h-14 md:h-24 mr-6 rounded" src="https://i.ytimg.com/vi_webp/{{ article.video_id }}/maxresdefault.webp"></img>
|
|
<span>{{ article.title }}</span>
|
|
</a>
|
|
{% endfor %}
|
|
<div class="mb-0.5"></div>
|
|
</div>
|
|
</main>
|
|
<script>
|
|
const LOADING_SVG = `<svg
|
|
class="w-full"
|
|
width="24"
|
|
height="24"
|
|
viewBox="0 0 24 24"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
fill="currentColor"
|
|
>
|
|
<style>
|
|
.spinner_qM83 {
|
|
animation: spinner_8HQG 1.05s infinite;
|
|
}
|
|
.spinner_oXPr {
|
|
animation-delay: 0.1s;
|
|
}
|
|
.spinner_ZTLf {
|
|
animation-delay: 0.2s;
|
|
}
|
|
@keyframes spinner_8HQG {
|
|
0%,
|
|
57.14% {
|
|
animation-timing-function: cubic-bezier(0.33, 0.66, 0.66, 1);
|
|
transform: translate(0);
|
|
}
|
|
28.57% {
|
|
animation-timing-function: cubic-bezier(0.33, 0, 0.66, 0.33);
|
|
transform: translateY(-6px);
|
|
}
|
|
100% {
|
|
transform: translate(0);
|
|
}
|
|
}
|
|
</style>
|
|
<circle class="spinner_qM83" cx="4" cy="12" r="3"></circle>
|
|
<circle class="spinner_qM83 spinner_oXPr" cx="12" cy="12" r="3"></circle>
|
|
<circle class="spinner_qM83 spinner_ZTLf" cx="20" cy="12" r="3"></circle>
|
|
</svg>`;
|
|
|
|
/**
|
|
* Wrapper API Call
|
|
**/
|
|
function apiCall(data) {
|
|
let fetchObj = {
|
|
method: data.method || "GET",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
};
|
|
|
|
if (fetchObj.method == "POST")
|
|
fetchObj.body = JSON.stringify(data.data || {});
|
|
|
|
return fetch(data.url, fetchObj).then((resp) => resp.json());
|
|
}
|
|
|
|
function generateAction(){
|
|
let inputEl = document.querySelector("input");
|
|
let inputVal = inputEl.value;
|
|
let videoID = getYouTubeVideoId(inputVal);
|
|
if (!videoID) return alert("Invalid URL")
|
|
|
|
// Loading
|
|
let submitEl = document.querySelector("#submit");
|
|
let oldHTML = submitEl.innerHTML;
|
|
submitEl.innerHTML = LOADING_SVG;
|
|
|
|
// Do API Call
|
|
apiCall({
|
|
url: "/api/v1/generate",
|
|
method: "POST",
|
|
data: { video: videoID },
|
|
}).then((resp) => {
|
|
if ("error" in resp) throw new Error(resp.error);
|
|
window.location.href = "/articles/" + videoID;
|
|
}).catch(e => {
|
|
console.log(e);
|
|
alert(e.message);
|
|
submitEl.innerHTML = oldHTML;
|
|
});
|
|
}
|
|
|
|
function initListeners(){
|
|
let buttonEl = document.querySelector("button");
|
|
let inputEl = document.querySelector("input");
|
|
buttonEl.addEventListener("click", generateAction);
|
|
inputEl.addEventListener("keydown", function(event) {
|
|
if (event.keyCode !== 13) return;
|
|
generateAction();
|
|
});
|
|
}
|
|
|
|
function getYouTubeVideoId(url) {
|
|
var regExp = /^.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
|
|
var match = url.match(regExp);
|
|
if (match && match[1]) {
|
|
return match[1];
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
initListeners();
|
|
</script>
|
|
</body>
|
|
</html>
|