getPreferences.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //search engine
  2. let selectedSearchEngine = "";
  3. localStorage.getItem("text-startpage:selectedSearchEngine")
  4. ? (selectedSearchEngine = localStorage.getItem(
  5. "text-startpage:selectedSearchEngine"
  6. ))
  7. : (selectedSearchEngine = "duckduckgo");
  8. //theme
  9. document
  10. .querySelector(":root")
  11. .classList.add(localStorage.getItem("text-startpage:theme"));
  12. //custom theme colors
  13. let customBackgroundColor = localStorage.getItem(
  14. "text-startpage:custom-background-color"
  15. );
  16. let customLightBackgroundColor = localStorage.getItem(
  17. "text-startpage:custom-light-background-color"
  18. );
  19. let customTextColor = localStorage.getItem("text-startpage:custom-text-color");
  20. let customLightTextColor = localStorage.getItem(
  21. "text-startpage:custom-light-text-color"
  22. );
  23. let customHighlighterColor = localStorage.getItem(
  24. "text-startpage:custom-highlighter"
  25. );
  26. //custom page title
  27. let enableCustomTitle = JSON.parse(
  28. localStorage.getItem("text-startpage:enableCustomTitle")
  29. );
  30. let customTitle = localStorage.getItem("text-startpage:customTitle");
  31. //greeting
  32. let enableGreeting = "";
  33. localStorage.getItem("text-startpage:enableGreeting")
  34. ? (enableGreeting = localStorage.getItem("text-startpage:enableGreeting"))
  35. : (enableGreeting = false);
  36. let greetingText = "";
  37. localStorage.getItem("text-startpage:greetingText")
  38. ? (greetingText = localStorage.getItem("text-startpage:greetingText"))
  39. : (greetingText = "Hello");
  40. let greetingName = localStorage.getItem("text-startpage:greetingName");
  41. //clock
  42. let enableClock = localStorage.getItem("text-startpage:enableClock");
  43. let clockSeperator = localStorage.getItem("text-startpage:clockSeperator");
  44. let dateSeperator = localStorage.getItem("text-startpage:dateSeperator");
  45. //quote
  46. let enableQuote = localStorage.getItem("text-startpage:enableQuote");
  47. //wallpapers
  48. let wallpapersLinksArray =
  49. JSON.parse(localStorage.getItem("text-startpage:wallpapers")) || 0;
  50. let wallpapersCycleIndex =
  51. JSON.parse(localStorage.getItem("text-startpage:wallpaperCycleIndex")) || 0;
  52. let enableCustomWallpapers =
  53. JSON.parse(localStorage.getItem("text-startpage:enableCustomWallpapers")) ||
  54. 0;
  55. //bookmarks
  56. let bookmarks = JSON.parse(localStorage.getItem("text-startpage:bookmarks"));
  57. if (!bookmarks) {
  58. const xhr = new XMLHttpRequest();
  59. xhr.open("GET", "json/defaultBookmarks.json");
  60. xhr.responseType = "json";
  61. xhr.send();
  62. xhr.onload = () => {
  63. if (xhr.status == 200) {
  64. localStorage.setItem(
  65. "text-startpage:bookmarks",
  66. JSON.stringify(xhr.response)
  67. );
  68. window.location.reload();
  69. } else {
  70. const errorSpan = document.createElement("span");
  71. const errorText = document.createTextNode("ERROR: " + xhr.status);
  72. errorSpan.appendChild(errorText);
  73. document
  74. .getElementById("bookmarks-container")
  75. .appendChild(errorSpan);
  76. }
  77. };
  78. }
  79. //set the theme
  80. if (localStorage.getItem("text-startpage:theme") == "custom") {
  81. const colorsToInject = document.createElement("style");
  82. colorsToInject.innerText = `
  83. .custom {
  84. --background-color: ${customBackgroundColor};
  85. --light-background-color: ${customLightBackgroundColor};
  86. --text-color: ${customTextColor};
  87. --light-text-color: ${customLightTextColor};
  88. --highlighter: ${customHighlighterColor};
  89. }
  90. `;
  91. document.head.appendChild(colorsToInject);
  92. }
  93. //set custom page title
  94. if (enableCustomTitle) {
  95. if (customTitle) {
  96. document.title = customTitle;
  97. console.log(customTitle);
  98. } else {
  99. document.title = "​";
  100. }
  101. }