Skip to content

Instantly share code, notes, and snippets.

@icantrank
Created August 20, 2024 14:40
Show Gist options
  • Save icantrank/e28943d23d752e0c4453c40777d89ea2 to your computer and use it in GitHub Desktop.
Save icantrank/e28943d23d752e0c4453c40777d89ea2 to your computer and use it in GitHub Desktop.
<script>
(function () {
// return false if the query string does not contain a camp parameter
if (window.location.search.indexOf('camp=') === -1) return
// get the camp parameter value
let camp = window.location.search.split('camp=')[1].split('&')[0]
// get all links containing get.verisure
let links = document.querySelectorAll('a[href*="get.verisure"]')
// loop through all links
Array.from(links).forEach(link => {
// get the href value
let href = link.getAttribute('href')
// remove the old camp parameter from the href value
href = href.replace(/[?&]camp=[^&]*/, '')
// add the camp parameter to the href value if it's not already present
if (!href.includes('?')) href += `?camp=${camp}`
else if (!href.includes('camp=')) href += `&camp=${camp}`
// set the new href value
link.setAttribute('href', href)
})
})()
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment