简体   繁体   English

缺乏编码经验,需要帮助添加到 HTML 脚本

[英]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.我通过帮助管理他们刚刚迁移到 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.话虽如此,我已经成功复制+粘贴某些代码,例如我在下面找到的这个 HTML 倒数计时器。 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.我正在寻找任何能够帮助我让这个脚本每周循环播放的人,每周日倒计时到上午 10 点,而不必每周输入 go 并更改日期。 Is there someone that may be able to help me here?有没有人可以在这里帮助我? Squarespace doesn't provide support for code injection. Squarespace 不支持代码注入。 Thank you!谢谢!

*Also, FYI, haven't had much luck injecting other code besides html. *另外,仅供参考,除了 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.您希望将countDownDate日期设置为即将到来的第一个星期日。 You can use the solution this answer: https://codereview.stackexchange.com/a/33648 to find it.您可以使用这个答案的解决方案: https://codereview.stackexchange.com/a/33648来找到它。


I am not entirely sure what you mean with "injecting html".我不完全确定“注入 html”是什么意思。 It seems that you are just adding some javascript to your Squarespace website.您似乎只是在 Squarespace 网站上添加了一些 javascript。 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.有关更多信息,请参阅https://en.m.wikipedia.org/wiki/Code_injection

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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