Click here to Skip to main content
14,427,367 members
Rate this:
Please Sign up or sign in to vote.
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


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.


<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 20:43pm
Comments
Gerry Schmitz 5-Jan-20 0:05am
   
So, you just want to suck up people's time?
Mayheptad 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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100