Skip to content

Instantly share code, notes, and snippets.

@piyush-json
Created May 23, 2025 22:00
Show Gist options
  • Select an option

  • Save piyush-json/8caa807f12eca120e939c0ebdcb63ed5 to your computer and use it in GitHub Desktop.

Select an option

Save piyush-json/8caa807f12eca120e939c0ebdcb63ed5 to your computer and use it in GitHub Desktop.
;(function () {
console.log('Auto-redirect script started')
// Override the startCountdown function to complete immediately
window.startCountdown = function (
containerId,
buttonId,
duration,
onComplete
) {
console.log('Countdown bypassed for', buttonId)
// Skip the countdown and immediately complete
setTimeout(function () {
onComplete()
}, 100)
}
// Function to handle all redirections
async function handleRedirections() {
console.log('Handling redirections...')
// Step 1: Click the top button to start the process
if (document.getElementById('topButton')) {
console.log('Clicking top button...')
document.getElementById('topButton').click()
// Wait a moment for any state changes
await new Promise((resolve) => setTimeout(resolve, 500))
// If the button becomes enabled again, click it once more (for second phase)
if (
document.getElementById('topButton') &&
!document.getElementById('topButton').hasAttribute('disabled')
) {
console.log('Clicking top button again...')
document.getElementById('topButton').click()
}
}
// Step 2: Wait for bottom button to appear and click it
await new Promise((resolve) => {
const checkBottomButton = setInterval(() => {
if (
document.getElementById('bottomButton') &&
document.getElementById('bottomButton').style.display !== 'none'
) {
clearInterval(checkBottomButton)
console.log('Bottom button found, clicking...')
document.getElementById('bottomButton').click()
resolve()
}
}, 300)
})
// Step 3: Wait for the open-link element to appear
await new Promise((resolve) => {
const checkOpenLink = setInterval(() => {
if (document.getElementById('open-link')) {
clearInterval(checkOpenLink)
// Extract the target URL
if (typeof tagrget_url !== 'undefined') {
console.log('Found target URL, attempting to redirect...')
// Set cookie and redirect directly
setCookiee('user_step', '1', 1)
try {
const decodedUrl = atob(tagrget_url)
console.log('Redirecting to:', decodedUrl)
window.location.href = decodedUrl
} catch (e) {
console.error('Failed to decode URL:', e)
// As fallback, click the link normally
document.getElementById('open-link').click()
}
} else {
console.log('Target URL not found, clicking link manually...')
document.getElementById('open-link').click()
}
resolve()
}
}, 300)
})
}
// Wait for page to be fully loaded before starting
if (document.readyState === 'complete') {
handleRedirections()
} else {
window.addEventListener('load', handleRedirections)
}
// Also handle possible pop-ups or modal windows
const closePopups = setInterval(() => {
// Close any popup that might appear
const closeButtons = document.querySelectorAll('.close-btn, .remove-sticky')
closeButtons.forEach((button) => {
if (button && button.style.display !== 'none') {
console.log('Closing popup/modal...')
button.click()
}
})
}, 1000)
// Clear popup checker after 30 seconds
setTimeout(() => {
clearInterval(closePopups)
}, 30000)
})()

Comments are disabled for this gist.