Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I saw a feature on thewpclub. net, I also want to implement it on my Wordpress blog. when you click on any download link, it will first redirect you to thewpclub. net/download and a 15 seconds countdown will happen there before the actual download link appear.

What I have tried:

I saw a code on help.gulshankumar. net/forum, I paste the code on my blog footer, but it ain't working. Please help me correct any error in the code and guide me on how to place and implement it on my blog.

See the code below.

The first script will select any links with class download-wait and change its link from “https://example.com/file.zip” to “https://yoursite.com/download?https%example.com%file.zip


JavaScript
const downloadLinks = document.querySelectorAll('.download-wait');
    downloadLinks.forEach(link => {
    const linkToFile = link.getAttribute('hrefs');
    const linkToFileEdited = linkToFile
        .replace('https://', 'https/')
        .replace(new RegExp('%', 'g'), '/');

    link.setAttribute('href', `${window.location.origin}/download/?${linkToFileEdited}`);
    });




after the user is redirected to the download page the second script will keep the user wait for 15 sec then decode the link and redirect the user to the external link.


HTML
<p style="font-size:16px;">Please wait, starting download in <strong><span id="countdown">15</span> seconds</strong></p>



<pre lang="Javascript">const query = window.location.search;
const link = query.slice(1);

const newLink = link
    .replace(new RegExp('%', 'g'), '/')
    .replace('https/', 'https://');

 // Total seconds to wait
 var seconds = 15;
 
 function countdown() {
     seconds = seconds - 1;
     if (seconds < 0) {
         // Download link
         window.location = newLink;
     } else {
         // Update remaining seconds
         document.getElementById("countdown").innerHTML = seconds;
         // Countdown wait time is 1 second
         setTimeout("countdown()", 1000);
     }
 }
 
 // Run countdown function
 countdown();
Posted
Updated 31-Dec-19 19:43pm
Comments
[no name] 5-Jan-20 0:05am    
So, you just want to suck up people's time?
Bill Mayheptad Ritchie 5-Jan-20 18:43pm    
nope, I just want to increase the page view on my blog, to increase AdSense earning, it will only be a 8 seconds waiting interveal. not much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900