all repos — h3rald @ 5ce44db426a8f765bb63a8201daaf6191a6d8848

The sources of https://h3rald.com

assets/js/scripts.js

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
(function (window) {
  'use strict';
  
  var themeLinks = document.getElementsByClassName('theme-css-link');
  var currentTheme = themeLinks[0].href.match(/(light|dark)/)[1];

  document.addEventListener("DOMContentLoaded", function(event) { 
    // Theme Switching
    var themeSwitcher = document.getElementById('theme-switcher');
    function switchTheme() {
      var newTheme = currentTheme === 'light' ? 'dark' : 'light';
      for (var i = 0; i < themeLinks.length; i++) {
        themeLinks[i].disabled = themeLinks[i].href.match(currentTheme);
        themeLinks[i].rel = themeLinks[i].href.match(currentTheme) ? 'alternate stylesheet' : 'stylesheet';
      }
      themeSwitcher.title = themeSwitcher.title.replace(newTheme, currentTheme);
      themeSwitcher.innerText = currentTheme;
      currentTheme = newTheme;
    }
    themeSwitcher.addEventListener('click', switchTheme);
  });
})(window)