convert est déprécié au profit de magick
This commit is contained in:
parent
50e6e46787
commit
c4c1944d71
2 changed files with 75 additions and 28 deletions
|
@ -1,18 +1,26 @@
|
|||
|
||||
|
||||
// ==UserScript==
|
||||
// @name Breizh autoplay
|
||||
// @version 1
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 2024-04-10
|
||||
// @description Add an audio player for audio files on fichiers.breizh.pm
|
||||
// @author Eldeberen
|
||||
// @match https://fichiers.breizh.pm/*
|
||||
// @grant none
|
||||
// @include https://fichiers.breizh.pm/*
|
||||
// ==/UserScript==
|
||||
|
||||
|
||||
// Add current song to history
|
||||
function ap_add2history(event) {
|
||||
ap_history.push(event.target);
|
||||
}
|
||||
|
||||
// Play the next track
|
||||
function ap_next(event) {
|
||||
let item = event.target;
|
||||
let autoplay = document.getElementById("ap-autoplay").checked;
|
||||
let item = ap_history.at(-1);
|
||||
let autoplay = document.getElementById("ap-player").open;
|
||||
let random = document.getElementById("ap-random").checked;
|
||||
let loop = document.getElementById("ap-loop").checked;
|
||||
let currentId = medias.indexOf(item);
|
||||
let currentId = ap_medias.indexOf(item);
|
||||
let nextId = -1;
|
||||
|
||||
// If no autoplay, exit
|
||||
|
@ -22,43 +30,82 @@ function ap_next(event) {
|
|||
// Note that this should not happen in a regular use
|
||||
if(currentId == -1) return;
|
||||
|
||||
// Make sure to pause the current track
|
||||
item.pause();
|
||||
|
||||
// If random, pick a random song in the list
|
||||
// Else pick the next one
|
||||
if(random) {
|
||||
nextId = Math.floor(Math.random() * medias.length);
|
||||
nextId = Math.floor(Math.random() * ap_medias.length);
|
||||
} else {
|
||||
nextId = currentId + 1;
|
||||
}
|
||||
|
||||
// If looping, stay in the range
|
||||
if(loop) {
|
||||
nextId %= medias.length;
|
||||
nextId %= ap_medias.length;
|
||||
}
|
||||
|
||||
// If the next song is out, exit
|
||||
if(nextId == medias.length) return;
|
||||
if(nextId == ap_medias.length) return;
|
||||
|
||||
// Finally, set the volume back and jump to the selected song
|
||||
medias[nextId].volume = item.volume;
|
||||
medias[nextId].play();
|
||||
ap_medias[nextId].volume = item.volume;
|
||||
ap_medias[nextId].play();
|
||||
}
|
||||
|
||||
// Play/pause current
|
||||
function ap_playpause() {
|
||||
if(ap_paused == null) {
|
||||
ap_paused = ap_history.pop();
|
||||
ap_paused.pause();
|
||||
} else {
|
||||
ap_paused.play();
|
||||
ap_paused = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Play previous song
|
||||
function ap_prev() {
|
||||
let current = ap_history.pop();
|
||||
let prev = ap_history.pop();
|
||||
current.pause();
|
||||
prev.currentTime = 0;
|
||||
prev.play();
|
||||
}
|
||||
// Get all audio medias on the page
|
||||
let medias = Array.from(document.querySelectorAll("audio"));
|
||||
let ap_medias = Array.from(document.querySelectorAll("audio"));
|
||||
|
||||
// Define a playing history
|
||||
let ap_history = [];
|
||||
let ap_paused = null;
|
||||
|
||||
// If there is at least one media
|
||||
if(medias.length > 0) {
|
||||
if(ap_medias.length > 0) {
|
||||
// Create the menu
|
||||
var ap_menu = document.createElement("div");
|
||||
ap_menu.id = "ap-menu";
|
||||
ap_menu.innerHTML = `<label for="ap-autoplay">Autoplay</label><input type="checkbox" id="ap-autoplay" />
|
||||
ap_menu.id = "ap-manu";
|
||||
ap_menu.innerHTML = `<details id="ap-player">
|
||||
<summary>Player</summary>
|
||||
<button id="ap-prev">⏮</button>
|
||||
<button id="ap-playpause">⏯</button>
|
||||
<button id="ap-next">⏭</button>
|
||||
<label for="ap-random">Aléatoire</label><input type="checkbox" id="ap-random" />
|
||||
<label for="ap-loop">Boucle</label><input type="checkbox" id="ap-loop" />`;
|
||||
<label for="ap-loop">Boucle</label><input type="checkbox" id="ap-loop" />
|
||||
</details>`;
|
||||
document.querySelector("body").insertBefore(ap_menu, document.getElementById("maintable"));
|
||||
|
||||
// Add event listeners
|
||||
[["ap-prev", ap_prev],
|
||||
["ap-playpause", ap_playpause],
|
||||
["ap-next", ap_next]].map((e) => {
|
||||
document.getElementById(e[0]).addEventListener("click", e[1]);
|
||||
});
|
||||
|
||||
// Apply the event listener to all medias
|
||||
medias.map(function(e) {
|
||||
ap_medias.map(function(e) {
|
||||
e.addEventListener("ended", ap_next);
|
||||
e.addEventListener("play", ap_add2history);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -184,7 +184,7 @@ do
|
|||
if [[ ! -f "${cache}/${thumbname}" ]] && [[ ${kbytes} -le 20480 ]] && [[ ! ${i} =~ \.v2m$ ]]
|
||||
then
|
||||
# Création de la miniature
|
||||
convert "${i}" -strip -thumbnail 'x60>' "${cache}/${thumbname}"
|
||||
magick "${i}" -strip -thumbnail 'x60>' "${cache}/${thumbname}"
|
||||
fi
|
||||
|
||||
# Si une miniature est présente, on l'affiche
|
||||
|
|
Loading…
Reference in a new issue