move the snippet into a fn
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending

This commit is contained in:
Mylloon 2023-04-24 15:59:29 +02:00
parent cfb21e7dcb
commit 40f038bfb9
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -1,33 +1,39 @@
for (const item of document.getElementsByTagName("img")) { window.addEventListener("load", () => main());
// Check if we may need to resize the image
const possible_piece = item.alt.split(/\s?\|\s?/); const main = () => {
if (possible_piece.length > 1) { for (const item of document.getElementsByTagName("img")) {
// Check if 1 or 2 dimension(s) is provided // Check if we may need to resize the image
// Then, check if syntax is correct const possible_piece = item.alt.split(/\s?\|\s?/);
// if (possible_piece.length > 1) {
// If everything is good, assign the width and/or the height // Check if 1 or 2 dimension(s) is provided
// to the image and remove the resize data from the alt text // Then, check if syntax is correct
const last_possible_piece = //
possible_piece[possible_piece.length - 1].trim(); // If everything is good, assign the width and/or the height
// Remove the resize data from the list // to the image and remove the resize data from the alt text
possible_piece.pop(); const last_possible_piece =
if (last_possible_piece.includes("x")) { possible_piece[possible_piece.length - 1].trim();
const verif = last_possible_piece.split(/\d+/); // Remove the resize data from the list
if ( possible_piece.pop();
verif.length == 3 && if (last_possible_piece.includes("x")) {
verif[0] == "" && const verif = last_possible_piece.split(/\d+/);
verif[1] == "x" && if (
verif[2] == "" verif.length == 3 &&
) { verif[0] == "" &&
[item.width, item.height] = last_possible_piece.split("x"); verif[1] == "x" &&
item.alt = possible_piece.join(""); verif[2] == ""
} ) {
} else { [w, h] = last_possible_piece.split("x");
const verif = last_possible_piece.split(/\d+/); item.width = w;
if (verif.length == 2 && verif[0] == "" && verif[1] == "") { item.height = h;
item.width = last_possible_piece; item.alt = possible_piece.join("");
item.alt = possible_piece.join(""); }
} else {
const verif = last_possible_piece.split(/\d+/);
if (verif.length == 2 && verif[0] == "" && verif[1] == "") {
item.width = last_possible_piece;
item.alt = possible_piece.join("");
}
} }
} }
} }
} };