document.addEventListener("DOMContentLoaded", function () {
const links = document.querySelectorAll('.linksblock a');
links.forEach(link => {
const href = link.getAttribute('href');
if (href) {
if (!href.includes('?=PAT')) {
// Check if URL already has a query string
const separator = href.includes('?') ? '&' : '?';
link.setAttribute('href', href + separator + '=PAT');
}
}
});
});
Just add above java script code to your html.
const links = document.querySelectorAll('.linksblock a');
will get all the elements inside with class linksblock,
links.forEach(link => {}
Above code Loops through each element found
if (href) {
Above code Checks that the href isn't null or empty
if (!href.includes('?=PAT')) {
** Above code Ensures ?=PAT is not already present, this is to avoid duplicating.**
const separator = href.includes('?') ? '&' : '?';
link.setAttribute('href', href + separator + '=PAT');
Above code Updates the link’s href by adding ?=PAT or &=PAT at the end
Let me know if you need further explination to the code? or any other issues if your having?