From 075ba1dd485d48cdb65ed5777c40e3d3c3d11b9a Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Thu, 11 Apr 2024 15:45:41 +0100 Subject: [PATCH] Rename variable from icon_prefix to iconPrefix --- js/dist/forum.js.map | 2 +- js/src/forum/addSettingsItems.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/js/dist/forum.js.map b/js/dist/forum.js.map index 1017174..4d61857 100755 --- a/js/dist/forum.js.map +++ b/js/dist/forum.js.map @@ -1 +1 @@ -{"version":3,"file":"forum.js","mappings":"MACA,IAAIA,EAAsB,CCA1BA,EAAyBC,IACxB,IAAIC,EAASD,GAAUA,EAAOE,WAC7B,IAAOF,EAAiB,QACxB,IAAM,EAEP,OADAD,EAAoBI,EAAEF,EAAQ,CAAEG,EAAGH,IAC5BA,CAAM,ECLdF,EAAwB,CAACM,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXP,EAAoBS,EAAEF,EAAYC,KAASR,EAAoBS,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDR,EAAwB,CAACc,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFf,EAAyBM,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,GAAO,G,4WCL9D,MAAM,EAA+BC,OAAOC,KAAKC,OAAO,c,aCmBxD,QATe,CACbC,KAAM,EACNC,MAAO,EACPC,KAAM,EAGNC,QAAS,kBAAMC,IAAAA,MAAUC,UAAU,gCAAkC,CAAC,GChBlE,EAA+BR,OAAOC,KAAKC,OAAO,iBCAlD,EAA+BF,OAAOC,KAAKC,OAAO,0B,aCApDO,EAAsC,WAStC,OARAA,EAAWrB,OAAOsB,QAAU,SAASC,GACjC,IAAK,IAA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ACW,IAAM,CACLxC,UAAU,sBACVyC,QAAS,WAKP5B,GACF,EACA6B,KAAMtD,IAAUtC,EAAOlD,KAAO,gBAAqBmH,EAAUwB,EAAY,MAAQA,EAAY,QAE5FvI,IAAAA,WAAeoH,MAAM,gDAExB,GApBgG,CAsBpG,KAEA5C,EAAAA,EAAAA,QAAOmE,IAAAA,UAA2B,SAAS,SAAUpB,GACnD,GAAKvH,IAAAA,QAAYkE,KAAjB,CAEA,IAAM6C,EAAUH,EAAW3C,KACrBsE,EAAcvI,IAAAA,MAAUC,UAAU,uCAAyC,UAAY,UAG7FsH,EAAMF,IACJN,EAAU,YAAc,UACxByB,IAAAA,UACE,CACEE,KAAS3B,EAAUwB,EAAY,OAASA,EAAY,MACpDE,QAAS,WACP5B,GAkBF,GAEF7G,IAAAA,WAAeoH,MAAM,wBAAuBL,EAAU,QAAU,UAEjE,EAlC0B,CAoC/B,IC9KA6B,GACF,G","sources":["webpack://@fof/nightmode/webpack/bootstrap","webpack://@fof/nightmode/webpack/runtime/compat get default export","webpack://@fof/nightmode/webpack/runtime/define property getters","webpack://@fof/nightmode/webpack/runtime/hasOwnProperty shorthand","webpack://@fof/nightmode/webpack/runtime/make namespace object","webpack://@fof/nightmode/external root \"flarum.core.compat['common/app']\"","webpack://@fof/nightmode/./src/common/Themes.js","webpack://@fof/nightmode/external root \"flarum.core.compat['common/extend']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/Page']\"","webpack://@fof/nightmode/./node_modules/es-cookie/src/es-cookie.js","webpack://@fof/nightmode/./src/forum/helpers/perDeviceSetting.js","webpack://@fof/nightmode/./src/forum/fixInvalidThemeSetting.js","webpack://@fof/nightmode/./src/forum/getTheme.js","webpack://@fof/nightmode/./src/common/setSelectedTheme.js","webpack://@fof/nightmode/external root \"flarum.core.compat['forum/app']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['forum/components/SettingsPage']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['forum/components/SessionDropdown']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['forum/components/HeaderSecondary']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/Button']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/LoadingIndicator']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/Select']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/FieldSet']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/Switch']\"","webpack://@fof/nightmode/./src/forum/helpers/switchTheme.js","webpack://@fof/nightmode/./src/forum/addSettingsItems.js","webpack://@fof/nightmode/./src/forum/index.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/app'];","import app from 'flarum/common/app';\r\n\r\n/*\r\n\r\n JS enum equivalent. Makes sure no value mix-ups are made!\r\n\r\n DEFAULT is used when an invalid value has been set, as well as for guest and new users.\r\n\r\n*/\r\n\r\nconst Themes = {\r\n AUTO: 0,\r\n LIGHT: 1,\r\n DARK: 2,\r\n\r\n // adds an \"ultra default\" of 0 if the admins don't set a default tsk tsk tsk\r\n DEFAULT: () => app.forum.attribute('fof-nightmode.default_theme') || 0,\r\n};\r\n\r\nexport default Themes;\r\n","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/extend'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/Page'];","var __assign = (this && this.__assign) || function () {\r\n __assign = Object.assign || function(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\r\n t[p] = s[p];\r\n }\r\n return t;\r\n };\r\n return __assign.apply(this, arguments);\r\n};\r\nfunction stringifyAttribute(name, value) {\r\n if (!value) {\r\n return '';\r\n }\r\n var stringified = '; ' + name;\r\n if (value === true) {\r\n return stringified; // boolean attributes shouldn't have a value\r\n }\r\n return stringified + '=' + value;\r\n}\r\nfunction stringifyAttributes(attributes) {\r\n if (typeof attributes.expires === 'number') {\r\n var expires = new Date();\r\n expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);\r\n attributes.expires = expires;\r\n }\r\n return stringifyAttribute('Expires', attributes.expires ? attributes.expires.toUTCString() : '')\r\n + stringifyAttribute('Domain', attributes.domain)\r\n + stringifyAttribute('Path', attributes.path)\r\n + stringifyAttribute('Secure', attributes.secure)\r\n + stringifyAttribute('SameSite', attributes.sameSite);\r\n}\r\nexport function encode(name, value, attributes) {\r\n return encodeURIComponent(name)\r\n .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent) // allowed special characters\r\n .replace(/\\(/g, '%28').replace(/\\)/g, '%29') // replace opening and closing parens\r\n + '=' + encodeURIComponent(value)\r\n // allowed special characters\r\n .replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g, decodeURIComponent)\r\n + stringifyAttributes(attributes);\r\n}\r\nexport function parse(cookieString) {\r\n var result = {};\r\n var cookies = cookieString ? cookieString.split('; ') : [];\r\n for (var _i = 0, cookies_1 = cookies; _i < cookies_1.length; _i++) {\r\n var cookie = cookies_1[_i];\r\n var parts = cookie.split('=');\r\n var value = parts.slice(1).join('=');\r\n if (value[0] === '\"') {\r\n value = value.slice(1, -1);\r\n }\r\n try {\r\n var name_1 = decodeURIComponent(parts[0]);\r\n result[name_1] = value.replace(/(%[\\dA-F]{2})+/gi, decodeURIComponent);\r\n }\r\n catch (e) {\r\n // ignore cookies with invalid name/value encoding\r\n }\r\n }\r\n return result;\r\n}\r\nexport function getAll() {\r\n return parse(document.cookie);\r\n}\r\nexport function get(name) {\r\n return getAll()[name];\r\n}\r\nexport function set(name, value, attributes) {\r\n document.cookie = encode(name, value, __assign({ path: '/' }, attributes));\r\n}\r\nexport function remove(name, attributes) {\r\n set(name, '', __assign(__assign({}, attributes), { expires: -1 }));\r\n}\r\n","import * as Cookies from 'es-cookie';\r\nimport Themes from '../../common/Themes';\r\n\r\nexport const KEY = 'flarum_nightmode';\r\n\r\nexport const get = () => {\r\n const value = Cookies.get(KEY);\r\n\r\n if (!value && value !== '0') {\r\n return Themes.DEFAULT();\r\n }\r\n\r\n return Number(value);\r\n};\r\n\r\nexport const set = (val) =>\r\n Cookies.set(KEY, val, {\r\n sameSite: 'lax',\r\n secure: location.protocol === 'https:',\r\n });\r\n\r\nexport const remove = () => Cookies.remove(KEY);\r\n","/*\r\n This function is designed to catch invalid theme values\r\n and handle them before they can break Flarum for users.\r\n\r\n E.g. if a user manually edited their cookies to\r\n set their theme to an invalid value, this theme would\r\n detect that, and reset it to 0 (auto).\r\n*/\r\n\r\nimport Themes from '../common/Themes';\r\nimport { get, set } from './helpers/perDeviceSetting';\r\n\r\nexport default function fixInvalidThemeSetting() {\r\n // get array of valid values without duplicate entries\r\n let validValues = Array.from(new Set(Object.values(Themes)));\r\n\r\n const Theme = get();\r\n\r\n if (isNaN(Theme)) {\r\n resetTheme('Theme is not a valid integer! Resetting...');\r\n } else if (!validValues.includes(Theme)) {\r\n // theme out of bounds\r\n resetTheme(`Theme is out of bounds! Resetting...`);\r\n }\r\n}\r\n\r\nfunction resetTheme(reason) {\r\n console.warn(reason);\r\n\r\n set(Themes.DEFAULT());\r\n}\r\n","import app from 'flarum/common/app';\r\nimport Themes from '../common/Themes';\r\nimport { get } from './helpers/perDeviceSetting';\r\n\r\nexport default function getTheme() {\r\n const user = app.session.user;\r\n\r\n const IsUsingPerDeviceSettings = !user || !!user.preferences().fofNightMode_perDevice;\r\n const SelectedTheme = user && user.preferences().fofNightMode;\r\n\r\n let value;\r\n\r\n if (IsUsingPerDeviceSettings) {\r\n // fetch through LS is per device enabled\r\n value = get();\r\n } else {\r\n if (typeof SelectedTheme === 'number' && SelectedTheme !== -1) {\r\n // use user prefs\r\n value = SelectedTheme;\r\n }\r\n }\r\n\r\n return typeof value === 'number' ? value : Themes.DEFAULT();\r\n}\r\n","import app from 'flarum/common/app';\r\n\r\nimport { extend } from 'flarum/common/extend';\r\nimport Page from 'flarum/common/components/Page';\r\n\r\nimport Themes from './Themes';\r\nimport fixInvalidThemeSetting from '../forum/fixInvalidThemeSetting';\r\nimport getTheme from '../forum/getTheme';\r\n\r\nexport default () => {\r\n extend(Page.prototype, 'oninit', setTheme);\r\n\r\n // Register setTheme() as the handler for 'prefers-color-scheme' media property\r\n // change. This allows to make sure the 'fofnightmodechange' event is dispatched\r\n // when this property changes, and that the correct stylesheets are loaded.\r\n const prefersColorSchemeDark = window.matchMedia('(prefers-color-scheme: dark)');\r\n prefersColorSchemeDark.addEventListener('change', setTheme);\r\n};\r\n\r\nexport function setTheme() {\r\n const { user } = app.session;\r\n\r\n const PerDevice = app.session.user?.preferences().fofNightMode_perDevice;\r\n\r\n if (!user || PerDevice) {\r\n fixInvalidThemeSetting();\r\n }\r\n\r\n if (PerDevice) {\r\n fixInvalidThemeSetting();\r\n }\r\n\r\n const CurrentTheme = getTheme();\r\n\r\n setThemeFromID(CurrentTheme);\r\n}\r\n\r\nexport function getUrls() {\r\n return {\r\n day: app.data['fof-nightmode.assets.day'],\r\n night: app.data['fof-nightmode.assets.night'],\r\n };\r\n}\r\n\r\nexport function setThemeFromID(theme) {\r\n if (theme === Themes.DARK) {\r\n setStyle('night');\r\n } else if (theme === Themes.LIGHT) {\r\n setStyle('day');\r\n } else {\r\n const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches;\r\n\r\n setStyle(preferDark ? 'night' : 'day');\r\n }\r\n}\r\n\r\nexport function setStyle(type) {\r\n const light = document.querySelector('link.nightmode-light[rel=stylesheet]');\r\n const dark = document.querySelector('link.nightmode-dark[rel=stylesheet]');\r\n\r\n bothStyleSheets: if (light && dark) {\r\n if (getTheme() === Themes.AUTO) break bothStyleSheets;\r\n\r\n let newLink = document.createElement('link');\r\n\r\n // onload on link tags not supported in all browsers\r\n // so we should check it is present in the user's\r\n // current browser\r\n if ('onload' in newLink) {\r\n // if it is, only remove the old link tags after the new\r\n // one has finished loading (prevents flash of unstyled\r\n // content)\r\n newLink.onload = function () {\r\n light.remove();\r\n dark.remove();\r\n };\r\n } else {\r\n // if it isn't, just remove the old link tags immediately\r\n light.remove();\r\n dark.remove();\r\n }\r\n\r\n newLink.rel = 'stylesheet';\r\n newLink.className = 'nightmode';\r\n newLink.href = getUrls()[type];\r\n\r\n document.head.append(newLink);\r\n } else {\r\n const el = light || dark || document.querySelector('link.nightmode[rel=stylesheet]');\r\n\r\n const url = getUrls()[type];\r\n\r\n if (url !== el.href) {\r\n el.href = url;\r\n el.className = 'nightmode';\r\n }\r\n }\r\n\r\n const colorScheme = document.querySelector('meta[name=\"color-scheme\"]');\r\n\r\n if (colorScheme) {\r\n colorScheme.content = type === 'night' ? 'dark' : 'light';\r\n }\r\n\r\n // Dispatch a 'fofnightmodechange' event with 'day' or 'night' as detail.\r\n // This allows other extensions to integrate with this one.\r\n const event = new CustomEvent('fofnightmodechange', { detail: type });\r\n document.dispatchEvent(event);\r\n}\r\n","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['forum/app'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['forum/components/SettingsPage'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['forum/components/SessionDropdown'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['forum/components/HeaderSecondary'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/Button'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/LoadingIndicator'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/Select'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/FieldSet'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/Switch'];","import app from 'flarum/forum/app';\r\nimport Themes from '../../common/Themes';\r\nimport { setTheme } from '../../common/setSelectedTheme';\r\nimport getTheme from '../getTheme';\r\nimport * as perDevice from '../helpers/perDeviceSetting';\r\n\r\nexport function getIsLight(theme) {\r\n return theme === Themes.LIGHT || (theme === Themes.AUTO && !window.matchMedia('(prefers-color-scheme: dark)').matches);\r\n}\r\n\r\nfunction toggleThrough(current) {\r\n if (current === Themes.AUTO) {\r\n return Themes.LIGHT;\r\n }\r\n\r\n if (current === Themes.LIGHT) {\r\n return Themes.DARK;\r\n }\r\n\r\n return Themes.AUTO;\r\n}\r\n\r\nexport function switchTheme() {\r\n const theme = getTheme();\r\n const isLight = getIsLight(theme);\r\n const user = app.session.user;\r\n\r\n if (user) {\r\n const val = isLight ? Themes.DARK : Themes.LIGHT;\r\n\r\n if (!!user.preferences().fofNightMode_perDevice) {\r\n perDevice.set(val);\r\n setTheme();\r\n return;\r\n }\r\n\r\n user\r\n .savePreferences({\r\n fofNightMode: val,\r\n })\r\n .then(() => {\r\n // need to force-update selected theme (as it's only set\r\n // on a page load and redraw doesn't count as a page load)\r\n setTheme();\r\n });\r\n } else {\r\n const newTheme = toggleThrough(theme);\r\n\r\n perDevice.set(newTheme);\r\n setTheme();\r\n }\r\n}\r\n","import app from 'flarum/forum/app';\r\nimport { extend } from 'flarum/common/extend';\r\n\r\nimport SettingsPage from 'flarum/forum/components/SettingsPage';\r\nimport SessionDropdown from 'flarum/forum/components/SessionDropdown';\r\nimport HeaderSecondary from 'flarum/forum/components/HeaderSecondary';\r\nimport Button from 'flarum/common/components/Button';\r\nimport LoadingIndicator from 'flarum/common/components/LoadingIndicator';\r\nimport Select from 'flarum/common/components/Select';\r\nimport FieldSet from 'flarum/common/components/FieldSet';\r\nimport Switch from 'flarum/common/components/Switch';\r\n\r\nimport { setTheme } from '../common/setSelectedTheme';\r\nimport fixInvalidThemeSetting from './fixInvalidThemeSetting';\r\nimport * as perDevice from './helpers/perDeviceSetting';\r\nimport getTheme from './getTheme';\r\nimport Themes from '../common/Themes';\r\nimport { switchTheme, getIsLight } from './helpers/switchTheme';\r\n\r\n// custom function for translations makes it a lot cleaner\r\nconst trans = (key) => app.translator.trans(`fof-nightmode.forum.user.settings.${key}`);\r\n\r\nexport default function () {\r\n extend(SettingsPage.prototype, 'settingsItems', function (items) {\r\n const { user } = app.session;\r\n\r\n const PerDevice = !!user.preferences().fofNightMode_perDevice;\r\n\r\n if (PerDevice) {\r\n fixInvalidThemeSetting();\r\n }\r\n\r\n const doesNotSupportAuto = !window.matchMedia('not all and (prefers-color-scheme), (prefers-color-scheme)').matches;\r\n\r\n let currentTheme = getTheme();\r\n\r\n const options = { 0: trans('options.auto'), 1: trans('options.day'), 2: trans('options.night') };\r\n\r\n if (doesNotSupportAuto) {\r\n delete options['0'];\r\n\r\n if (currentTheme === Themes.AUTO) {\r\n currentTheme = app.forum.attribute('fofNightMode_autoUnsupportedFallback');\r\n }\r\n }\r\n\r\n items.add(\r\n 'fof-nightmode',\r\n FieldSet.component(\r\n {\r\n label: trans('heading'),\r\n className: 'Settings-theme',\r\n },\r\n [\r\n

{trans('description')}

,\r\n

{trans('description2')}

,\r\n doesNotSupportAuto ?

{trans('auto_unsupported')}

: null,\r\n Switch.component(\r\n {\r\n className: 'Settings-theme--per_device_cb',\r\n state: PerDevice,\r\n onchange: (checked) => {\r\n if (checked) {\r\n // save current theme as this device's default\r\n perDevice.set(currentTheme);\r\n } else {\r\n perDevice.remove();\r\n }\r\n\r\n user\r\n .savePreferences({\r\n fofNightMode_perDevice: checked,\r\n })\r\n .then(() => {\r\n // need to force-update selected theme (as it's only set\r\n // on a page load and redraw doesn't count as a page load)\r\n setTheme();\r\n });\r\n },\r\n },\r\n trans('device_specific_setting_checkbox')\r\n ),\r\n Select.component({\r\n value: currentTheme,\r\n className: 'Settings-theme--input',\r\n onchange: (e) => {\r\n if (PerDevice) {\r\n perDevice.set(e);\r\n\r\n setTheme();\r\n return;\r\n }\r\n\r\n user\r\n .savePreferences({\r\n fofNightMode: e,\r\n })\r\n .then(() => {\r\n m.redraw();\r\n\r\n // need to force-update selected theme (as it's only set\r\n // on a page load and redraw doesn't count as a apge load)\r\n setTheme();\r\n });\r\n },\r\n options,\r\n }),\r\n

\r\n {currentTheme === Themes.AUTO\r\n ? trans('option_descriptions.auto')\r\n : currentTheme === Themes.LIGHT\r\n ? trans('option_descriptions.day')\r\n : currentTheme === Themes.DARK\r\n ? trans('option_descriptions.night')\r\n : // prevents nasty paragraph switching\r\n LoadingIndicator.component()}\r\n

,\r\n ]\r\n )\r\n );\r\n });\r\n\r\n extend(HeaderSecondary.prototype, 'items', function (items) {\r\n if (app.session.user && !app.forum.attribute('fofNightMode.showThemeToggleOnHeaderAlways')) return;\r\n\r\n const theme = getTheme();\r\n const isLight = getIsLight(theme);\r\n const icon_prefix = app.forum.attribute('fofNightMode.showThemeToggleInSolid') ? 'fas fa-' : 'far fa-';\r\n items.add(\r\n 'nightmode',\r\n {\r\n // const newTheme = toggleThrough(theme);\r\n\r\n // perDevice.set(newTheme);\r\n // setTheme();\r\n switchTheme();\r\n }}\r\n icon={theme === Themes.AUTO ? 'fas fa-adjust' : `${isLight ? icon_prefix+'sun' : icon_prefix+'moon'}`}\r\n >\r\n {app.translator.trans('fof-nightmode.forum.header.nightmode_button')}\r\n ,\r\n 15\r\n );\r\n });\r\n\r\n extend(SessionDropdown.prototype, 'items', function (items) {\r\n if (!app.session.user) return;\r\n\r\n const isLight = getIsLight(getTheme());\r\n const icon_prefix = app.forum.attribute('fofNightMode.showThemeToggleInSolid') ? 'fas fa-' : 'far fa-';\r\n\r\n // Add night mode link to session dropdown\r\n items.add(\r\n isLight ? 'nightmode' : 'daymode',\r\n Button.component(\r\n {\r\n icon: `${isLight ? icon_prefix+'moon' : icon_prefix+'sun'}`,\r\n onclick: () => {\r\n switchTheme();\r\n // const val = isLight ? Themes.DARK : Themes.LIGHT;\r\n\r\n // if (!!user.preferences().fofNightMode_perDevice) {\r\n // perDevice.set(val);\r\n // setTheme();\r\n // return;\r\n // }\r\n\r\n // user\r\n // .savePreferences({\r\n // fofNightMode: val,\r\n // })\r\n // .then(() => {\r\n // // need to force-update selected theme (as it's only set\r\n // // on a page load and redraw doesn't count as a apge load)\r\n // setTheme();\r\n // });\r\n },\r\n },\r\n app.translator.trans(`fof-nightmode.forum.${isLight ? 'night' : 'day'}`)\r\n ),\r\n -1\r\n );\r\n });\r\n}\r\n","import app from 'flarum/forum/app';\r\nimport addSettingsItems from './addSettingsItems';\r\nimport setSelectedTheme from '../common/setSelectedTheme';\r\n\r\nexport * as perDeviceSetting from './helpers/perDeviceSetting';\r\nexport * as switchTheme from './helpers/switchTheme';\r\nexport { default as getTheme } from './getTheme';\r\n\r\napp.initializers.add('fof-nightmode', () => {\r\n addSettingsItems();\r\n setSelectedTheme();\r\n});\r\n"],"names":["__webpack_require__","module","getter","__esModule","d","a","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","flarum","core","compat","AUTO","LIGHT","DARK","DEFAULT","app","attribute","__assign","assign","t","s","i","n","arguments","length","p","apply","this","stringifyAttribute","name","stringified","set","attributes","document","cookie","encodeURIComponent","replace","decodeURIComponent","expires","Date","setMilliseconds","getMilliseconds","toUTCString","domain","path","secure","sameSite","stringifyAttributes","encode","KEY","cookieString","result","_i","cookies_1","split","parts","slice","join","e","parse","Number","Themes","val","Cookies","location","protocol","remove","fixInvalidThemeSetting","validValues","Array","from","Set","values","Theme","isNaN","resetTheme","includes","reason","console","warn","getTheme","user","IsUsingPerDeviceSettings","preferences","fofNightMode_perDevice","SelectedTheme","fofNightMode","extend","Page","setTheme","window","matchMedia","addEventListener","_app$session$user","PerDevice","setThemeFromID","getUrls","day","night","theme","setStyle","matches","type","light","querySelector","dark","bothStyleSheets","newLink","createElement","onload","rel","className","href","head","append","el","url","colorScheme","content","event","CustomEvent","detail","dispatchEvent","getIsLight","switchTheme","current","isLight","perDevice","savePreferences","then","newTheme","trans","add","SettingsPage","items","doesNotSupportAuto","currentTheme","options","FieldSet","label","m","class","Switch","state","onchange","checked","Select","redraw","LoadingIndicator","HeaderSecondary","icon_prefix","Button","onclick","icon","SessionDropdown","setSelectedTheme"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"forum.js","mappings":"MACA,IAAIA,EAAsB,CCA1BA,EAAyBC,IACxB,IAAIC,EAASD,GAAUA,EAAOE,WAC7B,IAAOF,EAAiB,QACxB,IAAM,EAEP,OADAD,EAAoBI,EAAEF,EAAQ,CAAEG,EAAGH,IAC5BA,CAAM,ECLdF,EAAwB,CAACM,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXP,EAAoBS,EAAEF,EAAYC,KAASR,EAAoBS,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDR,EAAwB,CAACc,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFf,EAAyBM,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,GAAO,G,4WCL9D,MAAM,EAA+BC,OAAOC,KAAKC,OAAO,c,aCmBxD,QATe,CACbC,KA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QAAO8D,IAAAA,UAA2B,SAAS,SAAUf,GACnD,IAAIvH,IAAAA,QAAYkE,MAASlE,IAAAA,MAAUC,UAAU,8CAA7C,CAEA,IAAMmF,EAAQnB,IACR8C,EAAUH,EAAWxB,GACrBmD,EAAavI,IAAAA,MAAUC,UAAU,uCAAyC,UAAY,UAC5FsH,EAAMF,IACJ,YACAQ,EAACW,IAAM,CACLxC,UAAU,sBACVyC,QAAS,WAKP5B,GACF,EACA6B,KAAMtD,IAAUtC,EAAOlD,KAAO,gBAAqBmH,EAAUwB,EAAW,MAAQA,EAAW,QAE1FvI,IAAAA,WAAeoH,MAAM,gDAExB,GApBgG,CAsBpG,KAEA5C,EAAAA,EAAAA,QAAOmE,IAAAA,UAA2B,SAAS,SAAUpB,GACnD,GAAKvH,IAAAA,QAAYkE,KAAjB,CAEA,IAAM6C,EAAUH,EAAW3C,KACrBsE,EAAavI,IAAAA,MAAUC,UAAU,uCAAyC,UAAY,UAG5FsH,EAAMF,IACJN,EAAU,YAAc,UACxByB,IAAAA,UACE,CACEE,KAAS3B,EAAUwB,EAAW,OAASA,EAAW,MAClDE,QAAS,WACP5B,GAkBF,GAEF7G,IAAAA,WAAeoH,MAAM,wBAAuBL,EAAU,QAAU,UAEjE,EAlC0B,CAoC/B,IC9KA6B,GACF,G","sources":["webpack://@fof/nightmode/webpack/bootstrap","webpack://@fof/nightmode/webpack/runtime/compat get default export","webpack://@fof/nightmode/webpack/runtime/define property getters","webpack://@fof/nightmode/webpack/runtime/hasOwnProperty shorthand","webpack://@fof/nightmode/webpack/runtime/make namespace object","webpack://@fof/nightmode/external root \"flarum.core.compat['common/app']\"","webpack://@fof/nightmode/./src/common/Themes.js","webpack://@fof/nightmode/external root \"flarum.core.compat['common/extend']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/Page']\"","webpack://@fof/nightmode/./node_modules/es-cookie/src/es-cookie.js","webpack://@fof/nightmode/./src/forum/helpers/perDeviceSetting.js","webpack://@fof/nightmode/./src/forum/fixInvalidThemeSetting.js","webpack://@fof/nightmode/./src/forum/getTheme.js","webpack://@fof/nightmode/./src/common/setSelectedTheme.js","webpack://@fof/nightmode/external root \"flarum.core.compat['forum/app']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['forum/components/SettingsPage']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['forum/components/SessionDropdown']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['forum/components/HeaderSecondary']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/Button']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/LoadingIndicator']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/Select']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/FieldSet']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/Switch']\"","webpack://@fof/nightmode/./src/forum/helpers/switchTheme.js","webpack://@fof/nightmode/./src/forum/addSettingsItems.js","webpack://@fof/nightmode/./src/forum/index.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/app'];","import app from 'flarum/common/app';\r\n\r\n/*\r\n\r\n JS enum equivalent. Makes sure no value mix-ups are made!\r\n\r\n DEFAULT is used when an invalid value has been set, as well as for guest and new users.\r\n\r\n*/\r\n\r\nconst Themes = {\r\n AUTO: 0,\r\n LIGHT: 1,\r\n DARK: 2,\r\n\r\n // adds an \"ultra default\" of 0 if the admins don't set a default tsk tsk tsk\r\n DEFAULT: () => app.forum.attribute('fof-nightmode.default_theme') || 0,\r\n};\r\n\r\nexport default Themes;\r\n","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/extend'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/Page'];","var __assign = (this && this.__assign) || function () {\r\n __assign = Object.assign || function(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\r\n t[p] = s[p];\r\n }\r\n return t;\r\n };\r\n return __assign.apply(this, arguments);\r\n};\r\nfunction stringifyAttribute(name, value) {\r\n if (!value) {\r\n return '';\r\n }\r\n var stringified = '; ' + name;\r\n if (value === true) {\r\n return stringified; // boolean attributes shouldn't have a value\r\n }\r\n return stringified + '=' + value;\r\n}\r\nfunction stringifyAttributes(attributes) {\r\n if (typeof attributes.expires === 'number') {\r\n var expires = new Date();\r\n expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);\r\n attributes.expires = expires;\r\n }\r\n return stringifyAttribute('Expires', attributes.expires ? attributes.expires.toUTCString() : '')\r\n + stringifyAttribute('Domain', attributes.domain)\r\n + stringifyAttribute('Path', attributes.path)\r\n + stringifyAttribute('Secure', attributes.secure)\r\n + stringifyAttribute('SameSite', attributes.sameSite);\r\n}\r\nexport function encode(name, value, attributes) {\r\n return encodeURIComponent(name)\r\n .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent) // allowed special characters\r\n .replace(/\\(/g, '%28').replace(/\\)/g, '%29') // replace opening and closing parens\r\n + '=' + encodeURIComponent(value)\r\n // allowed special characters\r\n .replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g, decodeURIComponent)\r\n + stringifyAttributes(attributes);\r\n}\r\nexport function parse(cookieString) {\r\n var result = {};\r\n var cookies = cookieString ? cookieString.split('; ') : [];\r\n for (var _i = 0, cookies_1 = cookies; _i < cookies_1.length; _i++) {\r\n var cookie = cookies_1[_i];\r\n var parts = cookie.split('=');\r\n var value = parts.slice(1).join('=');\r\n if (value[0] === '\"') {\r\n value = value.slice(1, -1);\r\n }\r\n try {\r\n var name_1 = decodeURIComponent(parts[0]);\r\n result[name_1] = value.replace(/(%[\\dA-F]{2})+/gi, decodeURIComponent);\r\n }\r\n catch (e) {\r\n // ignore cookies with invalid name/value encoding\r\n }\r\n }\r\n return result;\r\n}\r\nexport function getAll() {\r\n return parse(document.cookie);\r\n}\r\nexport function get(name) {\r\n return getAll()[name];\r\n}\r\nexport function set(name, value, attributes) {\r\n document.cookie = encode(name, value, __assign({ path: '/' }, attributes));\r\n}\r\nexport function remove(name, attributes) {\r\n set(name, '', __assign(__assign({}, attributes), { expires: -1 }));\r\n}\r\n","import * as Cookies from 'es-cookie';\r\nimport Themes from '../../common/Themes';\r\n\r\nexport const KEY = 'flarum_nightmode';\r\n\r\nexport const get = () => {\r\n const value = Cookies.get(KEY);\r\n\r\n if (!value && value !== '0') {\r\n return Themes.DEFAULT();\r\n }\r\n\r\n return Number(value);\r\n};\r\n\r\nexport const set = (val) =>\r\n Cookies.set(KEY, val, {\r\n sameSite: 'lax',\r\n secure: location.protocol === 'https:',\r\n });\r\n\r\nexport const remove = () => Cookies.remove(KEY);\r\n","/*\r\n This function is designed to catch invalid theme values\r\n and handle them before they can break Flarum for users.\r\n\r\n E.g. if a user manually edited their cookies to\r\n set their theme to an invalid value, this theme would\r\n detect that, and reset it to 0 (auto).\r\n*/\r\n\r\nimport Themes from '../common/Themes';\r\nimport { get, set } from './helpers/perDeviceSetting';\r\n\r\nexport default function fixInvalidThemeSetting() {\r\n // get array of valid values without duplicate entries\r\n let validValues = Array.from(new Set(Object.values(Themes)));\r\n\r\n const Theme = get();\r\n\r\n if (isNaN(Theme)) {\r\n resetTheme('Theme is not a valid integer! Resetting...');\r\n } else if (!validValues.includes(Theme)) {\r\n // theme out of bounds\r\n resetTheme(`Theme is out of bounds! Resetting...`);\r\n }\r\n}\r\n\r\nfunction resetTheme(reason) {\r\n console.warn(reason);\r\n\r\n set(Themes.DEFAULT());\r\n}\r\n","import app from 'flarum/common/app';\r\nimport Themes from '../common/Themes';\r\nimport { get } from './helpers/perDeviceSetting';\r\n\r\nexport default function getTheme() {\r\n const user = app.session.user;\r\n\r\n const IsUsingPerDeviceSettings = !user || !!user.preferences().fofNightMode_perDevice;\r\n const SelectedTheme = user && user.preferences().fofNightMode;\r\n\r\n let value;\r\n\r\n if (IsUsingPerDeviceSettings) {\r\n // fetch through LS is per device enabled\r\n value = get();\r\n } else {\r\n if (typeof SelectedTheme === 'number' && SelectedTheme !== -1) {\r\n // use user prefs\r\n value = SelectedTheme;\r\n }\r\n }\r\n\r\n return typeof value === 'number' ? value : Themes.DEFAULT();\r\n}\r\n","import app from 'flarum/common/app';\r\n\r\nimport { extend } from 'flarum/common/extend';\r\nimport Page from 'flarum/common/components/Page';\r\n\r\nimport Themes from './Themes';\r\nimport fixInvalidThemeSetting from '../forum/fixInvalidThemeSetting';\r\nimport getTheme from '../forum/getTheme';\r\n\r\nexport default () => {\r\n extend(Page.prototype, 'oninit', setTheme);\r\n\r\n // Register setTheme() as the handler for 'prefers-color-scheme' media property\r\n // change. This allows to make sure the 'fofnightmodechange' event is dispatched\r\n // when this property changes, and that the correct stylesheets are loaded.\r\n const prefersColorSchemeDark = window.matchMedia('(prefers-color-scheme: dark)');\r\n prefersColorSchemeDark.addEventListener('change', setTheme);\r\n};\r\n\r\nexport function setTheme() {\r\n const { user } = app.session;\r\n\r\n const PerDevice = app.session.user?.preferences().fofNightMode_perDevice;\r\n\r\n if (!user || PerDevice) {\r\n fixInvalidThemeSetting();\r\n }\r\n\r\n if (PerDevice) {\r\n fixInvalidThemeSetting();\r\n }\r\n\r\n const CurrentTheme = getTheme();\r\n\r\n setThemeFromID(CurrentTheme);\r\n}\r\n\r\nexport function getUrls() {\r\n return {\r\n day: app.data['fof-nightmode.assets.day'],\r\n night: app.data['fof-nightmode.assets.night'],\r\n };\r\n}\r\n\r\nexport function setThemeFromID(theme) {\r\n if (theme === Themes.DARK) {\r\n setStyle('night');\r\n } else if (theme === Themes.LIGHT) {\r\n setStyle('day');\r\n } else {\r\n const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches;\r\n\r\n setStyle(preferDark ? 'night' : 'day');\r\n }\r\n}\r\n\r\nexport function setStyle(type) {\r\n const light = document.querySelector('link.nightmode-light[rel=stylesheet]');\r\n const dark = document.querySelector('link.nightmode-dark[rel=stylesheet]');\r\n\r\n bothStyleSheets: if (light && dark) {\r\n if (getTheme() === Themes.AUTO) break bothStyleSheets;\r\n\r\n let newLink = document.createElement('link');\r\n\r\n // onload on link tags not supported in all browsers\r\n // so we should check it is present in the user's\r\n // current browser\r\n if ('onload' in newLink) {\r\n // if it is, only remove the old link tags after the new\r\n // one has finished loading (prevents flash of unstyled\r\n // content)\r\n newLink.onload = function () {\r\n light.remove();\r\n dark.remove();\r\n };\r\n } else {\r\n // if it isn't, just remove the old link tags immediately\r\n light.remove();\r\n dark.remove();\r\n }\r\n\r\n newLink.rel = 'stylesheet';\r\n newLink.className = 'nightmode';\r\n newLink.href = getUrls()[type];\r\n\r\n document.head.append(newLink);\r\n } else {\r\n const el = light || dark || document.querySelector('link.nightmode[rel=stylesheet]');\r\n\r\n const url = getUrls()[type];\r\n\r\n if (url !== el.href) {\r\n el.href = url;\r\n el.className = 'nightmode';\r\n }\r\n }\r\n\r\n const colorScheme = document.querySelector('meta[name=\"color-scheme\"]');\r\n\r\n if (colorScheme) {\r\n colorScheme.content = type === 'night' ? 'dark' : 'light';\r\n }\r\n\r\n // Dispatch a 'fofnightmodechange' event with 'day' or 'night' as detail.\r\n // This allows other extensions to integrate with this one.\r\n const event = new CustomEvent('fofnightmodechange', { detail: type });\r\n document.dispatchEvent(event);\r\n}\r\n","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['forum/app'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['forum/components/SettingsPage'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['forum/components/SessionDropdown'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['forum/components/HeaderSecondary'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/Button'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/LoadingIndicator'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/Select'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/FieldSet'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/Switch'];","import app from 'flarum/forum/app';\r\nimport Themes from '../../common/Themes';\r\nimport { setTheme } from '../../common/setSelectedTheme';\r\nimport getTheme from '../getTheme';\r\nimport * as perDevice from '../helpers/perDeviceSetting';\r\n\r\nexport function getIsLight(theme) {\r\n return theme === Themes.LIGHT || (theme === Themes.AUTO && !window.matchMedia('(prefers-color-scheme: dark)').matches);\r\n}\r\n\r\nfunction toggleThrough(current) {\r\n if (current === Themes.AUTO) {\r\n return Themes.LIGHT;\r\n }\r\n\r\n if (current === Themes.LIGHT) {\r\n return Themes.DARK;\r\n }\r\n\r\n return Themes.AUTO;\r\n}\r\n\r\nexport function switchTheme() {\r\n const theme = getTheme();\r\n const isLight = getIsLight(theme);\r\n const user = app.session.user;\r\n\r\n if (user) {\r\n const val = isLight ? Themes.DARK : Themes.LIGHT;\r\n\r\n if (!!user.preferences().fofNightMode_perDevice) {\r\n perDevice.set(val);\r\n setTheme();\r\n return;\r\n }\r\n\r\n user\r\n .savePreferences({\r\n fofNightMode: val,\r\n })\r\n .then(() => {\r\n // need to force-update selected theme (as it's only set\r\n // on a page load and redraw doesn't count as a page load)\r\n setTheme();\r\n });\r\n } else {\r\n const newTheme = toggleThrough(theme);\r\n\r\n perDevice.set(newTheme);\r\n setTheme();\r\n }\r\n}\r\n","import app from 'flarum/forum/app';\r\nimport { extend } from 'flarum/common/extend';\r\n\r\nimport SettingsPage from 'flarum/forum/components/SettingsPage';\r\nimport SessionDropdown from 'flarum/forum/components/SessionDropdown';\r\nimport HeaderSecondary from 'flarum/forum/components/HeaderSecondary';\r\nimport Button from 'flarum/common/components/Button';\r\nimport LoadingIndicator from 'flarum/common/components/LoadingIndicator';\r\nimport Select from 'flarum/common/components/Select';\r\nimport FieldSet from 'flarum/common/components/FieldSet';\r\nimport Switch from 'flarum/common/components/Switch';\r\n\r\nimport { setTheme } from '../common/setSelectedTheme';\r\nimport fixInvalidThemeSetting from './fixInvalidThemeSetting';\r\nimport * as perDevice from './helpers/perDeviceSetting';\r\nimport getTheme from './getTheme';\r\nimport Themes from '../common/Themes';\r\nimport { switchTheme, getIsLight } from './helpers/switchTheme';\r\n\r\n// custom function for translations makes it a lot cleaner\r\nconst trans = (key) => app.translator.trans(`fof-nightmode.forum.user.settings.${key}`);\r\n\r\nexport default function () {\r\n extend(SettingsPage.prototype, 'settingsItems', function (items) {\r\n const { user } = app.session;\r\n\r\n const PerDevice = !!user.preferences().fofNightMode_perDevice;\r\n\r\n if (PerDevice) {\r\n fixInvalidThemeSetting();\r\n }\r\n\r\n const doesNotSupportAuto = !window.matchMedia('not all and (prefers-color-scheme), (prefers-color-scheme)').matches;\r\n\r\n let currentTheme = getTheme();\r\n\r\n const options = { 0: trans('options.auto'), 1: trans('options.day'), 2: trans('options.night') };\r\n\r\n if (doesNotSupportAuto) {\r\n delete options['0'];\r\n\r\n if (currentTheme === Themes.AUTO) {\r\n currentTheme = app.forum.attribute('fofNightMode_autoUnsupportedFallback');\r\n }\r\n }\r\n\r\n items.add(\r\n 'fof-nightmode',\r\n FieldSet.component(\r\n {\r\n label: trans('heading'),\r\n className: 'Settings-theme',\r\n },\r\n [\r\n

{trans('description')}

,\r\n

{trans('description2')}

,\r\n doesNotSupportAuto ?

{trans('auto_unsupported')}

: null,\r\n Switch.component(\r\n {\r\n className: 'Settings-theme--per_device_cb',\r\n state: PerDevice,\r\n onchange: (checked) => {\r\n if (checked) {\r\n // save current theme as this device's default\r\n perDevice.set(currentTheme);\r\n } else {\r\n perDevice.remove();\r\n }\r\n\r\n user\r\n .savePreferences({\r\n fofNightMode_perDevice: checked,\r\n })\r\n .then(() => {\r\n // need to force-update selected theme (as it's only set\r\n // on a page load and redraw doesn't count as a page load)\r\n setTheme();\r\n });\r\n },\r\n },\r\n trans('device_specific_setting_checkbox')\r\n ),\r\n Select.component({\r\n value: currentTheme,\r\n className: 'Settings-theme--input',\r\n onchange: (e) => {\r\n if (PerDevice) {\r\n perDevice.set(e);\r\n\r\n setTheme();\r\n return;\r\n }\r\n\r\n user\r\n .savePreferences({\r\n fofNightMode: e,\r\n })\r\n .then(() => {\r\n m.redraw();\r\n\r\n // need to force-update selected theme (as it's only set\r\n // on a page load and redraw doesn't count as a apge load)\r\n setTheme();\r\n });\r\n },\r\n options,\r\n }),\r\n

\r\n {currentTheme === Themes.AUTO\r\n ? trans('option_descriptions.auto')\r\n : currentTheme === Themes.LIGHT\r\n ? trans('option_descriptions.day')\r\n : currentTheme === Themes.DARK\r\n ? trans('option_descriptions.night')\r\n : // prevents nasty paragraph switching\r\n LoadingIndicator.component()}\r\n

,\r\n ]\r\n )\r\n );\r\n });\r\n\r\n extend(HeaderSecondary.prototype, 'items', function (items) {\r\n if (app.session.user && !app.forum.attribute('fofNightMode.showThemeToggleOnHeaderAlways')) return;\r\n\r\n const theme = getTheme();\r\n const isLight = getIsLight(theme);\r\n const iconPrefix = app.forum.attribute('fofNightMode.showThemeToggleInSolid') ? 'fas fa-' : 'far fa-';\r\n items.add(\r\n 'nightmode',\r\n {\r\n // const newTheme = toggleThrough(theme);\r\n\r\n // perDevice.set(newTheme);\r\n // setTheme();\r\n switchTheme();\r\n }}\r\n icon={theme === Themes.AUTO ? 'fas fa-adjust' : `${isLight ? iconPrefix+'sun' : iconPrefix+'moon'}`}\r\n >\r\n {app.translator.trans('fof-nightmode.forum.header.nightmode_button')}\r\n ,\r\n 15\r\n );\r\n });\r\n\r\n extend(SessionDropdown.prototype, 'items', function (items) {\r\n if (!app.session.user) return;\r\n\r\n const isLight = getIsLight(getTheme());\r\n const iconPrefix = app.forum.attribute('fofNightMode.showThemeToggleInSolid') ? 'fas fa-' : 'far fa-';\r\n\r\n // Add night mode link to session dropdown\r\n items.add(\r\n isLight ? 'nightmode' : 'daymode',\r\n Button.component(\r\n {\r\n icon: `${isLight ? iconPrefix+'moon' : iconPrefix+'sun'}`,\r\n onclick: () => {\r\n switchTheme();\r\n // const val = isLight ? Themes.DARK : Themes.LIGHT;\r\n\r\n // if (!!user.preferences().fofNightMode_perDevice) {\r\n // perDevice.set(val);\r\n // setTheme();\r\n // return;\r\n // }\r\n\r\n // user\r\n // .savePreferences({\r\n // fofNightMode: val,\r\n // })\r\n // .then(() => {\r\n // // need to force-update selected theme (as it's only set\r\n // // on a page load and redraw doesn't count as a apge load)\r\n // setTheme();\r\n // });\r\n },\r\n },\r\n app.translator.trans(`fof-nightmode.forum.${isLight ? 'night' : 'day'}`)\r\n ),\r\n -1\r\n );\r\n });\r\n}\r\n","import app from 'flarum/forum/app';\r\nimport addSettingsItems from './addSettingsItems';\r\nimport setSelectedTheme from '../common/setSelectedTheme';\r\n\r\nexport * as perDeviceSetting from './helpers/perDeviceSetting';\r\nexport * as switchTheme from './helpers/switchTheme';\r\nexport { default as getTheme } from './getTheme';\r\n\r\napp.initializers.add('fof-nightmode', () => {\r\n addSettingsItems();\r\n setSelectedTheme();\r\n});\r\n"],"names":["__webpack_require__","module","getter","__esModule","d","a","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","flarum","core","compat","AUTO","LIGHT","DARK","DEFAULT","app","attribute","__assign","assign","t","s","i","n","arguments","length","p","apply","this","stringifyAttribute","name","stringified","set","attributes","document","cookie","encodeURIComponent","replace","decodeURIComponent","expires","Date","setMilliseconds","getMilliseconds","toUTCString","domain","path","secure","sameSite","stringifyAttributes","encode","KEY","cookieString","result","_i","cookies_1","split","parts","slice","join","e","parse","Number","Themes","val","Cookies","location","protocol","remove","fixInvalidThemeSetting","validValues","Array","from","Set","values","Theme","isNaN","resetTheme","includes","reason","console","warn","getTheme","user","IsUsingPerDeviceSettings","preferences","fofNightMode_perDevice","SelectedTheme","fofNightMode","extend","Page","setTheme","window","matchMedia","addEventListener","_app$session$user","PerDevice","setThemeFromID","getUrls","day","night","theme","setStyle","matches","type","light","querySelector","dark","bothStyleSheets","newLink","createElement","onload","rel","className","href","head","append","el","url","colorScheme","content","event","CustomEvent","detail","dispatchEvent","getIsLight","switchTheme","current","isLight","perDevice","savePreferences","then","newTheme","trans","add","SettingsPage","items","doesNotSupportAuto","currentTheme","options","FieldSet","label","m","class","Switch","state","onchange","checked","Select","redraw","LoadingIndicator","HeaderSecondary","iconPrefix","Button","onclick","icon","SessionDropdown","setSelectedTheme"],"sourceRoot":""} \ No newline at end of file diff --git a/js/src/forum/addSettingsItems.js b/js/src/forum/addSettingsItems.js index c8522a8..6ed29b7 100755 --- a/js/src/forum/addSettingsItems.js +++ b/js/src/forum/addSettingsItems.js @@ -125,7 +125,7 @@ export default function () { const theme = getTheme(); const isLight = getIsLight(theme); - const icon_prefix = app.forum.attribute('fofNightMode.showThemeToggleInSolid') ? 'fas fa-' : 'far fa-'; + const iconPrefix = app.forum.attribute('fofNightMode.showThemeToggleInSolid') ? 'fas fa-' : 'far fa-'; items.add( 'nightmode', , @@ -149,14 +149,14 @@ export default function () { if (!app.session.user) return; const isLight = getIsLight(getTheme()); - const icon_prefix = app.forum.attribute('fofNightMode.showThemeToggleInSolid') ? 'fas fa-' : 'far fa-'; + const iconPrefix = app.forum.attribute('fofNightMode.showThemeToggleInSolid') ? 'fas fa-' : 'far fa-'; // Add night mode link to session dropdown items.add( isLight ? 'nightmode' : 'daymode', Button.component( { - icon: `${isLight ? icon_prefix+'moon' : icon_prefix+'sun'}`, + icon: `${isLight ? iconPrefix+'moon' : iconPrefix+'sun'}`, onclick: () => { switchTheme(); // const val = isLight ? Themes.DARK : Themes.LIGHT;