diff --git a/inline-script.js b/inline-script.js index 6dc37c7..6b7c1b4 100644 --- a/inline-script.js +++ b/inline-script.js @@ -3,7 +3,17 @@ // the build process and write it to inline-script-checksum.json. window.__themeColors = process.env.THEME_COLORS -if (localStorage.store_currentInstance && localStorage.store_instanceThemes) { +const hasLocalStorage = (() => { + try { + // iOS safari throws here if cookies are disabled + let unused = localStorage.length // eslint-disable-line + return true + } catch (e) { + return false + } +})() + +if (hasLocalStorage && localStorage.store_currentInstance && localStorage.store_instanceThemes) { let safeParse = (str) => str === 'undefined' ? undefined : JSON.parse(str) let theme = safeParse(localStorage.store_instanceThemes)[safeParse(localStorage.store_currentInstance)] if (theme && theme !== 'default') { @@ -18,14 +28,14 @@ if (localStorage.store_currentInstance && localStorage.store_instanceThemes) { } } -if (!localStorage.store_currentInstance) { +if (!hasLocalStorage || !localStorage.store_currentInstance) { // if not logged in, show all these 'hidden-from-ssr' elements let style = document.createElement('style') style.textContent = '.hidden-from-ssr { opacity: 1 !important; }' document.head.appendChild(style) } -if (localStorage.store_disableCustomScrollbars === 'true') { +if (hasLocalStorage && localStorage.store_disableCustomScrollbars === 'true') { // if user has disabled custom scrollbars, remove this style let theScrollbarStyle = document.getElementById('theScrollbarStyle') theScrollbarStyle.setAttribute('media', 'only x') // disables the style diff --git a/package-lock.json b/package-lock.json index a550c43..d138ef9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6003,6 +6003,11 @@ "json5": "^0.5.0" } }, + "localstorage-memory": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/localstorage-memory/-/localstorage-memory-1.0.3.tgz", + "integrity": "sha512-t9P8WB6DcVttbw/W4PIE8HOqum8Qlvx5SjR6oInwR9Uia0EEmyUeBh7S+weKByW+l/f45Bj4L/dgZikGFDM6ng==" + }, "locate-path": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", diff --git a/package.json b/package.json index 008181a..980e1cd 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "idb-keyval": "^3.1.0", "indexeddb-getall-shim": "^1.3.5", "intersection-observer": "^0.5.1", + "localstorage-memory": "^1.0.3", "lodash-es": "^4.17.11", "lodash-webpack-plugin": "^0.11.5", "mini-css-extract-plugin": "^0.4.5", diff --git a/routes/_pages/settings/instances/add.html b/routes/_pages/settings/instances/add.html index a36e7c3..15a063e 100644 --- a/routes/_pages/settings/instances/add.html +++ b/routes/_pages/settings/instances/add.html @@ -3,10 +3,18 @@