Skip to content
This repository has been archived by the owner on Dec 24, 2024. It is now read-only.

Commit

Permalink
fix: prevent an resize on file with number in name
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Jan 2, 2024
1 parent 5a02ac0 commit ad9d2c9
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/js/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,42 @@ if (header_links) {
);
}
}

function getHeightWidth(alt) {
/**
*
* @param {string} alt
* @param {number} originalWidth
* @param {number} originalHeight
* @returns number[]
*/
function getHeightWidth(alt, originalWidth, originalHeight) {
const heightXwidthReg = new RegExp("\\d+x\\d+");
const widthReg = new RegExp("\\d+");
if (alt.match(heightXwidthReg)) {
var width = parseInt(alt.split("x")[0]);
var height = parseInt(alt.split("x")[1]);
const width = parseInt(alt.split("x")[0]);
const height = parseInt(alt.split("x")[1]);
return [width, height];
} else if (alt.match(widthReg)) {
var width = parseInt(alt.match(widthReg)[0]);
return [width, 0];
const width = parseInt(alt.match(widthReg)[0]);
return [width, originalHeight];
} else {
return [0, 0];
return [originalWidth, originalHeight];
}
}

const p_img = /\.+\\/gi;
for (const i of document.querySelectorAll("img")) {
const regAlt = new RegExp("\\|");
const alt = i.alt;
if (alt.match(regAlt)) {
const altSplitted = alt.split("|");
for (const part of altSplitted) {
if (part.match(new RegExp("\\d+", "g"))) {
var size = getHeightWidth(part);
var size = getHeightWidth(part, i.width, i.height);
i.width = size[0] > 0 ? size[0] : i.width;
i.height = size[1] > 0 ? size[1] : i.height;
var partReg = new RegExp(`\\${part}`);
i.alt = alt.replace(partReg, "");
}
}
} else if (alt.match(/\d+/g)) {
var size = getHeightWidth(alt);
i.width = size[0] > 0 ? size[0] : i.width;
i.height = size[1] > 0 ? size[1] : i.height;
i.alt = alt.replace(p_img, "");
}
}

Expand Down

0 comments on commit ad9d2c9

Please sign in to comment.