You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

info-page.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. document.addEventListener("DOMContentLoaded", function(){
  2. var SwitchTime = 10; // in Seconds
  3. document.getElementById("topper").onclick = function(){
  4. window.location = "/main";
  5. }
  6. var maxPages;
  7. var currentPage = 0;
  8. var maxDisplayed = 6;
  9. async function loadPosts(){
  10. var response = await fetch("/getliveposts", {
  11. method: "GET",
  12. headers: {
  13. "Accept":"application/json",
  14. "Content-Type":"application/json"
  15. }
  16. })
  17. var data = await response.json();
  18. //console.log(data);
  19. try{
  20. showPosts(data.posts.slice(0 + (currentPage * maxDisplayed), maxDisplayed + (currentPage * maxDisplayed)));
  21. //console.log(data.posts.slice(0 + (currentPage * maxDisplayed), maxDisplayed + (currentPage * maxDisplayed)));
  22. maxPages = data.posts.length / maxDisplayed;
  23. //console.log(maxPages, currentPage+1)
  24. }catch(error){
  25. document.getElementById("content").innerHTML = ""; //empty content
  26. }
  27. };
  28. loadPosts();
  29. function showPosts(pdata){
  30. var container = document.getElementById("content"); //insert in content
  31. container.innerHTML = "" //empty content
  32. pdata.forEach(element => {
  33. var post = document.createElement("div");
  34. post.classList.add("post");
  35. post.style.backgroundColor = element.bcolor;
  36. post.innerHTML = `
  37. <div class="title" style="background-color:${element.bcolor};">
  38. <h2 class="preview-title" >${element.title}</h2>
  39. </div>
  40. <div class="body">
  41. ${element.text}
  42. </div>
  43. `
  44. container.appendChild(post)
  45. });
  46. }
  47. function startTime() {
  48. var today = new Date();
  49. var h = today.getHours();
  50. var m = today.getMinutes();
  51. var s = today.getSeconds();
  52. h = checkTime(h);
  53. m = checkTime(m);
  54. s = checkTime(s);
  55. document.getElementById('clock').innerHTML =
  56. h + ":" + m + ":" + s;
  57. var t = setTimeout(startTime, 500);
  58. }
  59. function checkTime(i) {
  60. if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
  61. return i;
  62. }
  63. startTime();
  64. function changePage(){
  65. if(maxPages > currentPage+1) {
  66. currentPage++;
  67. }
  68. else{
  69. currentPage = 0;
  70. loadPosts();
  71. }
  72. loadPosts();
  73. setTimeout(changePage, SwitchTime*1000);
  74. }
  75. changePage();
  76. });