Skip to content

Instantly share code, notes, and snippets.

@MelanieS
Created June 12, 2023 23:30
Show Gist options
  • Save MelanieS/23ac3c2cebe4e86f62ead25d5b6c8fb0 to your computer and use it in GitHub Desktop.
Save MelanieS/23ac3c2cebe4e86f62ead25d5b6c8fb0 to your computer and use it in GitHub Desktop.
// Check if page contains the text "Maternal side"
function checkPage(url, element, callback) {
let newTab = window.open(url, "_blank");
newTab.addEventListener("load", function onTabLoad() {
newTab.removeEventListener("load", onTabLoad);
let isMaternal = newTab.document.body.textContent.includes("Maternal side");
callback(isMaternal, element, newTab);
});
}
window.addEventListener("load", (event) => {
// Select all 'a' elements
let links = document.querySelectorAll("a");
// Filter to only those with href starting with 'http://somewebsite.com/' and containing '/match/'
let matches = Array.from(links).filter(
(link) =>
link.href.startsWith("http://somewebsite.com/") &&
link.href.includes("/match/")
);
// Iterate over each match
let i = 0;
function openNextTab() {
if (i < matches.length) {
let match = matches[i];
// Create a random delay between 1 and 4 seconds
let delay = Math.random() * 8000;
checkPage(match.href, match, function (isMaternal, element, newTab) {
if (isMaternal) {
newTab.close(); // Close the match tab
let databaseTab = window.open("https://melaniesdatabase.com/something.aspx");
databaseTab.focus(); // Focus on the database tab
// Locate the delete button associated with this element and click it
let deleteButton = element.parentNode.querySelector(
'input[title="Delete"]'
);
if (deleteButton) {
deleteButton.click();
}
} else {
newTab.close(); // Close the match tab
}
i++;
setTimeout(openNextTab, delay);
});
}
}
openNextTab();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment