This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/handle_mp3/script.js
2024-01-28 21:24:21 +00:00

30 lines
960 B
JavaScript

document.addEventListener("DOMContentLoaded", () => {
let main_image = document.getElementById("main_image");
if (main_image) {
main_image.setAttribute("volume", 0.25);
}
let base_href = document.body.getAttribute("data-base-href");
let audio_src = document.getElementById("audio_src");
if (audio_src) {
let ilink = audio_src.getAttribute("src");
window.jsmediatags.read(location.origin + base_href + ilink, {
onSuccess: function (tag) {
var artist = tag.tags.artist,
title = tag.tags.title;
document.getElementById("audio-title").innerText = title;
document.getElementById("audio-artist").innerText = artist;
document
.getElementById("audio-download")
.setAttribute(
"download",
(artist + " - " + title).substring(0, 250) + ".mp3",
);
},
onError: function (error) {
console.log(error);
},
});
}
});