Advertisement
Guest User

Untitled

a guest
May 28th, 2022
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.         function swapStyleSheet(sheet) {
  3.           document.getElementById("pagestyle").setAttribute("href", sheet);  
  4.         }
  5.      
  6.         function initate() {
  7.           baguetteBox.run('.galleryBaguetteBox');
  8.           var styleSwag = document.getElementById("enableSwag");
  9.           var swagEnable = false; //working with a boolean instead of a strin makes life easier
  10.          
  11.           let storedSwagEnable = localStorage.getItem('swagEnable'); //load strored swag
  12.           if (storedSwagEnable != null) swagEnable = storedSwagEnable; //if there is a perviously stored value, write it to the swagEnable variable
  13.             swapStyleSheet(swagEnable ? "styleSwag.css" : "style.css"); //set style
  14.          
  15.           styleSwag.onclick = function () {
  16.             swagEnable = !swagEnable; //swagEnable is set tot the opposite of swagEnbable. true -> false or false -> true
  17.             swapStyleSheet(swagEnable ? "styleSwag.css" : "style.css"); //ternery operator works like this: condition ? value-if-true : value-if-false
  18.                         localStorage.setItem('swagEnable', swagEnable); //store swag mode
  19.           };
  20.         }
  21.        
  22.         window.onload = initate;
  23.      
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement