const tweetId = location.pathname.match(/status\/([0-9]+)/)[1]; const imgElements = document.querySelectorAll(`a[href*="${tweetId}"] img`); let imgArray = new Array(); for (const imgElement of imgElements) { let imgSrc = imgElement .getAttribute("src") .replace(/\?format=/, ".") .replace(/&.+/, ""); imgArray.push(imgSrc); }