// Get the like button and unlike button elements
const likeButton = document.getElementById('like-button');
const unlikeButton = document.getElementById('unlike-button');

// Set the initial state of the like button and unlike button based on the value of the "like" cookie
if (getCookie('like') === 'true') {
  likeButton.style.display = 'none';
  unlikeButton.style.display = 'inline-block';
} else {
  likeButton.style.display = 'inline-block';
  unlikeButton.style.display = 'none';
}

// Add a click event listener to the like button
likeButton.addEventListener('click', function() {
  // Set the "like" cookie to "true"
  setCookie('like', 'true', 365);
  // Update the button display
  likeButton.style.display = 'none';
  unlikeButton.style.display = 'inline-block';
});

// Add a click event listener to the unlike button
unlikeButton.addEventListener('click', function() {
  // Set the "like" cookie to "false"
  setCookie('like', 'false', 365);
  // Update the button display
  likeButton.style.display = 'inline-block';
  unlikeButton.style.display = 'none';
});

// Function to get a cookie value
function getCookie(name) {
  const value = `; ${document.cookie}`;
  const parts = value.split(`; ${name}=`);
  if (parts.length === 2) return parts.pop().split(';').shift();
}

// Function to set a cookie
function setCookie(name, value, days) {
  const date = new Date();
  date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  const expires = `expires=${date.toUTCString()}`;
  document.cookie = `${name}=${value};${expires};-Path=/`;
}
1
John.McCarthy Sweet sweet code
Dec 24, 2022 at 5:29 pm · Reply
 
12
1
John.McCarthy dfdfg
Dec 13, 2022 at 4:17 pm · Reply
1
John.McCarthy photo comment
Dec 13, 2022 at 5:46 pm · Reply · Photo
0
John.McCarthy John.McCarthy post reply on image
Dec 13, 2022 at 6:43 pm · Reply · Photo
0
John.McCarthy John.McCarthy photo reply
Dec 13, 2022 at 6:40 pm · Reply · Photo
1
John.McCarthy test
Dec 13, 2022 at 6:30 pm · Reply
1
John.McCarthy post comment
Dec 13, 2022 at 6:39 pm · Reply
1
John.McCarthy John.McCarthy post reply on non-image
Dec 13, 2022 at 6:51 pm · Reply
 
Please login to add new posts.
 

California

State

7 Subscribers
7 Posts
California, United States
Parent Community

United States

Country

8 Subscribers
0 Posts
My Account · Communities · Galleries · People
Terms of Service · Privacy Policy · Mobile · Copyright © 2023 Zuppon.com