Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

In order to implement dynamic data substitution on your LHT, use the scripts presented below

There are 3 types of scripts that perform different actions:

  1. substitutes today's date. Video about the operation and configuration of script number 1 -

https://youtu.be/NpOGP8ealjk
  1. counts down how many days are left until the webinar and displays the text “today/tomorrow/3 days/4 days/5 days, etc.”. Explanation of script number 2 -

https://youtu.be/d3OkWHDdCIw
  1. A timer that is displayed in the format “HH:MM:SS” or “DD:HH:MM:SS“. When the timer expires, it will redirect to the link you specified. Resistant to page refreshes and opening in an adjacent tab. Video explaining the operation and configuration of this script:

https://youtu.be/0tQX-WWxVHA

NOTE! To place a script, you need to select “source” in the LGT, add a script, click “source” again and only then save the LGT. The video, which you can find under the script, shows how to do this.

  1. substitutes today's date

Web will be available today - <span id="today">today</span>

<script>

var today = document.getElementById('today');

var webDate = new Date();

var month = webDate.getMonth()+1;

var day = webDate.getDate();

today.innerText = (day < 10 ?'0'+day : day)+'.'+ (month<10 ?"0"+month : month);

</script>

<span id="today">today</span> - you need to write in the place of the text on LGT where you want today's date to be

  1. counts down how many days are left until the webinar

<span id="day_before_web">через 110 дней</span>  

<script>

var one_day = 1000 * 60 * 60 * 24;

var presentDate = new Date(new Date().setHours(0, 0,0,0))

var dayBeforeWebDate = new Date('2021-01-28');

if(document.getElementById('web_at')){document.getElementById('web_at').innerText = dayBeforeWebDate.toLocaleDateString('ru');}

var result = (Math.round(dayBeforeWebDate.getTime() - presentDate.getTime()) / (one_day)).toFixed(0);

var finalResult = "через " + result + " дней";

if(result == 0) {

finalResult = "СЕГОДНЯ!";

} else{

if(result == 1){

finalResult = "ЗАВТРА!";

} else {

var dec = 0;

finalResult = 'через ' + result + ' ' + ((((dec = result%100) >= 11 && dec <= 19) || (dec = result%10) >= 5 || dec == 0) ? 'дней' :  (dec == 1 ? 'день' : 'дня'));

}}
document.getElementById('day_before_web').innerText= finalResult;
</script>

<span id="day_before_web">через 110 дней</span>  - insert in the place of the text where you want it to be displayed after how long


var dayBeforeWebDate = new Date('2021-01-28'); - set the date for the webinar

  1. counts how many days are left and redirects to the link you specified

<span id="timer">00:00</span> - insert in the place you want to display the time in LGT


<script>

  var counterUrl = 'https://www.google.com';

  var cookieName = 'timer-test';

  var counterStartDate = new Date();

  var counterIds = [

    'timer',

  ];

  var needTime = new Date();

  var withDays = false;

  var dateText = {};

  var MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;

  var MILLISECONDS_IN_HOUR = 60 * 60 * 1000;

  var MILLISECONDS_IN_MINUTES = 60 * 1000;

  var MILLISECONDS_IN_SECONDS = 1000;

  var shiftToEnd = {

    days   : 2,

    hours  : 0,

    minutes: 0,

    seconds: 0,

  };

  var dateToDisplay = {};

  function setCookie(cname, cvalue, exdays) {

    var d = new Date();

    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));

    var expires = 'expires=' + d.toUTCString();

    document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/';

  }

  function getCookie(cname) {

    var name = cname + '=';

    var ca = document.cookie.split(';');

    for (var i = 0; i < ca.length; i++) {

      var c = ca[i];

      while (c.charAt(0) === ' ') {

        c = c.substring(1);

      }

      if (c.indexOf(name) === 0) {

        return c.substring(name.length, c.length);

      }

    }

    return '';

  }

  function checkCookie() {

    var counter = getCookie(cookieName);

    if (counter !== '') {

      counterStartDate = new Date(+counter);

    } else {

      setCookie(cookieName, counterStartDate.getTime(), 365);

    }

  }

  function countShiftInMilliSeconds(shift) {

    var result = 0;

    result += shift.days * MILLISECONDS_IN_DAY;

    result += shift.hours * MILLISECONDS_IN_HOUR;

    result += shift.minutes * MILLISECONDS_IN_MINUTES;

    result += shift.seconds * MILLISECONDS_IN_SECONDS;

    return result;

  }

  function millisecondsInShift(timeInMilliseconds) {

    if (withDays) {

      dateToDisplay.days = Math.floor(timeInMilliseconds / MILLISECONDS_IN_DAY);

      timeInMilliseconds -= dateToDisplay.days * MILLISECONDS_IN_DAY;

    }

    dateToDisplay.hours = Math.floor(timeInMilliseconds / MILLISECONDS_IN_HOUR);

    timeInMilliseconds -= dateToDisplay.hours * MILLISECONDS_IN_HOUR;

    dateToDisplay.minutes = Math.floor(timeInMilliseconds / MILLISECONDS_IN_MINUTES);

    timeInMilliseconds -= dateToDisplay.minutes * MILLISECONDS_IN_MINUTES;

    dateToDisplay.seconds = Math.floor(timeInMilliseconds / MILLISECONDS_IN_SECONDS);

  }

  function prepateTime(text) {

    return ('' + text).length < 2 ? '0' + text : text;

  }

    function displayTime(time) {

      if (time < 0) {

        time = 0;

      }

      millisecondsInShift(time);

      var dateToDisplayString = (withDays ? prepateTime(dateToDisplay.days) + ':' : '')

        + prepateTime(dateToDisplay.hours)

        + ':'

        + prepateTime(dateToDisplay.minutes)

        + ':'

        + prepateTime(dateToDisplay.seconds);

counterElements.forEach(function (counterElement) {

        counterElement.innerHTML = dateToDisplayString;

        

      });

    }

    var counterElements = counterIds.map(function(counterElementId){

      return document.getElementById(counterElementId);

    });

    checkCookie();

    needTime = counterStartDate.getTime();

    var now = new Date();

    var milisecondsShift = countShiftInMilliSeconds(shiftToEnd);

    needTime = needTime + milisecondsShift - now.getTime();

    if (needTime < 0) {

      window.location = counterUrl;

    }

    displayTime(needTime);

    setInterval(function () {

      needTime -= MILLISECONDS_IN_SECONDS;

      displayTime(needTime);

      if (needTime < 0) {

        window.location = counterUrl;

      }

    }, 1000);

</script>

var counterUrl = 'https://www.google.com'; - where to redirect

  var cookieName = 'timer-test'; - write any unique name instead of timer-test


 var shiftToEnd = {

    days   : 2,

    hours  : 0,

    minutes: 0,

    seconds: 0,

  };


How long after a person visits the page will a redirect occur?


  • No labels