简体   繁体   中英

Inexperienced to code, need help adding to an HTML script

I'm doing some volunteer work for a local church by helping manage their website that they just migrated over to Squarespace. They want to do some advanced stuff that require code injection that I have little to no knowledge on how to do. That being said, I've had success copy+pasting certain code, like this HTML countdown timer that I found below. I'm looking for anyone who might be able to help me get this script to loop on a weekly basis, counting down to 10AM every Sunday without having to go in and change the date every week. Is there someone that may be able to help me here? Squarespace doesn't provide support for code injection. Thank you!

*Also, FYI, haven't had much luck injecting other code besides html. the site doesn't want to take it for some reason.


<!-- Display the countdown timer in an element -->
<p id="demo"></p>

<script>
// Set the date we're counting down to
var countDownDate = new Date("Jan 5, 2022 15:37:25").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

  // Get today's date and time
  var now = new Date().getTime();

  // Find the distance between now and the count down date
  var distance = countDownDate - now;

  // Time calculations for days, hours, minutes and seconds
  var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  var seconds = Math.floor((distance % (1000 * 60)) / 1000);

  // Display the result in the element with id="demo"
  document.getElementById("demo").innerHTML = days + "d " + hours + "h "
  + minutes + "m " + seconds + "s ";

  // If the count down is finished, write some text
  if (distance < 0) {
    clearInterval(x);
    document.getElementById("demo").innerHTML = "EXPIRED";
  }
}, 1000);
</script>

You want to set the countDownDate date to be the first upcoming Sunday. You can use the solution this answer: https://codereview.stackexchange.com/a/33648 to find it.


I am not entirely sure what you mean with "injecting html". It seems that you are just adding some javascript to your Squarespace website. Code injection is when you store invalid data in a program such that it executes this data. See https://en.m.wikipedia.org/wiki/Code_injection for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM