pagescript.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. var classHolder = document.getElementsByTagName("BODY")[0],
  3. /**
  4. * Load from localstorage
  5. **/
  6. themeSettings = (localStorage.getItem('themeSettings')) ? JSON.parse(localStorage.getItem('themeSettings')) :
  7. {},
  8. themeURL = themeSettings.themeURL || '',
  9. themeOptions = themeSettings.themeOptions || '';
  10. /**
  11. * Load theme options
  12. **/
  13. if (themeSettings.themeOptions)
  14. {
  15. classHolder.className = themeSettings.themeOptions;
  16. console.log("%c✔ Theme settings loaded", "color: #148f32");
  17. }
  18. else
  19. {
  20. console.log("Heads up! Theme settings is empty or does not exist, loading default settings...");
  21. }
  22. if (themeSettings.themeURL && !document.getElementById('mytheme'))
  23. {
  24. var cssfile = document.createElement('link');
  25. cssfile.id = 'mytheme';
  26. cssfile.rel = 'stylesheet';
  27. cssfile.href = themeURL;
  28. document.getElementsByTagName('head')[0].appendChild(cssfile);
  29. }
  30. /**
  31. * Save to localstorage
  32. **/
  33. var saveSettings = function()
  34. {
  35. themeSettings.themeOptions = String(classHolder.className).split(/[^\w-]+/).filter(function(item)
  36. {
  37. return /^(nav|header|mod|display)-/i.test(item);
  38. }).join(' ');
  39. if (document.getElementById('mytheme'))
  40. {
  41. themeSettings.themeURL = document.getElementById('mytheme').getAttribute("href");
  42. };
  43. localStorage.setItem('themeSettings', JSON.stringify(themeSettings));
  44. }
  45. /**
  46. * Reset settings
  47. **/
  48. var resetSettings = function()
  49. {
  50. localStorage.setItem("themeSettings", "");
  51. }