1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#container {
display: grid;
grid-template-columns: repeat(2, 1fr);
column-gap: 4em;
margin: 0 auto;
width: max-content;
}
.liste {
width: 500px;
height: 400px;
border: 1px solid black;
overflow: scroll;
}
</style>
</head>
<body>
<div id="container">
<div id="cf" class="liste"></div>
<div id="vf" class="liste"></div>
</div>
<div style="width: 100%; text-align: center; margin-top: 20px;">
<button onclick="trier()" style=" width: 150px; height: 35px;cursor: pointer;">Trier</button>
</div>
<script>
// l'array pages sont les URLs des pages
let pages = ["page.html?numerodefilm=001_2024_cf.jpg", "page.html?numerodefilm=005_2024_cf.jpg", "page.html?numerodefilm=003_2024_vf.jpg",
"page.html?numerodefilm=021_2023_cf.jpg", "nul", "page.html?numerodefilm=012_2024_vf.jpg", "page.html?numerodefilm=030_2024_cf.jpg",
"page.html?numerodefilm=040_2024_vf.jpg", "page.html?numerodefilm=051_2024_vf.jpg", "ici rien",
"page.html?numerodefilm=015_2024_vf.jpg", "page.html?numerodefilm=099_2024_cf.jpg", "page.html?numerodefilm=229_2024_cf.jpg"];
function trier() {
let x, srt, position, tdf, tmp;
for (x = 0; x < pages.length; x += 1) { // on boucle
srt = pages[x]; // page[0]="page.html?numerodefilm=001_2024_cf.jpg", pages[1]="page.html?numerodefilm=005_2024_cf.jpg", ect..
// Si "_cf" est présent dans pages[x] sinon c'est "_vf" qui sera alors normalement présent
srt.indexOf("_cf") != -1 ? position = srt.indexOf("_cf") : position = srt.indexOf("_vf");
if (position != -1) { // Si position n'est pas égale à -1, "_cf" ou "_vf" ont été trouvés
tmp = srt.substring((position + 1), (position + 3)); // La variable tmp contiendra "vf" ou "cf"
tmp == "cf" ? tdf = "Ciné" : tdf = "Vidéo";// Si "cf" alors tdf="Ciné" sinon tdf="Vidéo"
// Affichage dans la <div> id="cf" ou id="vf"
document.getElementById(tmp).innerHTML +=
"<ul><li>Type film: " + tdf + " film</li><li>URL: " + pages[x] + "</li></ul>";
}
}
}
</script>
</body>
</html> |
Partager