index.js 1.1 KB

1234567891011121314151617181920212223242526272829
  1. document.addEventListener('DOMContentLoaded', function() {
  2. const currentUser = JSON.parse(localStorage.getItem('currentUser'));
  3. const loginLink = document.getElementById('login-link');
  4. const registerLink = document.getElementById('register-link');
  5. const profileLink = document.getElementById('profile-link');
  6. const logoutLink = document.getElementById('logout-link');
  7. if (currentUser) {
  8. loginLink.style.display = 'none';
  9. registerLink.style.display = 'none';
  10. profileLink.style.display = 'block';
  11. logoutLink.style.display = 'block';
  12. } else {
  13. loginLink.style.display = 'block';
  14. registerLink.style.display = 'block';
  15. profileLink.style.display = 'none';
  16. logoutLink.style.display = 'none';
  17. }
  18. logoutLink.addEventListener('click', function(event) {
  19. event.preventDefault();
  20. localStorage.removeItem('currentUser');
  21. loginLink.style.display = 'block';
  22. registerLink.style.display = 'block';
  23. profileLink.style.display = 'none';
  24. logoutLink.style.display = 'none';
  25. });
  26. });