feat: generate podcast url from an archvie url and copy it to clipboard
This commit is contained in:
parent
9b8672230f
commit
4c743dc452
2 changed files with 89 additions and 10 deletions
|
@ -13,3 +13,79 @@ import "../css/app.scss"
|
||||||
// import socket from "./socket"
|
// import socket from "./socket"
|
||||||
//
|
//
|
||||||
import "phoenix_html"
|
import "phoenix_html"
|
||||||
|
|
||||||
|
window.onload = function () {
|
||||||
|
document.getElementById('archiveUrlInput').addEventListener('keydown', function(event) {
|
||||||
|
setTimeout(function () { generatePodcastUrl(); }, 100)
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('copiaRss').addEventListener('click', function(event) {
|
||||||
|
setTimeout(function () { copyToClipboard(fetchPodcastUrl()); }, 100)
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function fetchArchiveUrl() {
|
||||||
|
return document.getElementById("archiveUrlInput").value.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchPodcastUrl() {
|
||||||
|
return document.getElementById("podcastUrl").value.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function generatePodcastUrl() {
|
||||||
|
const archiveUrl = fetchArchiveUrl();
|
||||||
|
if (!validateArchiveUrl(archiveUrl)) {
|
||||||
|
document.getElementById("podcastUrl").value = "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = new URL(archiveUrl);
|
||||||
|
const podcastName = url.pathname.split("/").slice(-1).pop();
|
||||||
|
const podcastUrl = "https://openpod.abbiamoundominio.org/podcast/" + podcastName;
|
||||||
|
|
||||||
|
document.getElementById("podcastUrl").value = podcastUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateArchiveUrl(url) {
|
||||||
|
try {
|
||||||
|
const archiveUrl = new URL(url);
|
||||||
|
|
||||||
|
var urlPattern = new RegExp("(http|https)://archive.org/details/[a-zA-Z0-9_-]*$")
|
||||||
|
if (!urlPattern.test(url) ){
|
||||||
|
throw 'Paste and archive.org url';
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyToClipboard(text) {
|
||||||
|
if (window.clipboardData && window.clipboardData.setData) {
|
||||||
|
// Internet Explorer-specific code path to prevent textarea being shown while dialog is visible.
|
||||||
|
return clipboardData.setData("Text", text);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
|
||||||
|
var textarea = document.createElement("textarea");
|
||||||
|
textarea.textContent = text;
|
||||||
|
textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in Microsoft Edge.
|
||||||
|
document.body.appendChild(textarea);
|
||||||
|
textarea.select();
|
||||||
|
try {
|
||||||
|
return document.execCommand("copy"); // Security exception may be thrown by some browsers.
|
||||||
|
}
|
||||||
|
catch (ex) {
|
||||||
|
console.warn("Copy to clipboard failed.", ex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
document.body.removeChild(textarea);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// archiveUrlInput
|
||||||
|
// https://archive.org/details/uau-pod
|
||||||
|
// https://openpod.abbiamoundominio.org/podcast/il-mio-podcast
|
||||||
|
|
|
@ -55,25 +55,26 @@
|
||||||
<span class="emoji">🥳</span>
|
<span class="emoji">🥳</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-8 col-12 py-3">
|
<div class="col-md-8 col-12 py-3">
|
||||||
<form>
|
<form id="podcastUrlGenerationForm">
|
||||||
<div class="form-group m-0">
|
<div class="form-group m-0">
|
||||||
<label for="exampleInputEmail1">
|
<label for="archiveUrlInput">
|
||||||
<span class="text-danger"
|
<span class="text-danger">Genera il feed RSS del tuo podcast</span>
|
||||||
>Genera il feed RSS del tuo podcast</span
|
|
||||||
>
|
|
||||||
pronto per la distribuzione su tutti i servizi e app di
|
pronto per la distribuzione su tutti i servizi e app di
|
||||||
podcasting! Incolla qui sotto il link al tuo <i>item</i> su
|
podcasting! Incolla qui sotto il link al tuo <i>item</i> su
|
||||||
<a href="https://archive.org" target="_blank">archive.org</a>
|
<a href="https://archive.org" target="_blank">archive.org</a>
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
class="form-control mb-3"
|
id="archiveUrlInput"
|
||||||
id="exampleInputEmail1"
|
name="archiveUrlInput"
|
||||||
|
type="url"
|
||||||
placeholder="es: https://archive.org/details/il-mio-podcast"
|
placeholder="es: https://archive.org/details/il-mio-podcast"
|
||||||
|
pattern="https://archive.org/details/.*" size="30" required
|
||||||
|
class="form-control mb-3"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<button
|
<button
|
||||||
|
id="copiaRss"
|
||||||
class="btn btn-danger btn-rss text-uppercase"
|
class="btn btn-danger btn-rss text-uppercase"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
@ -81,10 +82,12 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
|
id="podcastUrl"
|
||||||
|
name="podcastUrl"
|
||||||
type="text"
|
type="text"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
disabled
|
disabled
|
||||||
value="https://openpod.abbiamoundominio.org/podcast/il-mio-podcast"
|
value=""
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue