I am updating a greasemonkey script: [code] Before, the document.evaluate would use…
- User
I am updating a greasemonkey script:
code// New code to download all images found // image class: fui-Image const imageButtons = document.evaluate( "//*[@id='root']/div/div/div/div[3]/div[3]/div/div/div", // "/html/body/div[1]/div/div/div/div[3]/div[3]/div/div/div[1]/button", //"/html/body/div[1]/div/div/div/div[3]/div[3]/div/div/div[1]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null ); const numImages = imageButtons.snapshotLength; console.logWithTimestamp(`What did we find? numImages=${numImages}`); for (let i = 0; i < numImages; i++) { console.logWithTimestamp(`Pressing image ${i + 1}`); const button = imageButtons.snapshotItem(i); button.click(); await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait for 5 seconds console.logWithTimestamp("Pressing download"); await clickElementContainingText("Download", "button"); await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait for 5 seconds console.logWithTimestamp("Testing for second download button."); //if (await clickSecondDownloadButton()) { // await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait for 5 seconds //} try { await clickSecondDownloadButtonText(); } catch (error) { console.error("Error while clicking the second download button:", error); } await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait for 5 seconds console.logWithTimestamp("Pressing close"); await clickElementByAttributeText("Close", "button", "aria-label"); await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait for 5 seconds } } - Assistant
To build a list of button elements based on the
data-testidattribute value that matches the pattern "media-asset-tile-{image_number}" and click on each button, you can use thedocument.querySelectorAllmethod with an attribute selector.Given the updated HTML structure, you can modify the Greasemonkey script to find and click on the button elements inside each . Here's an updated version of the relevant parts of your script: