Make it possible to generate only video preview

This commit is contained in:
Kuba Orlik 2024-01-17 10:30:44 +01:00
parent 895302fa1e
commit 139c4b9359
2 changed files with 294 additions and 269 deletions

115
script.js
View File

@ -1,40 +1,44 @@
function generateHtml() {
if (
document.querySelector("#episode_name").value &&
document.querySelector("#castopod").value &&
document.querySelector("#peertube").value &&
document.querySelector("#youtube").value
) {
function getCastopodURL() {
let castopod_url;
let peertube_id;
try {
castopod_url = document
.querySelector("#castopod").value;
const regex = /^https:\/\/podcast\.internet-czas-dzialac\.pl\/@icd\/episodes\//;
castopod_url = document.querySelector("#castopod").value;
const regex =
/^https:\/\/podcast\.internet-czas-dzialac\.pl\/@icd\/episodes\//;
if (!regex.test(castopod_url)) {
throw new Error("Incorrect Castopod URL format! Please paste the correct URL. Example: https://podcast.internet-czas-dzialac.pl/@icd/episodes/icd-weekend-6-stara-myszka-mickey-nowy-prezes-uodo-i-sony-psujace-sylwestra");
throw new Error(
"Incorrect Castopod URL format! Please paste the correct URL. Example: https://podcast.internet-czas-dzialac.pl/@icd/episodes/icd-weekend-6-stara-myszka-mickey-nowy-prezes-uodo-i-sony-psujace-sylwestra"
);
}
} catch (error) {
alert(error);
}
return castopod_url;
}
function getPeertubeID() {
let peertube_id;
try {
const regex = /^https:\/\/video\.internet-czas-dzialac\.pl\/w\/[a-zA-Z0-9]{22,}$/;
peertube_id = document
.querySelector("#peertube")
.value.split("/w/")[1];
const regex =
/^https:\/\/video\.internet-czas-dzialac\.pl\/w\/[a-zA-Z0-9]{22,}$/;
peertube_id = document.querySelector("#peertube").value.split("/w/")[1];
if (!regex.test(document.querySelector("#peertube").value) || !peertube_id) {
throw new Error("Incorrect PeerTube URL format! Please paste the correct URL. Example: https://video.internet-czas-dzialac.pl/w/nTgqnY7FJLQzNYfD9xtcSy");
if (
!regex.test(document.querySelector("#peertube").value) ||
!peertube_id
) {
throw new Error(
"Incorrect PeerTube URL format! Please paste the correct URL. Example: https://video.internet-czas-dzialac.pl/w/nTgqnY7FJLQzNYfD9xtcSy"
);
}
} catch (error) {
alert(error);
}
return peertube_id;
}
let html = "";
if (document.querySelector("#castopod-player-visible").checked) {
html += `<div class="player">
function makeCastopodPlayer(castopod_url) {
return /* HTML */ `<div class="player">
<iframe
width="100%"
height="112"
@ -43,12 +47,11 @@ function generateHtml() {
style="width: 100%; height: 112px; overflow: hidden;"
src="${castopod_url}/embed/light"
></iframe>
</div>`
}
</div>`;
}
if (document.querySelector("#peertube-player-visible").checked) {
html += `
<div class="player">
function makePeertubePlayer(peertube_id) {
return /* HTML */ ` <div class="player">
<iframe
sandbox="allow-same-origin allow-scripts"
src="https://video.internet-czas-dzialac.pl/videos/embed/${peertube_id}"
@ -57,12 +60,11 @@ function generateHtml() {
height="394"
frameborder="0"
></iframe>
</div>`
}
</div>`;
}
if (document.querySelector("#audio-links-visible").checked) {
html += `
<div class="podcast-logos audio-logos">
function makeAudioLinks(castopod_url) {
return /* HTML */ ` <div class="podcast-logos audio-logos">
<a
title="Link do naszego podcastowego RSSa"
alt="Logo RSS"
@ -76,7 +78,8 @@ function generateHtml() {
/>
</a>
<a
title="${document.querySelector("#episode_name").value} na naszej instancji Castopod."
title="${document.querySelector("#episode_name")
.value} na naszej instancji Castopod."
alt="Logo Castopod"
href="${castopod_url}"
>
@ -145,13 +148,14 @@ function generateHtml() {
height="48"
/>
</a>
</div>`
}
if (document.querySelector("#video-links-visible").checked) {
html += `
<div class="podcast-logos video-logos">
</div>`;
}
function makeVideoLinks(peertube_id) {
return /* HTML */ ` <div class="podcast-logos video-logos">
<a
title="${document.querySelector("#episode_name").value} na naszej instancji PeerTube."
title="${document.querySelector("#episode_name")
.value} na naszej instancji PeerTube."
alt="Logo PeerTube"
href="https://video.internet-czas-dzialac.pl/videos/watch/${peertube_id}"
>
@ -169,7 +173,7 @@ function generateHtml() {
alt="Logo Odysee"
href="${document.querySelector("#odysee").value
? document.querySelector("#odysee").value
: 'https://odysee.com/@internetczasdzialac'}"
: "https://odysee.com/@internetczasdzialac"}"
>
<img
class="logo"
@ -179,7 +183,8 @@ function generateHtml() {
/>
</a>
<a
title="${document.querySelector("#episode_name").value} w serwisie YouTube."
title="${document.querySelector("#episode_name")
.value} w serwisie YouTube."
alt="Logo YouTube"
href="${document.querySelector("#youtube").value}"
>
@ -190,13 +195,34 @@ function generateHtml() {
height="48"
/>
</a>
</div>`
</div>`;
}
function generateHtml() {
const castopod_url = getCastopodURL();
const peertube_id = getPeertubeID();
let html = "";
if (document.querySelector("#castopod-player-visible").checked) {
html += makeCastopodPlayer(castopod_url);
}
console.log('Copied to clipboard');
if (document.querySelector("#peertube-player-visible").checked) {
html += makePeertubePlayer(peertube_id);
}
if (document.querySelector("#audio-links-visible").checked) {
html += makeAudioLinks(castopod_url);
}
if (document.querySelector("#video-links-visible").checked) {
html += makeVideoLinks(peertube_id);
}
console.log("Copied to clipboard");
document.querySelector("textarea").value = html;
document.querySelector(".preview").innerHTML = html;
}
}
function copyHtml() {
@ -204,4 +230,3 @@ function copyHtml() {
navigator.clipboard.writeText(document.querySelector("textarea").value);
}
}

View File

@ -8,7 +8,8 @@
}
body {
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande",
"Lucida Sans Unicode", Geneva, Verdana, sans-serif;
color: hsl(258.8, 17.4%, 3%);
}
@ -20,7 +21,7 @@ section {
label {
margin-top: 1rem;
margin-bottom: .5rem;
margin-bottom: 0.5rem;
}
label:nth-child(1) {
@ -28,7 +29,7 @@ label:nth-child(1) {
}
fieldset {
padding: .5rem;
padding: 0.5rem;
margin-bottom: 2rem;
}
@ -52,35 +53,34 @@ h1 {
.output {
display: flex;
flex-flow: column;
height: 20vh;
}
.input-checkbox {
padding: .5rem;
padding: 0.5rem;
user-select: none;
}
input[type="checkbox"]+label {
input[type="checkbox"] + label {
cursor: pointer;
}
input[type="text"] {
font-family: 'Courier New', Courier, monospace;
font-family: "Courier New", Courier, monospace;
}
textarea {
border: 1px solid #5e636e;
padding: .5rem;
padding: 0.5rem;
overflow-y: scroll;
font-size: .5rem;
font-family: 'Courier New', Courier, monospace;
font-size: 0.5rem;
font-family: "Courier New", Courier, monospace;
width: 100%;
height: 100%;
min-height: 20vh;
margin-bottom: 1rem;
}
button {
padding: 0.25rem .5rem;
padding: 0.25rem 0.5rem;
margin-bottom: 2rem;
}
@ -114,17 +114,17 @@ section {
margin-bottom: 2rem;
}
.podcast-logos>a {
.podcast-logos > a {
margin: 0.75rem 0;
}
.podcast-logos>a,
.podcast-logos>a:hover {
.podcast-logos > a,
.podcast-logos > a:hover {
text-decoration: none !important;
box-shadow: none !important;
}
.podcast-logos>a>img {
.podcast-logos > a > img {
width: auto !important;
margin: 0 0.75rem;
max-width: 120px;