diff --git a/js/dist/admin.js b/js/dist/admin.js index 01c0a75..db298df 100755 --- a/js/dist/admin.js +++ b/js/dist/admin.js @@ -1,2 +1,2 @@ -(()=>{var e={116:function(e,t){"use strict";var n=this&&this.__assign||function(){return n=Object.assign||function(e){for(var t,n=1,o=arguments.length;n{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};(()=>{"use strict";n.r(o);const e=flarum.core.compat["admin/app"];var t=n.n(e);const r=flarum.core.compat["common/app"];var a=n.n(r);const i=flarum.core.compat["common/extend"],s=flarum.core.compat["common/components/Page"];var c=n.n(s),l="fof-nightmode.default_theme";const d={AUTO:0,LIGHT:1,DARK:2,DEFAULT:function(){var e;return Number.parseInt((null==(e=a().data.settings)?void 0:e[l])||a().data[l])||0}};var u=n(116),f="flarum_nightmode",m=function(){var e=u.get(f);return e||"0"===e?Number(e):d.DEFAULT()};function p(){var e=Array.from(new Set(Object.values(d))),t=m();isNaN(t)?h("Theme is not a valid integer! Resetting..."):e.includes(t)||h("Theme is out of bounds! Resetting...")}function h(e){var t;console.warn(e),t=d.DEFAULT(),u.set(f,t,{sameSite:"lax",secure:"https:"===location.protocol})}function g(){var e,t=a().session.user,n=!t||!!t.preferences().fofNightMode_perDevice,o=t&&t.preferences().fofNightMode;return n?e=m():"number"==typeof o&&-1!==o&&(e=o),"number"==typeof e?e:d.DEFAULT()}function v(){var e,t,n=a().session.user,o=null==(e=a().session.user)?void 0:e.preferences().fofNightMode_perDevice;n&&!o||p(),o&&p(),b((t=g())===d.DARK?"night":t===d.LIGHT?"day":window.matchMedia("(prefers-color-scheme: dark)").matches?"night":"day")}function y(){return{day:a().data["fof-nightmode.assets.day"],night:a().data["fof-nightmode.assets.night"]}}function b(e){var t=document.querySelector("link.nightmode-light[rel=stylesheet]"),n=document.querySelector("link.nightmode-dark[rel=stylesheet]");if(t&&n){if(g()===d.AUTO)return;var o=document.createElement("link");"onload"in o?o.onload=function(){t.remove(),n.remove()}:(t.remove(),n.remove()),o.rel="stylesheet",o.className="nightmode",o.href=y()[e],document.head.append(o)}else{var r=t||n||document.querySelector("link.nightmode[rel=stylesheet]"),a=y()[e];a!==r.href&&(r.href=a,r.className="nightmode")}}t().initializers.add("fof-nightmode",(function(){var e;t().extensionData.for("fof-nightmode").registerSetting({label:t().translator.trans("fof-nightmode.admin.settings.modal.default_theme"),setting:"fof-nightmode.default_theme",type:"select",options:(e={},Object.keys(d).forEach((function(n,o){"DEFAULT"!==n&&(e[o]=t().translator.trans("fof-nightmode.admin.settings.modal.theme_"+n.toLowerCase()))})),e)}).registerSetting({label:t().translator.trans("fof-nightmode.admin.settings.modal.default_theme_helper"),type:"hidden"}),(0,i.extend)(c().prototype,"oninit",v)}))})(),module.exports=o})(); +(()=>{var e={116:function(e,t){"use strict";var n=this&&this.__assign||function(){return n=Object.assign||function(e){for(var t,n=1,o=arguments.length;n{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};(()=>{"use strict";n.r(o);const e=flarum.core.compat["admin/app"];var t=n.n(e);const r=flarum.core.compat["common/app"];var a=n.n(r);const i=flarum.core.compat["common/extend"],s=flarum.core.compat["common/components/Page"];var c=n.n(s),l="fof-nightmode.default_theme";const d={AUTO:0,LIGHT:1,DARK:2,DEFAULT:function(){var e;return Number.parseInt((null==(e=a().data.settings)?void 0:e[l])||a().data[l])||0}};var m=n(116),f="flarum_nightmode",u=function(){var e=m.get(f);return e||"0"===e?Number(e):d.DEFAULT()};function p(){var e=Array.from(new Set(Object.values(d))),t=u();isNaN(t)?h("Theme is not a valid integer! Resetting..."):e.includes(t)||h("Theme is out of bounds! Resetting...")}function h(e){var t;console.warn(e),t=d.DEFAULT(),m.set(f,t,{sameSite:"lax",secure:"https:"===location.protocol})}function g(){var e,t=a().session.user,n=!t||!!t.preferences().fofNightMode_perDevice,o=t&&t.preferences().fofNightMode;return n?e=u():"number"==typeof o&&-1!==o&&(e=o),"number"==typeof e?e:d.DEFAULT()}function v(){var e,t,n=a().session.user,o=null==(e=a().session.user)?void 0:e.preferences().fofNightMode_perDevice;n&&!o||p(),o&&p(),_((t=g())===d.DARK?"night":t===d.LIGHT?"day":window.matchMedia("(prefers-color-scheme: dark)").matches?"night":"day")}function y(){return{day:a().data["fof-nightmode.assets.day"],night:a().data["fof-nightmode.assets.night"]}}function _(e){var t=document.querySelector("link.nightmode-light[rel=stylesheet]"),n=document.querySelector("link.nightmode-dark[rel=stylesheet]");if(t&&n){if(g()===d.AUTO)return;var o=document.createElement("link");"onload"in o?o.onload=function(){t.remove(),n.remove()}:(t.remove(),n.remove()),o.rel="stylesheet",o.className="nightmode",o.href=y()[e],document.head.append(o)}else{var r=t||n||document.querySelector("link.nightmode[rel=stylesheet]"),a=y()[e];a!==r.href&&(r.href=a,r.className="nightmode")}}t().initializers.add("fof-nightmode",(function(){var e;t().extensionData.for("fof-nightmode").registerSetting({label:t().translator.trans("fof-nightmode.admin.settings.modal.always_show_theme_toggle_on_header"),setting:"fofNightMode.show_theme_toggle_on_header_always",type:"switch"}).registerSetting({label:t().translator.trans("fof-nightmode.admin.settings.modal.default_theme"),setting:"fof-nightmode.default_theme",type:"select",options:(e={},Object.keys(d).forEach((function(n,o){"DEFAULT"!==n&&(e[o]=t().translator.trans("fof-nightmode.admin.settings.modal.theme_"+n.toLowerCase()))})),e)}).registerSetting({label:t().translator.trans("fof-nightmode.admin.settings.modal.default_theme_helper"),type:"hidden"}),(0,i.extend)(c().prototype,"oninit",v)}))})(),module.exports=o})(); //# sourceMappingURL=admin.js.map \ No newline at end of file diff --git a/js/dist/admin.js.map b/js/dist/admin.js.map index 9277cdf..28b5e4b 100755 --- a/js/dist/admin.js.map +++ b/js/dist/admin.js.map @@ -1 +1 @@ -{"version":3,"file":"admin.js","mappings":"4CACA,IAAIA,EAAYC,MAAQA,KAAKD,UAAa,WAStC,OARAA,EAAWE,OAAOC,QAAU,SAASC,GACjC,IAAK,IAAIC,EAAGC,EAAI,EAAGC,EAAIC,UAAUC,OAAQH,EAAIC,EAAGD,IAE5C,IAAK,IAAII,KADTL,EAAIG,UAAUF,GACOJ,OAAOS,UAAUC,eAAeC,KAAKR,EAAGK,KACzDN,EAAEM,GAAKL,EAAEK,IAEjB,OAAON,GAEJJ,EAASc,MAAMb,KAAMO,YAGhC,SAASO,EAAmBC,EAAMC,GAC9B,IAAKA,EACD,MAAO,GAEX,IAAIC,EAAc,KAAOF,EACzB,OAAc,IAAVC,EACOC,EAEJA,EAAc,IAAMD,EAc/B,SAASE,EAAOH,EAAMC,EAAOG,GACzB,OAAOC,mBAAmBL,GACrBM,QAAQ,2BAA4BC,oBACpCD,QAAQ,MAAO,OAAOA,QAAQ,MAAO,OACpC,IAAMD,mBAAmBJ,GAE1BK,QAAQ,4DAA6DC,oBAlB9E,SAA6BH,GACzB,GAAkC,iBAAvBA,EAAWI,QAAsB,CACxC,IAAIA,EAAU,IAAIC,KAClBD,EAAQE,gBAAgBF,EAAQG,kBAAyC,MAArBP,EAAWI,SAC/DJ,EAAWI,QAAUA,EAEzB,OAAOT,EAAmB,UAAWK,EAAWI,QAAUJ,EAAWI,QAAQI,cAAgB,IACvFb,EAAmB,SAAUK,EAAWS,QACxCd,EAAmB,OAAQK,EAAWU,MACtCf,EAAmB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B5C,IAAAA,aAAAA,IAAqB,iBAAiB,WAbtC,IACMkD,EAaJlD,IAAAA,cAAAA,IACO,iBACJmD,gBAAgB,CACfC,MAAOpD,IAAAA,WAAAA,MAAqB,oDAC5BqD,QAAS,8BACTjB,KAAM,SACNc,SAnBAA,EAAU,GAGdnI,OAAOuI,KAAKpD,GAAQqD,SAAQ,SAAC5B,EAAOxG,GACpB,YAAVwG,IAEJuB,EAAQ/H,GAAK6E,IAAAA,WAAAA,MAAA,4CAAiE2B,EAAM6B,mBAG/EN,KAYJC,gBAAgB,CACfC,MAAOpD,IAAAA,WAAAA,MAAqB,2DAC5BoC,KAAM,YDlBVqB,EAAAA,EAAAA,QAAOC,IAAAA,UAAgB,SAAUhC,O","sources":["webpack://@fof/nightmode/./node_modules/es-cookie/src/es-cookie.js","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['admin/app']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/app']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/extend']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/Page']\"","webpack://@fof/nightmode/./src/common/Themes.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/./src/admin/index.js"],"sourcesContent":["\"use strict\";\r\nvar __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\nexports.__esModule = true;\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\nfunction encode(name, value, attributes) {\r\n return encodeURIComponent(name)\r\n .replace(/%(23|24|26|2B|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(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent)\r\n + stringifyAttributes(attributes);\r\n}\r\nexports.encode = encode;\r\nfunction parse(cookieString) {\r\n var result = {};\r\n var cookies = cookieString ? cookieString.split('; ') : [];\r\n var rdecode = /(%[\\dA-F]{2})+/gi;\r\n for (var i = 0; i < cookies.length; i++) {\r\n var parts = cookies[i].split('=');\r\n var cookie = parts.slice(1).join('=');\r\n if (cookie.charAt(0) === '\"') {\r\n cookie = cookie.slice(1, -1);\r\n }\r\n try {\r\n var name_1 = parts[0].replace(rdecode, decodeURIComponent);\r\n result[name_1] = cookie.replace(rdecode, 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\nexports.parse = parse;\r\nfunction getAll() {\r\n return parse(document.cookie);\r\n}\r\nexports.getAll = getAll;\r\nfunction get(name) {\r\n return getAll()[name];\r\n}\r\nexports.get = get;\r\nfunction set(name, value, attributes) {\r\n document.cookie = encode(name, value, __assign({ path: '/' }, attributes));\r\n}\r\nexports.set = set;\r\nfunction remove(name, attributes) {\r\n set(name, '', __assign(__assign({}, attributes), { expires: -1 }));\r\n}\r\nexports.remove = remove;\r\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\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['admin/app'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/app'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/extend'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/Page'];","import app from 'flarum/common/app';\n\n/*\n\n JS enum equivalent. Makes sure no value mix-ups are made!\n\n DEFAULT is used when an invalid value has been set, as well as for guest and new users.\n\n*/\n\nconst KEY = 'fof-nightmode.default_theme';\n\nconst Themes = {\n AUTO: 0,\n LIGHT: 1,\n DARK: 2,\n\n // adds an \"ultra default\" of 0 if the admins don't set a default tsk tsk tsk\n DEFAULT: () => Number.parseInt(app.data.settings?.[KEY] || app.data[KEY]) || 0,\n};\n\nexport default Themes;\n","import * as Cookies from 'es-cookie';\nimport Themes from '../../common/Themes';\n\nexport const KEY = 'flarum_nightmode';\n\nexport const get = () => {\n const value = Cookies.get(KEY);\n\n if (!value && value !== '0') {\n return Themes.DEFAULT();\n }\n\n return Number(value);\n};\n\nexport const set = (val) =>\n Cookies.set(KEY, val, {\n sameSite: 'lax',\n secure: location.protocol === 'https:',\n });\n\nexport const remove = () => Cookies.remove(KEY);\n","/*\n This function is designed to catch invalid theme values\n and handle them before they can break Flarum for users.\n\n E.g. if a user manually edited their cookies to\n set their theme to an invalid value, this theme would\n detect that, and reset it to 0 (auto).\n*/\n\nimport Themes from '../common/Themes';\nimport { get, set } from './helpers/perDeviceSetting';\n\nexport default function fixInvalidThemeSetting() {\n // get array of valid values without duplicate entries\n let validValues = Array.from(new Set(Object.values(Themes)));\n\n const Theme = get();\n\n if (isNaN(Theme)) {\n resetTheme('Theme is not a valid integer! Resetting...');\n } else if (!validValues.includes(Theme)) {\n // theme out of bounds\n resetTheme(`Theme is out of bounds! Resetting...`);\n }\n}\n\nfunction resetTheme(reason) {\n console.warn(reason);\n\n set(Themes.DEFAULT());\n}\n","import app from 'flarum/common/app';\nimport Themes from '../common/Themes';\nimport { get } from './helpers/perDeviceSetting';\n\nexport default function getTheme() {\n const user = app.session.user;\n\n const IsUsingPerDeviceSettings = !user || !!user.preferences().fofNightMode_perDevice;\n const SelectedTheme = user && user.preferences().fofNightMode;\n\n let value;\n\n if (IsUsingPerDeviceSettings) {\n // fetch through LS is per device enabled\n value = get();\n } else {\n if (typeof SelectedTheme === 'number' && SelectedTheme !== -1) {\n // use user prefs\n value = SelectedTheme;\n }\n }\n\n return typeof value === 'number' ? value : Themes.DEFAULT();\n}\n","import app from 'flarum/common/app';\n\nimport { extend } from 'flarum/common/extend';\nimport Page from 'flarum/common/components/Page';\n\nimport Themes from './Themes';\nimport fixInvalidThemeSetting from '../forum/fixInvalidThemeSetting';\nimport getTheme from '../forum/getTheme';\n\nexport default () => {\n extend(Page.prototype, 'oninit', setTheme);\n};\n\nexport function setTheme() {\n const { user } = app.session;\n\n const PerDevice = app.session.user?.preferences().fofNightMode_perDevice;\n\n if (!user || PerDevice) {\n fixInvalidThemeSetting();\n }\n\n if (PerDevice) {\n fixInvalidThemeSetting();\n }\n\n const CurrentTheme = getTheme();\n\n setThemeFromID(CurrentTheme);\n}\n\nexport function getUrls() {\n return {\n day: app.data['fof-nightmode.assets.day'],\n night: app.data['fof-nightmode.assets.night'],\n };\n}\n\nexport function setThemeFromID(theme) {\n if (theme === Themes.DARK) {\n setStyle('night');\n } else if (theme === Themes.LIGHT) {\n setStyle('day');\n } else {\n const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches;\n\n setStyle(preferDark ? 'night' : 'day');\n }\n}\n\nexport function setStyle(type) {\n const light = document.querySelector('link.nightmode-light[rel=stylesheet]');\n const dark = document.querySelector('link.nightmode-dark[rel=stylesheet]');\n\n if (light && dark) {\n if (getTheme() === Themes.AUTO) return;\n\n let newLink = document.createElement('link');\n\n // onload on link tags not supported in all browsers\n // so we should check it is present in the user's\n // current browser\n if ('onload' in newLink) {\n // if it is, only remove the old link tags after the new\n // one has finished loading (prevents flash of unstyled\n // content)\n newLink.onload = function () {\n light.remove();\n dark.remove();\n };\n } else {\n // if it isn't, just remove the old link tags immediately\n light.remove();\n dark.remove();\n }\n\n newLink.rel = 'stylesheet';\n newLink.className = 'nightmode';\n newLink.href = getUrls()[type];\n\n document.head.append(newLink);\n } else {\n const el = light || dark || document.querySelector('link.nightmode[rel=stylesheet]');\n\n const url = getUrls()[type];\n\n if (url !== el.href) {\n el.href = url;\n el.className = 'nightmode';\n }\n }\n}\n","import app from 'flarum/admin/app';\nimport setSelectedTheme from '../common/setSelectedTheme';\nimport Themes from '../common/Themes';\n\nfunction populateThemes() {\n let options = {};\n\n // add themes based on JS enum\n Object.keys(Themes).forEach((theme, i) => {\n if (theme === 'DEFAULT') return;\n\n options[i] = app.translator.trans(`fof-nightmode.admin.settings.modal.theme_${theme.toLowerCase()}`);\n });\n\n return options;\n}\n\napp.initializers.add('fof-nightmode', () => {\n app.extensionData\n .for('fof-nightmode')\n .registerSetting({\n label: app.translator.trans('fof-nightmode.admin.settings.modal.default_theme'),\n setting: 'fof-nightmode.default_theme',\n type: 'select',\n options: populateThemes(),\n })\n .registerSetting({\n label: app.translator.trans('fof-nightmode.admin.settings.modal.default_theme_helper'),\n type: 'hidden',\n });\n\n setSelectedTheme();\n});\n"],"names":["__assign","this","Object","assign","t","s","i","n","arguments","length","p","prototype","hasOwnProperty","call","apply","stringifyAttribute","name","value","stringified","encode","attributes","encodeURIComponent","replace","decodeURIComponent","expires","Date","setMilliseconds","getMilliseconds","toUTCString","domain","path","secure","sameSite","stringifyAttributes","parse","cookieString","result","cookies","split","rdecode","parts","cookie","slice","join","charAt","e","getAll","document","set","exports","__esModule","get","remove","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","module","__webpack_modules__","getter","d","a","definition","key","o","defineProperty","enumerable","obj","prop","r","Symbol","toStringTag","flarum","core","compat","KEY","AUTO","LIGHT","DARK","DEFAULT","Number","parseInt","app","Cookies","Themes","fixInvalidThemeSetting","validValues","Array","from","Set","values","Theme","isNaN","resetTheme","includes","reason","val","console","warn","location","protocol","getTheme","user","IsUsingPerDeviceSettings","preferences","fofNightMode_perDevice","SelectedTheme","fofNightMode","setTheme","theme","PerDevice","setStyle","window","matchMedia","matches","getUrls","day","night","type","light","querySelector","dark","newLink","createElement","onload","rel","className","href","head","append","el","url","options","registerSetting","label","setting","keys","forEach","toLowerCase","extend","Page"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"admin.js","mappings":"4CACA,IAAIA,EAAYC,MAAQA,KAAKD,UAAa,WAStC,OARAA,EAAWE,OAAOC,QAAU,SAASC,GACjC,IAAK,IAAIC,EAAGC,EAAI,EAAGC,EAAIC,UAAUC,OAAQH,EAAIC,EAAGD,IAE5C,IAAK,IAAII,KADTL,EAAIG,UAAUF,GACOJ,OAAOS,UAAUC,eAAeC,KAAKR,EAAGK,KACzDN,EAAEM,GAAKL,EAAEK,IAEjB,OAAON,GAEJJ,EAASc,MAAMb,KAAMO,YAGhC,SAASO,EAAmBC,EAAMC,GAC9B,IAAKA,EACD,MAAO,GAEX,IAAIC,EAAc,KAAOF,EACzB,OAAc,IAAVC,EACOC,EAEJA,EAAc,IAAMD,EAc/B,SAASE,EAAOH,EAAMC,EAAOG,GACzB,OAAOC,mBAAmBL,GACrBM,QAAQ,2BAA4BC,oBACpCD,QAAQ,MAAO,OAAOA,QAAQ,MAAO,OACpC,IAAMD,mBAAmBJ,GAE1BK,QAAQ,4DAA6DC,oBAlB9E,SAA6BH,GACzB,GAAkC,iBAAvBA,EAAWI,QAAsB,CACxC,IAAIA,EAAU,IAAIC,KAClBD,EAAQE,gBAAgBF,EAAQG,kBAAyC,MAArBP,EAAWI,SAC/DJ,EAAWI,QAAUA,EAEzB,OAAOT,EAAmB,UAAWK,EAAWI,QAAUJ,EAAWI,QAAQI,cAAgB,IACvFb,EAAmB,SAAUK,EAAWS,QACxCd,EAAmB,OAAQK,EAAWU,MACtCf,EAAmB,SAAUK,EAAWW,QACxChB,EAAmB,WAAYK,EAAWY,UAS1CC,CAAoBb,GAG9B,SAASc,EAAMC,GAIX,IAHA,IAAIC,EAAS,GAC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AAAA,WAAAA,MAAqB,yEAC5BqD,QAAS,kDACTjB,KAAM,WAEPe,gBAAgB,CACfC,MAAOpD,IAAAA,WAAAA,MAAqB,oDAC5BqD,QAAS,8BACTjB,KAAM,SACNc,SAxBAA,EAAU,GAGdnI,OAAOuI,KAAKpD,GAAQqD,SAAQ,SAAC5B,EAAOxG,GACpB,YAAVwG,IAEJuB,EAAQ/H,GAAK6E,IAAAA,WAAAA,MAAA,4CAAiE2B,EAAM6B,mBAG/EN,KAiBJC,gBAAgB,CACfC,MAAOpD,IAAAA,WAAAA,MAAqB,2DAC5BoC,KAAM,YDvBVqB,EAAAA,EAAAA,QAAOC,IAAAA,UAAgB,SAAUhC,O","sources":["webpack://@fof/nightmode/./node_modules/es-cookie/src/es-cookie.js","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['admin/app']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/app']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/extend']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/Page']\"","webpack://@fof/nightmode/./src/common/Themes.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/./src/admin/index.js"],"sourcesContent":["\"use strict\";\r\nvar __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\nexports.__esModule = true;\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\nfunction encode(name, value, attributes) {\r\n return encodeURIComponent(name)\r\n .replace(/%(23|24|26|2B|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(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent)\r\n + stringifyAttributes(attributes);\r\n}\r\nexports.encode = encode;\r\nfunction parse(cookieString) {\r\n var result = {};\r\n var cookies = cookieString ? cookieString.split('; ') : [];\r\n var rdecode = /(%[\\dA-F]{2})+/gi;\r\n for (var i = 0; i < cookies.length; i++) {\r\n var parts = cookies[i].split('=');\r\n var cookie = parts.slice(1).join('=');\r\n if (cookie.charAt(0) === '\"') {\r\n cookie = cookie.slice(1, -1);\r\n }\r\n try {\r\n var name_1 = parts[0].replace(rdecode, decodeURIComponent);\r\n result[name_1] = cookie.replace(rdecode, 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\nexports.parse = parse;\r\nfunction getAll() {\r\n return parse(document.cookie);\r\n}\r\nexports.getAll = getAll;\r\nfunction get(name) {\r\n return getAll()[name];\r\n}\r\nexports.get = get;\r\nfunction set(name, value, attributes) {\r\n document.cookie = encode(name, value, __assign({ path: '/' }, attributes));\r\n}\r\nexports.set = set;\r\nfunction remove(name, attributes) {\r\n set(name, '', __assign(__assign({}, attributes), { expires: -1 }));\r\n}\r\nexports.remove = remove;\r\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\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['admin/app'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/app'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/extend'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/Page'];","import app from 'flarum/common/app';\n\n/*\n\n JS enum equivalent. Makes sure no value mix-ups are made!\n\n DEFAULT is used when an invalid value has been set, as well as for guest and new users.\n\n*/\n\nconst KEY = 'fof-nightmode.default_theme';\n\nconst Themes = {\n AUTO: 0,\n LIGHT: 1,\n DARK: 2,\n\n // adds an \"ultra default\" of 0 if the admins don't set a default tsk tsk tsk\n DEFAULT: () => Number.parseInt(app.data.settings?.[KEY] || app.data[KEY]) || 0,\n};\n\nexport default Themes;\n","import * as Cookies from 'es-cookie';\nimport Themes from '../../common/Themes';\n\nexport const KEY = 'flarum_nightmode';\n\nexport const get = () => {\n const value = Cookies.get(KEY);\n\n if (!value && value !== '0') {\n return Themes.DEFAULT();\n }\n\n return Number(value);\n};\n\nexport const set = (val) =>\n Cookies.set(KEY, val, {\n sameSite: 'lax',\n secure: location.protocol === 'https:',\n });\n\nexport const remove = () => Cookies.remove(KEY);\n","/*\n This function is designed to catch invalid theme values\n and handle them before they can break Flarum for users.\n\n E.g. if a user manually edited their cookies to\n set their theme to an invalid value, this theme would\n detect that, and reset it to 0 (auto).\n*/\n\nimport Themes from '../common/Themes';\nimport { get, set } from './helpers/perDeviceSetting';\n\nexport default function fixInvalidThemeSetting() {\n // get array of valid values without duplicate entries\n let validValues = Array.from(new Set(Object.values(Themes)));\n\n const Theme = get();\n\n if (isNaN(Theme)) {\n resetTheme('Theme is not a valid integer! Resetting...');\n } else if (!validValues.includes(Theme)) {\n // theme out of bounds\n resetTheme(`Theme is out of bounds! Resetting...`);\n }\n}\n\nfunction resetTheme(reason) {\n console.warn(reason);\n\n set(Themes.DEFAULT());\n}\n","import app from 'flarum/common/app';\nimport Themes from '../common/Themes';\nimport { get } from './helpers/perDeviceSetting';\n\nexport default function getTheme() {\n const user = app.session.user;\n\n const IsUsingPerDeviceSettings = !user || !!user.preferences().fofNightMode_perDevice;\n const SelectedTheme = user && user.preferences().fofNightMode;\n\n let value;\n\n if (IsUsingPerDeviceSettings) {\n // fetch through LS is per device enabled\n value = get();\n } else {\n if (typeof SelectedTheme === 'number' && SelectedTheme !== -1) {\n // use user prefs\n value = SelectedTheme;\n }\n }\n\n return typeof value === 'number' ? value : Themes.DEFAULT();\n}\n","import app from 'flarum/common/app';\n\nimport { extend } from 'flarum/common/extend';\nimport Page from 'flarum/common/components/Page';\n\nimport Themes from './Themes';\nimport fixInvalidThemeSetting from '../forum/fixInvalidThemeSetting';\nimport getTheme from '../forum/getTheme';\n\nexport default () => {\n extend(Page.prototype, 'oninit', setTheme);\n};\n\nexport function setTheme() {\n const { user } = app.session;\n\n const PerDevice = app.session.user?.preferences().fofNightMode_perDevice;\n\n if (!user || PerDevice) {\n fixInvalidThemeSetting();\n }\n\n if (PerDevice) {\n fixInvalidThemeSetting();\n }\n\n const CurrentTheme = getTheme();\n\n setThemeFromID(CurrentTheme);\n}\n\nexport function getUrls() {\n return {\n day: app.data['fof-nightmode.assets.day'],\n night: app.data['fof-nightmode.assets.night'],\n };\n}\n\nexport function setThemeFromID(theme) {\n if (theme === Themes.DARK) {\n setStyle('night');\n } else if (theme === Themes.LIGHT) {\n setStyle('day');\n } else {\n const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches;\n\n setStyle(preferDark ? 'night' : 'day');\n }\n}\n\nexport function setStyle(type) {\n const light = document.querySelector('link.nightmode-light[rel=stylesheet]');\n const dark = document.querySelector('link.nightmode-dark[rel=stylesheet]');\n\n if (light && dark) {\n if (getTheme() === Themes.AUTO) return;\n\n let newLink = document.createElement('link');\n\n // onload on link tags not supported in all browsers\n // so we should check it is present in the user's\n // current browser\n if ('onload' in newLink) {\n // if it is, only remove the old link tags after the new\n // one has finished loading (prevents flash of unstyled\n // content)\n newLink.onload = function () {\n light.remove();\n dark.remove();\n };\n } else {\n // if it isn't, just remove the old link tags immediately\n light.remove();\n dark.remove();\n }\n\n newLink.rel = 'stylesheet';\n newLink.className = 'nightmode';\n newLink.href = getUrls()[type];\n\n document.head.append(newLink);\n } else {\n const el = light || dark || document.querySelector('link.nightmode[rel=stylesheet]');\n\n const url = getUrls()[type];\n\n if (url !== el.href) {\n el.href = url;\n el.className = 'nightmode';\n }\n }\n}\n","import app from 'flarum/admin/app';\nimport setSelectedTheme from '../common/setSelectedTheme';\nimport Themes from '../common/Themes';\n\nfunction populateThemes() {\n let options = {};\n\n // add themes based on JS enum\n Object.keys(Themes).forEach((theme, i) => {\n if (theme === 'DEFAULT') return;\n\n options[i] = app.translator.trans(`fof-nightmode.admin.settings.modal.theme_${theme.toLowerCase()}`);\n });\n\n return options;\n}\n\napp.initializers.add('fof-nightmode', () => {\n app.extensionData\n .for('fof-nightmode')\n .registerSetting({\n label: app.translator.trans('fof-nightmode.admin.settings.modal.always_show_theme_toggle_on_header'),\n setting: 'fofNightMode.show_theme_toggle_on_header_always',\n type: 'switch',\n })\n .registerSetting({\n label: app.translator.trans('fof-nightmode.admin.settings.modal.default_theme'),\n setting: 'fof-nightmode.default_theme',\n type: 'select',\n options: populateThemes(),\n })\n .registerSetting({\n label: app.translator.trans('fof-nightmode.admin.settings.modal.default_theme_helper'),\n type: 'hidden',\n });\n\n setSelectedTheme();\n});\n"],"names":["__assign","this","Object","assign","t","s","i","n","arguments","length","p","prototype","hasOwnProperty","call","apply","stringifyAttribute","name","value","stringified","encode","attributes","encodeURIComponent","replace","decodeURIComponent","expires","Date","setMilliseconds","getMilliseconds","toUTCString","domain","path","secure","sameSite","stringifyAttributes","parse","cookieString","result","cookies","split","rdecode","parts","cookie","slice","join","charAt","e","getAll","document","set","exports","__esModule","get","remove","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","module","__webpack_modules__","getter","d","a","definition","key","o","defineProperty","enumerable","obj","prop","r","Symbol","toStringTag","flarum","core","compat","KEY","AUTO","LIGHT","DARK","DEFAULT","Number","parseInt","app","Cookies","Themes","fixInvalidThemeSetting","validValues","Array","from","Set","values","Theme","isNaN","resetTheme","includes","reason","val","console","warn","location","protocol","getTheme","user","IsUsingPerDeviceSettings","preferences","fofNightMode_perDevice","SelectedTheme","fofNightMode","setTheme","theme","PerDevice","setStyle","window","matchMedia","matches","getUrls","day","night","type","light","querySelector","dark","newLink","createElement","onload","rel","className","href","head","append","el","url","options","registerSetting","label","setting","keys","forEach","toLowerCase","extend","Page"],"sourceRoot":""} \ No newline at end of file diff --git a/js/dist/forum.js b/js/dist/forum.js index 475a12e..e5118aa 100755 --- a/js/dist/forum.js +++ b/js/dist/forum.js @@ -1,2 +1,2 @@ -(()=>{var e={116:function(e,o){"use strict";var t=this&&this.__assign||function(){return t=Object.assign||function(e){for(var o,t=1,n=arguments.length;t{var o=e&&e.__esModule?()=>e.default:()=>e;return t.d(o,{a:o}),o},t.d=(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})},t.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};(()=>{"use strict";t.r(n);const e=flarum.core.compat["forum/app"];var o=t.n(e);const r=flarum.core.compat["common/extend"],c=flarum.core.compat["forum/components/SettingsPage"];var i=t.n(c);const a=flarum.core.compat["forum/components/SessionDropdown"];var s=t.n(a);const u=flarum.core.compat["forum/components/HeaderSecondary"];var f=t.n(u);const d=flarum.core.compat["common/components/Button"];var p=t.n(d);const l=flarum.core.compat["common/components/LoadingIndicator"];var h=t.n(l);const g=flarum.core.compat["common/components/Select"];var v=t.n(g);const y=flarum.core.compat["common/components/FieldSet"];var _=t.n(y);const S=flarum.core.compat["common/components/Switch"];var T=t.n(S);flarum.core.compat["common/helpers/icon"];const b=flarum.core.compat["common/app"];var N=t.n(b);const A=flarum.core.compat["common/components/Page"];var U=t.n(A),x="fof-nightmode.default_theme";const D={AUTO:0,LIGHT:1,DARK:2,DEFAULT:function(){var e;return Number.parseInt((null==(e=N().data.settings)?void 0:e[x])||N().data[x])||0}};var M=t(116),O="flarum_nightmode",I=function(){var e=M.get(O);return e||"0"===e?Number(e):D.DEFAULT()},w=function(e){return M.set(O,e,{sameSite:"lax",secure:"https:"===location.protocol})};function k(){var e=Array.from(new Set(Object.values(D))),o=I();isNaN(o)?R("Theme is not a valid integer! Resetting..."):e.includes(o)||R("Theme is out of bounds! Resetting...")}function R(e){console.warn(e),w(D.DEFAULT())}function L(){var e,o=N().session.user,t=!o||!!o.preferences().fofNightMode_perDevice,n=o&&o.preferences().fofNightMode;return t?e=I():"number"==typeof n&&-1!==n&&(e=n),"number"==typeof e?e:D.DEFAULT()}function P(){var e,o,t=N().session.user,n=null==(e=N().session.user)?void 0:e.preferences().fofNightMode_perDevice;t&&!n||k(),n&&k(),j((o=L())===D.DARK?"night":o===D.LIGHT?"day":window.matchMedia("(prefers-color-scheme: dark)").matches?"night":"day")}function C(){return{day:N().data["fof-nightmode.assets.day"],night:N().data["fof-nightmode.assets.night"]}}function j(e){var o=document.querySelector("link.nightmode-light[rel=stylesheet]"),t=document.querySelector("link.nightmode-dark[rel=stylesheet]");if(o&&t){if(L()===D.AUTO)return;var n=document.createElement("link");"onload"in n?n.onload=function(){o.remove(),t.remove()}:(o.remove(),t.remove()),n.rel="stylesheet",n.className="nightmode",n.href=C()[e],document.head.append(n)}else{var r=o||t||document.querySelector("link.nightmode[rel=stylesheet]"),c=C()[e];c!==r.href&&(r.href=c,r.className="nightmode")}}var E=function(e){return o().translator.trans("fof-nightmode.forum.user.settings."+e)},F=function(e){return e===D.LIGHT||e===D.AUTO&&!window.matchMedia("(prefers-color-scheme: dark)").matches};o().initializers.add("fof-nightmode",(function(){(0,r.extend)(i().prototype,"settingsItems",(function(e){var t=o().session.user,n=!!t.preferences().fofNightMode_perDevice;n&&k();var r=!window.matchMedia("not all and (prefers-color-scheme), (prefers-color-scheme)").matches,c=L(),i={0:E("options.auto"),1:E("options.day"),2:E("options.night")};r&&(delete i[0],c===D.AUTO&&(c=o().forum.attribute("fofNightMode_autoUnsupportedFallback"))),e.add("fof-nightmode",_().component({label:E("heading"),className:"Settings-theme"},[m("p",{className:"description"},E("description")),m("p",{className:"description"},E("description2")),r?m("p",{class:"description NightMode-autoUnsupported"},E("auto_unsupported")):null,T().component({className:"Settings-theme--per_device_cb",state:n,onchange:function(e){e?w(c):M.remove(O),t.savePreferences({fofNightMode_perDevice:e}).then((function(){P()}))}},E("device_specific_setting_checkbox")),v().component({value:c,className:"Settings-theme--input",onchange:function(e){if(n)return w(e),void P();t.savePreferences({fofNightMode:e}).then((function(){m.redraw(),P()}))},options:i}),m("p",{className:"Settings-theme--selection_description"},c===D.AUTO?E("option_descriptions.auto"):c===D.LIGHT?E("option_descriptions.day"):c===D.DARK?E("option_descriptions.night"):h().component())]))})),(0,r.extend)(f().prototype,"items",(function(e){if(!o().session.user){var t=L(),n=F(t);e.add("nightmode",m(p(),{className:"Button Button--flat",onclick:function(){var e,o=(e=t)===D.AUTO?D.LIGHT:e===D.LIGHT?D.DARK:D.AUTO;w(o),P()},icon:t===D.AUTO?"fas fa-adjust":"far fa-"+(n?"sun":"moon")},o().translator.trans("fof-nightmode.forum.header.nightmode_button")),15)}})),(0,r.extend)(s().prototype,"items",(function(e){if(o().session.user){var t=o().session.user,n=F(L());e.add(n?"nightmode":"daymode",p().component({icon:"far fa-"+(n?"moon":"sun"),onclick:function(){var e=n?D.DARK:D.LIGHT;if(t.preferences().fofNightMode_perDevice)return w(e),void P();t.savePreferences({fofNightMode:e}).then((function(){P()}))}},o().translator.trans("fof-nightmode.forum."+(n?"night":"day"))),-1)}})),(0,r.extend)(U().prototype,"oninit",P)}))})(),module.exports=n})(); +(()=>{var e={116:function(e,o){"use strict";var t=this&&this.__assign||function(){return t=Object.assign||function(e){for(var o,t=1,n=arguments.length;t{var o=e&&e.__esModule?()=>e.default:()=>e;return t.d(o,{a:o}),o},t.d=(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})},t.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};(()=>{"use strict";t.r(n);const e=flarum.core.compat["forum/app"];var o=t.n(e);const r=flarum.core.compat["common/extend"],i=flarum.core.compat["forum/components/SettingsPage"];var s=t.n(i);const a=flarum.core.compat["forum/components/SessionDropdown"];var c=t.n(a);const u=flarum.core.compat["forum/components/HeaderSecondary"];var f=t.n(u);const d=flarum.core.compat["common/components/Button"];var p=t.n(d);const l=flarum.core.compat["common/components/LoadingIndicator"];var h=t.n(l);const g=flarum.core.compat["common/components/Select"];var v=t.n(g);const y=flarum.core.compat["common/components/FieldSet"];var _=t.n(y);const T=flarum.core.compat["common/components/Switch"];var S=t.n(T);const b=flarum.core.compat["common/app"];var N=t.n(b);const A=flarum.core.compat["common/components/Page"];var D=t.n(A),U="fof-nightmode.default_theme";const x={AUTO:0,LIGHT:1,DARK:2,DEFAULT:function(){var e;return Number.parseInt((null==(e=N().data.settings)?void 0:e[U])||N().data[U])||0}};var M=t(116),O="flarum_nightmode",w=function(){var e=M.get(O);return e||"0"===e?Number(e):x.DEFAULT()},I=function(e){return M.set(O,e,{sameSite:"lax",secure:"https:"===location.protocol})};function k(){var e=Array.from(new Set(Object.values(x))),o=w();isNaN(o)?R("Theme is not a valid integer! Resetting..."):e.includes(o)||R("Theme is out of bounds! Resetting...")}function R(e){console.warn(e),I(x.DEFAULT())}function L(){var e,o=N().session.user,t=!o||!!o.preferences().fofNightMode_perDevice,n=o&&o.preferences().fofNightMode;return t?e=w():"number"==typeof n&&-1!==n&&(e=n),"number"==typeof e?e:x.DEFAULT()}function P(){var e,o,t=N().session.user,n=null==(e=N().session.user)?void 0:e.preferences().fofNightMode_perDevice;t&&!n||k(),n&&k(),j((o=L())===x.DARK?"night":o===x.LIGHT?"day":window.matchMedia("(prefers-color-scheme: dark)").matches?"night":"day")}function C(){return{day:N().data["fof-nightmode.assets.day"],night:N().data["fof-nightmode.assets.night"]}}function j(e){var o=document.querySelector("link.nightmode-light[rel=stylesheet]"),t=document.querySelector("link.nightmode-dark[rel=stylesheet]");if(o&&t){if(L()===x.AUTO)return;var n=document.createElement("link");"onload"in n?n.onload=function(){o.remove(),t.remove()}:(o.remove(),t.remove()),n.rel="stylesheet",n.className="nightmode",n.href=C()[e],document.head.append(n)}else{var r=o||t||document.querySelector("link.nightmode[rel=stylesheet]"),i=C()[e];i!==r.href&&(r.href=i,r.className="nightmode")}}function E(e){return e===x.LIGHT||e===x.AUTO&&!window.matchMedia("(prefers-color-scheme: dark)").matches}function F(){var e,t=L(),n=E(t),r=o().session.user;if(r){var i=n?x.DARK:x.LIGHT;if(r.preferences().fofNightMode_perDevice)return perDevice.set(i),void P();r.savePreferences({fofNightMode:i}).then((function(){P()}))}else{var s=(e=t)===x.AUTO?x.LIGHT:e===x.LIGHT?x.DARK:x.AUTO;perDevice.set(s),P()}}var H=function(e){return o().translator.trans("fof-nightmode.forum.user.settings."+e)};o().initializers.add("fof-nightmode",(function(){(0,r.extend)(s().prototype,"settingsItems",(function(e){var t=o().session.user,n=!!t.preferences().fofNightMode_perDevice;n&&k();var r=!window.matchMedia("not all and (prefers-color-scheme), (prefers-color-scheme)").matches,i=L(),s={0:H("options.auto"),1:H("options.day"),2:H("options.night")};r&&(delete s[0],i===x.AUTO&&(i=o().forum.attribute("fofNightMode_autoUnsupportedFallback"))),e.add("fof-nightmode",_().component({label:H("heading"),className:"Settings-theme"},[m("p",{className:"description"},H("description")),m("p",{className:"description"},H("description2")),r?m("p",{class:"description NightMode-autoUnsupported"},H("auto_unsupported")):null,S().component({className:"Settings-theme--per_device_cb",state:n,onchange:function(e){e?I(i):M.remove(O),t.savePreferences({fofNightMode_perDevice:e}).then((function(){P()}))}},H("device_specific_setting_checkbox")),v().component({value:i,className:"Settings-theme--input",onchange:function(e){if(n)return I(e),void P();t.savePreferences({fofNightMode:e}).then((function(){m.redraw(),P()}))},options:s}),m("p",{className:"Settings-theme--selection_description"},i===x.AUTO?H("option_descriptions.auto"):i===x.LIGHT?H("option_descriptions.day"):i===x.DARK?H("option_descriptions.night"):h().component())]))})),(0,r.extend)(f().prototype,"items",(function(e){if(!o().session.user||o().forum.attribute("fofNightMode.showThemeToggleOnHeaderAlways")){var t=L(),n=E(t);e.add("nightmode",m(p(),{className:"Button Button--flat",onclick:function(){F()},icon:t===x.AUTO?"fas fa-adjust":"far fa-"+(n?"sun":"moon")},o().translator.trans("fof-nightmode.forum.header.nightmode_button")),15)}})),(0,r.extend)(c().prototype,"items",(function(e){if(o().session.user){var t=E(L());e.add(t?"nightmode":"daymode",p().component({icon:"far fa-"+(t?"moon":"sun"),onclick:function(){F()}},o().translator.trans("fof-nightmode.forum."+(t?"night":"day"))),-1)}})),(0,r.extend)(D().prototype,"oninit",P)}))})(),module.exports=n})(); //# sourceMappingURL=forum.js.map \ No newline at end of file diff --git a/js/dist/forum.js.map b/js/dist/forum.js.map index cca6aeb..b37e4b6 100755 --- a/js/dist/forum.js.map +++ b/js/dist/forum.js.map @@ -1 +1 @@ -{"version":3,"file":"forum.js","mappings":"4CACA,IAAIA,EAAYC,MAAQA,KAAKD,UAAa,WAStC,OARAA,EAAWE,OAAOC,QAAU,SAASC,GACjC,IAAK,IAAIC,EAAGC,EAAI,EAAGC,EAAIC,UAAUC,OAAQH,EAAIC,EAAGD,IAE5C,IAAK,IAAII,KADTL,EAAIG,UAAUF,GACOJ,OAAOS,UAAUC,eAAeC,KAAKR,EAAGK,KACzDN,EAAEM,GAAKL,EAAEK,IAEjB,OAAON,GAEJJ,EAASc,MAAMb,KAAMO,YAGhC,SAASO,EAAmBC,EAAMC,GAC9B,IAAKA,EACD,MAAO,GAEX,IAAIC,EAAc,KAAOF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ACV+B,QAAS,WACP,IA3HaC,EA2HPC,GA3HOD,EA2HkBjD,KA1HvBzB,EAAAA,KACPA,EAAAA,MAGL0E,IAAY1E,EAAAA,MACPA,EAAAA,KAGFA,EAAAA,KAoHCgE,EAAcW,GACdnD,KAEFoD,KAAMnD,IAAUzB,EAAAA,KAAc,gBAAxB,WAAoDwE,EAAU,MAAQ,SAE3E1E,IAAAA,WAAAA,MAAqB,gDAExB,SAIJoD,EAAAA,EAAAA,QAAO2B,IAAAA,UAA2B,SAAS,SAAUzB,GACnD,GAAKtD,IAAAA,QAAAA,KAAL,CAEA,IAAMoB,EAAOpB,IAAAA,QAAAA,KACP0E,EAAUvB,EAAWhC,KAG3BmC,EAAMI,IACJgB,EAAU,YAAc,UACxBM,IAAAA,UACE,CACEF,KAAM,WAAUJ,EAAU,OAAS,OACnCC,QAAS,WACP,IAAMxE,EAAMuE,EAAUxE,EAAAA,KAAcA,EAAAA,MAEpC,GAAMkB,EAAKE,cAAcC,uBAGvB,OAFA2C,EAAc/D,QACduB,IAIFN,EACG+C,gBAAgB,CACf1C,aAActB,IAEfiE,MAAK,WAGJ1C,SAIR1B,IAAAA,WAAAA,MAAA,wBAA4C0E,EAAU,QAAU,UAEjE,QDxLLtB,EAAAA,EAAAA,QAAO6B,IAAAA,UAAgB,SAAUvD,O","sources":["webpack://@fof/nightmode/./node_modules/es-cookie/src/es-cookie.js","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['forum/app']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/extend']\"","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/external root \"flarum.core.compat['common/helpers/icon']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/app']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/Page']\"","webpack://@fof/nightmode/./src/common/Themes.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/./src/forum/addSettingsItems.js","webpack://@fof/nightmode/./src/forum/index.ts"],"sourcesContent":["\"use strict\";\r\nvar __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\nexports.__esModule = true;\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\nfunction encode(name, value, attributes) {\r\n return encodeURIComponent(name)\r\n .replace(/%(23|24|26|2B|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(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent)\r\n + stringifyAttributes(attributes);\r\n}\r\nexports.encode = encode;\r\nfunction parse(cookieString) {\r\n var result = {};\r\n var cookies = cookieString ? cookieString.split('; ') : [];\r\n var rdecode = /(%[\\dA-F]{2})+/gi;\r\n for (var i = 0; i < cookies.length; i++) {\r\n var parts = cookies[i].split('=');\r\n var cookie = parts.slice(1).join('=');\r\n if (cookie.charAt(0) === '\"') {\r\n cookie = cookie.slice(1, -1);\r\n }\r\n try {\r\n var name_1 = parts[0].replace(rdecode, decodeURIComponent);\r\n result[name_1] = cookie.replace(rdecode, 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\nexports.parse = parse;\r\nfunction getAll() {\r\n return parse(document.cookie);\r\n}\r\nexports.getAll = getAll;\r\nfunction get(name) {\r\n return getAll()[name];\r\n}\r\nexports.get = get;\r\nfunction set(name, value, attributes) {\r\n document.cookie = encode(name, value, __assign({ path: '/' }, attributes));\r\n}\r\nexports.set = set;\r\nfunction remove(name, attributes) {\r\n set(name, '', __assign(__assign({}, attributes), { expires: -1 }));\r\n}\r\nexports.remove = remove;\r\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\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['forum/app'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/extend'];","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'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/helpers/icon'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/app'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/Page'];","import app from 'flarum/common/app';\n\n/*\n\n JS enum equivalent. Makes sure no value mix-ups are made!\n\n DEFAULT is used when an invalid value has been set, as well as for guest and new users.\n\n*/\n\nconst KEY = 'fof-nightmode.default_theme';\n\nconst Themes = {\n AUTO: 0,\n LIGHT: 1,\n DARK: 2,\n\n // adds an \"ultra default\" of 0 if the admins don't set a default tsk tsk tsk\n DEFAULT: () => Number.parseInt(app.data.settings?.[KEY] || app.data[KEY]) || 0,\n};\n\nexport default Themes;\n","import * as Cookies from 'es-cookie';\nimport Themes from '../../common/Themes';\n\nexport const KEY = 'flarum_nightmode';\n\nexport const get = () => {\n const value = Cookies.get(KEY);\n\n if (!value && value !== '0') {\n return Themes.DEFAULT();\n }\n\n return Number(value);\n};\n\nexport const set = (val) =>\n Cookies.set(KEY, val, {\n sameSite: 'lax',\n secure: location.protocol === 'https:',\n });\n\nexport const remove = () => Cookies.remove(KEY);\n","/*\n This function is designed to catch invalid theme values\n and handle them before they can break Flarum for users.\n\n E.g. if a user manually edited their cookies to\n set their theme to an invalid value, this theme would\n detect that, and reset it to 0 (auto).\n*/\n\nimport Themes from '../common/Themes';\nimport { get, set } from './helpers/perDeviceSetting';\n\nexport default function fixInvalidThemeSetting() {\n // get array of valid values without duplicate entries\n let validValues = Array.from(new Set(Object.values(Themes)));\n\n const Theme = get();\n\n if (isNaN(Theme)) {\n resetTheme('Theme is not a valid integer! Resetting...');\n } else if (!validValues.includes(Theme)) {\n // theme out of bounds\n resetTheme(`Theme is out of bounds! Resetting...`);\n }\n}\n\nfunction resetTheme(reason) {\n console.warn(reason);\n\n set(Themes.DEFAULT());\n}\n","import app from 'flarum/common/app';\nimport Themes from '../common/Themes';\nimport { get } from './helpers/perDeviceSetting';\n\nexport default function getTheme() {\n const user = app.session.user;\n\n const IsUsingPerDeviceSettings = !user || !!user.preferences().fofNightMode_perDevice;\n const SelectedTheme = user && user.preferences().fofNightMode;\n\n let value;\n\n if (IsUsingPerDeviceSettings) {\n // fetch through LS is per device enabled\n value = get();\n } else {\n if (typeof SelectedTheme === 'number' && SelectedTheme !== -1) {\n // use user prefs\n value = SelectedTheme;\n }\n }\n\n return typeof value === 'number' ? value : Themes.DEFAULT();\n}\n","import app from 'flarum/common/app';\n\nimport { extend } from 'flarum/common/extend';\nimport Page from 'flarum/common/components/Page';\n\nimport Themes from './Themes';\nimport fixInvalidThemeSetting from '../forum/fixInvalidThemeSetting';\nimport getTheme from '../forum/getTheme';\n\nexport default () => {\n extend(Page.prototype, 'oninit', setTheme);\n};\n\nexport function setTheme() {\n const { user } = app.session;\n\n const PerDevice = app.session.user?.preferences().fofNightMode_perDevice;\n\n if (!user || PerDevice) {\n fixInvalidThemeSetting();\n }\n\n if (PerDevice) {\n fixInvalidThemeSetting();\n }\n\n const CurrentTheme = getTheme();\n\n setThemeFromID(CurrentTheme);\n}\n\nexport function getUrls() {\n return {\n day: app.data['fof-nightmode.assets.day'],\n night: app.data['fof-nightmode.assets.night'],\n };\n}\n\nexport function setThemeFromID(theme) {\n if (theme === Themes.DARK) {\n setStyle('night');\n } else if (theme === Themes.LIGHT) {\n setStyle('day');\n } else {\n const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches;\n\n setStyle(preferDark ? 'night' : 'day');\n }\n}\n\nexport function setStyle(type) {\n const light = document.querySelector('link.nightmode-light[rel=stylesheet]');\n const dark = document.querySelector('link.nightmode-dark[rel=stylesheet]');\n\n if (light && dark) {\n if (getTheme() === Themes.AUTO) return;\n\n let newLink = document.createElement('link');\n\n // onload on link tags not supported in all browsers\n // so we should check it is present in the user's\n // current browser\n if ('onload' in newLink) {\n // if it is, only remove the old link tags after the new\n // one has finished loading (prevents flash of unstyled\n // content)\n newLink.onload = function () {\n light.remove();\n dark.remove();\n };\n } else {\n // if it isn't, just remove the old link tags immediately\n light.remove();\n dark.remove();\n }\n\n newLink.rel = 'stylesheet';\n newLink.className = 'nightmode';\n newLink.href = getUrls()[type];\n\n document.head.append(newLink);\n } else {\n const el = light || dark || document.querySelector('link.nightmode[rel=stylesheet]');\n\n const url = getUrls()[type];\n\n if (url !== el.href) {\n el.href = url;\n el.className = 'nightmode';\n }\n }\n}\n","import app from 'flarum/forum/app';\nimport { extend } from 'flarum/common/extend';\n\nimport SettingsPage from 'flarum/forum/components/SettingsPage';\nimport SessionDropdown from 'flarum/forum/components/SessionDropdown';\nimport HeaderSecondary from 'flarum/forum/components/HeaderSecondary';\nimport Button from 'flarum/common/components/Button';\nimport LoadingIndicator from 'flarum/common/components/LoadingIndicator';\nimport Select from 'flarum/common/components/Select';\nimport FieldSet from 'flarum/common/components/FieldSet';\nimport Switch from 'flarum/common/components/Switch';\nimport icon from 'flarum/common/helpers/icon';\n\nimport { setTheme } from '../common/setSelectedTheme';\nimport fixInvalidThemeSetting from './fixInvalidThemeSetting';\nimport * as perDevice from './helpers/perDeviceSetting';\nimport getTheme from './getTheme';\nimport Themes from '../common/Themes';\n\n// custom function for translations makes it a lot cleaner\nconst trans = (key) => app.translator.trans(`fof-nightmode.forum.user.settings.${key}`);\n\nconst getIsLight = (theme) => theme === Themes.LIGHT || (theme === Themes.AUTO && !window.matchMedia('(prefers-color-scheme: dark)').matches);\n\nconst toggleThrough = (current) => {\n if (current === Themes.AUTO) {\n return Themes.LIGHT;\n }\n\n if (current === Themes.LIGHT) {\n return Themes.DARK;\n }\n\n return Themes.AUTO;\n};\n\nexport default function () {\n extend(SettingsPage.prototype, 'settingsItems', function (items) {\n const { user } = app.session;\n\n const PerDevice = !!user.preferences().fofNightMode_perDevice;\n\n if (PerDevice) {\n fixInvalidThemeSetting();\n }\n\n const doesNotSupportAuto = !window.matchMedia('not all and (prefers-color-scheme), (prefers-color-scheme)').matches;\n\n let currentTheme = getTheme();\n\n const options = { 0: trans('options.auto'), 1: trans('options.day'), 2: trans('options.night') };\n\n if (doesNotSupportAuto) {\n delete options['0'];\n\n if (currentTheme === Themes.AUTO) {\n currentTheme = app.forum.attribute('fofNightMode_autoUnsupportedFallback');\n }\n }\n\n items.add(\n 'fof-nightmode',\n FieldSet.component(\n {\n label: trans('heading'),\n className: 'Settings-theme',\n },\n [\n

{trans('description')}

,\n

{trans('description2')}

,\n doesNotSupportAuto ?

{trans('auto_unsupported')}

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

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

,\n ]\n )\n );\n });\n\n extend(HeaderSecondary.prototype, 'items', function (items) {\n if (app.session.user) return;\n\n const theme = getTheme();\n const isLight = getIsLight(theme);\n\n items.add(\n 'nightmode',\n {\n const newTheme = toggleThrough(theme);\n\n perDevice.set(newTheme);\n setTheme();\n }}\n icon={theme === Themes.AUTO ? 'fas fa-adjust' : `far fa-${isLight ? 'sun' : 'moon'}`}\n >\n {app.translator.trans('fof-nightmode.forum.header.nightmode_button')}\n ,\n 15\n );\n });\n\n extend(SessionDropdown.prototype, 'items', function (items) {\n if (!app.session.user) return;\n\n const user = app.session.user;\n const isLight = getIsLight(getTheme());\n\n // Add night mode link to session dropdown\n items.add(\n isLight ? 'nightmode' : 'daymode',\n Button.component(\n {\n icon: `far fa-${isLight ? 'moon' : 'sun'}`,\n onclick: () => {\n const val = isLight ? Themes.DARK : Themes.LIGHT;\n\n if (!!user.preferences().fofNightMode_perDevice) {\n perDevice.set(val);\n setTheme();\n return;\n }\n\n user\n .savePreferences({\n fofNightMode: val,\n })\n .then(() => {\n // need to force-update selected theme (as it's only set\n // on a page load and redraw doesn't count as a apge load)\n setTheme();\n });\n },\n },\n app.translator.trans(`fof-nightmode.forum.${isLight ? 'night' : 'day'}`)\n ),\n -1\n );\n });\n}\n","import app from 'flarum/forum/app';\nimport addSettingsItems from './addSettingsItems';\nimport setSelectedTheme from '../common/setSelectedTheme';\n\napp.initializers.add('fof-nightmode', () => {\n addSettingsItems();\n setSelectedTheme();\n});\n"],"names":["__assign","this","Object","assign","t","s","i","n","arguments","length","p","prototype","hasOwnProperty","call","apply","stringifyAttribute","name","value","stringified","encode","attributes","encodeURIComponent","replace","decodeURIComponent","expires","Date","setMilliseconds","getMilliseconds","toUTCString","domain","path","secure","sameSite","stringifyAttributes","parse","cookieString","result","cookies","split","rdecode","parts","cookie","slice","join","charAt","e","getAll","document","set","exports","__esModule","get","remove","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","module","__webpack_modules__","getter","d","a","definition","key","o","defineProperty","enumerable","obj","prop","r","Symbol","toStringTag","flarum","core","compat","KEY","AUTO","LIGHT","DARK","DEFAULT","Number","parseInt","app","Cookies","Themes","val","location","protocol","fixInvalidThemeSetting","validValues","Array","from","Set","values","Theme","isNaN","resetTheme","includes","reason","console","warn","getTheme","user","IsUsingPerDeviceSettings","preferences","fofNightMode_perDevice","SelectedTheme","fofNightMode","setTheme","theme","PerDevice","setStyle","window","matchMedia","matches","getUrls","day","night","type","light","querySelector","dark","newLink","createElement","onload","rel","className","href","head","append","el","url","trans","getIsLight","extend","SettingsPage","items","doesNotSupportAuto","currentTheme","options","add","FieldSet","label","class","Switch","state","onchange","checked","perDevice","savePreferences","then","Select","m","redraw","LoadingIndicator","HeaderSecondary","isLight","onclick","current","newTheme","icon","SessionDropdown","Button","Page"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"forum.js","mappings":"4CACA,IAAIA,EAAYC,MAAQA,KAAKD,UAAa,WAStC,OARAA,EAAWE,OAAOC,QAAU,SAASC,GACjC,IAAK,IAAIC,EAAGC,EAAI,EAAGC,EAAIC,UAAUC,OAAQH,EAAIC,EAAGD,IAE5C,IAAK,IAAII,KADTL,EAAIG,UAAUF,GACOJ,OAAOS,UAAUC,eAAeC,KAAKR,EAAGK,KACzDN,EAAEM,GAAKL,EAAEK,IAEjB,OAAON,GAEJJ,EAASc,MAAMb,KAAMO,YAGhC,SAASO,EAAmBC,EAAMC,GAC9B,IAAKA,EACD,MAAO,GAEX,IAAIC,EAAc,KAAOF,EACzB,OAAc,IAAVC,EACOC,EAEJA,EAAc,IAAMD,EAc/B,SAASE,EAAOH,EAAMC,EAAOG,GACzB,OAAOC,mBAAmBL,GACrBM,QAAQ,2BAA4BC,oBACpCD,QAAQ,MAAO,OAAOA,QAAQ,MAAO,OACpC,IAAMD,mBAAmBJ,GAE1BK,QAAQ,4DAA6DC,oBAlB9E,SAA6BH,GACzB,GAAkC,iBAAvBA,EAAWI,QAAsB,CACxC,IAAIA,EAAU,IAAIC,KAClBD,EAAQE,gBAAgBF,EAAQG,kBAAyC,MAArBP,EAAWI,SAC/DJ,EAAWI,QAAUA,EAEzB,OAAOT,EAAmB,UAAWK,EAAWI,QAAUJ,EAAWI,QAAQI,cAAgB,IACvFb,EAAmB,SAAUK,EAAWS,QACxCd,EAAmB,OAAQK,EAAWU,MACtCf,EAAmB,SA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BAAxB,WAAoDmD,EAAU,MAAQ,SAE3ErD,IAAAA,WAAAA,MAAqB,gDAExB,SAIJ2D,EAAAA,EAAAA,QAAOqB,IAAAA,UAA2B,SAAS,SAAUnB,GACnD,GAAK7D,IAAAA,QAAAA,KAAL,CAEA,IAAMqD,EAAUH,EAAW/B,KAG3B0C,EAAMI,IACJZ,EAAU,YAAc,UACxB4B,IAAAA,UACE,CACEF,KAAM,WAAU1B,EAAU,OAAS,OACnCyB,QAAS,WACP3B,MAoBJnD,IAAAA,WAAAA,MAAA,wBAA4CqD,EAAU,QAAU,UAEjE,QF3KLM,EAAAA,EAAAA,QAAOuB,IAAAA,UAAgB,SAAUxD,O","sources":["webpack://@fof/nightmode/./node_modules/es-cookie/src/es-cookie.js","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['forum/app']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/extend']\"","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/external root \"flarum.core.compat['common/app']\"","webpack://@fof/nightmode/external root \"flarum.core.compat['common/components/Page']\"","webpack://@fof/nightmode/./src/common/Themes.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/./src/forum/helpers/switchTheme.js","webpack://@fof/nightmode/./src/forum/addSettingsItems.js","webpack://@fof/nightmode/./src/forum/index.ts"],"sourcesContent":["\"use strict\";\r\nvar __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\nexports.__esModule = true;\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\nfunction encode(name, value, attributes) {\r\n return encodeURIComponent(name)\r\n .replace(/%(23|24|26|2B|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(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent)\r\n + stringifyAttributes(attributes);\r\n}\r\nexports.encode = encode;\r\nfunction parse(cookieString) {\r\n var result = {};\r\n var cookies = cookieString ? cookieString.split('; ') : [];\r\n var rdecode = /(%[\\dA-F]{2})+/gi;\r\n for (var i = 0; i < cookies.length; i++) {\r\n var parts = cookies[i].split('=');\r\n var cookie = parts.slice(1).join('=');\r\n if (cookie.charAt(0) === '\"') {\r\n cookie = cookie.slice(1, -1);\r\n }\r\n try {\r\n var name_1 = parts[0].replace(rdecode, decodeURIComponent);\r\n result[name_1] = cookie.replace(rdecode, 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\nexports.parse = parse;\r\nfunction getAll() {\r\n return parse(document.cookie);\r\n}\r\nexports.getAll = getAll;\r\nfunction get(name) {\r\n return getAll()[name];\r\n}\r\nexports.get = get;\r\nfunction set(name, value, attributes) {\r\n document.cookie = encode(name, value, __assign({ path: '/' }, attributes));\r\n}\r\nexports.set = set;\r\nfunction remove(name, attributes) {\r\n set(name, '', __assign(__assign({}, attributes), { expires: -1 }));\r\n}\r\nexports.remove = remove;\r\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\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['forum/app'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/extend'];","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'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/app'];","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['common/components/Page'];","import app from 'flarum/common/app';\n\n/*\n\n JS enum equivalent. Makes sure no value mix-ups are made!\n\n DEFAULT is used when an invalid value has been set, as well as for guest and new users.\n\n*/\n\nconst KEY = 'fof-nightmode.default_theme';\n\nconst Themes = {\n AUTO: 0,\n LIGHT: 1,\n DARK: 2,\n\n // adds an \"ultra default\" of 0 if the admins don't set a default tsk tsk tsk\n DEFAULT: () => Number.parseInt(app.data.settings?.[KEY] || app.data[KEY]) || 0,\n};\n\nexport default Themes;\n","import * as Cookies from 'es-cookie';\nimport Themes from '../../common/Themes';\n\nexport const KEY = 'flarum_nightmode';\n\nexport const get = () => {\n const value = Cookies.get(KEY);\n\n if (!value && value !== '0') {\n return Themes.DEFAULT();\n }\n\n return Number(value);\n};\n\nexport const set = (val) =>\n Cookies.set(KEY, val, {\n sameSite: 'lax',\n secure: location.protocol === 'https:',\n });\n\nexport const remove = () => Cookies.remove(KEY);\n","/*\n This function is designed to catch invalid theme values\n and handle them before they can break Flarum for users.\n\n E.g. if a user manually edited their cookies to\n set their theme to an invalid value, this theme would\n detect that, and reset it to 0 (auto).\n*/\n\nimport Themes from '../common/Themes';\nimport { get, set } from './helpers/perDeviceSetting';\n\nexport default function fixInvalidThemeSetting() {\n // get array of valid values without duplicate entries\n let validValues = Array.from(new Set(Object.values(Themes)));\n\n const Theme = get();\n\n if (isNaN(Theme)) {\n resetTheme('Theme is not a valid integer! Resetting...');\n } else if (!validValues.includes(Theme)) {\n // theme out of bounds\n resetTheme(`Theme is out of bounds! Resetting...`);\n }\n}\n\nfunction resetTheme(reason) {\n console.warn(reason);\n\n set(Themes.DEFAULT());\n}\n","import app from 'flarum/common/app';\nimport Themes from '../common/Themes';\nimport { get } from './helpers/perDeviceSetting';\n\nexport default function getTheme() {\n const user = app.session.user;\n\n const IsUsingPerDeviceSettings = !user || !!user.preferences().fofNightMode_perDevice;\n const SelectedTheme = user && user.preferences().fofNightMode;\n\n let value;\n\n if (IsUsingPerDeviceSettings) {\n // fetch through LS is per device enabled\n value = get();\n } else {\n if (typeof SelectedTheme === 'number' && SelectedTheme !== -1) {\n // use user prefs\n value = SelectedTheme;\n }\n }\n\n return typeof value === 'number' ? value : Themes.DEFAULT();\n}\n","import app from 'flarum/common/app';\n\nimport { extend } from 'flarum/common/extend';\nimport Page from 'flarum/common/components/Page';\n\nimport Themes from './Themes';\nimport fixInvalidThemeSetting from '../forum/fixInvalidThemeSetting';\nimport getTheme from '../forum/getTheme';\n\nexport default () => {\n extend(Page.prototype, 'oninit', setTheme);\n};\n\nexport function setTheme() {\n const { user } = app.session;\n\n const PerDevice = app.session.user?.preferences().fofNightMode_perDevice;\n\n if (!user || PerDevice) {\n fixInvalidThemeSetting();\n }\n\n if (PerDevice) {\n fixInvalidThemeSetting();\n }\n\n const CurrentTheme = getTheme();\n\n setThemeFromID(CurrentTheme);\n}\n\nexport function getUrls() {\n return {\n day: app.data['fof-nightmode.assets.day'],\n night: app.data['fof-nightmode.assets.night'],\n };\n}\n\nexport function setThemeFromID(theme) {\n if (theme === Themes.DARK) {\n setStyle('night');\n } else if (theme === Themes.LIGHT) {\n setStyle('day');\n } else {\n const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches;\n\n setStyle(preferDark ? 'night' : 'day');\n }\n}\n\nexport function setStyle(type) {\n const light = document.querySelector('link.nightmode-light[rel=stylesheet]');\n const dark = document.querySelector('link.nightmode-dark[rel=stylesheet]');\n\n if (light && dark) {\n if (getTheme() === Themes.AUTO) return;\n\n let newLink = document.createElement('link');\n\n // onload on link tags not supported in all browsers\n // so we should check it is present in the user's\n // current browser\n if ('onload' in newLink) {\n // if it is, only remove the old link tags after the new\n // one has finished loading (prevents flash of unstyled\n // content)\n newLink.onload = function () {\n light.remove();\n dark.remove();\n };\n } else {\n // if it isn't, just remove the old link tags immediately\n light.remove();\n dark.remove();\n }\n\n newLink.rel = 'stylesheet';\n newLink.className = 'nightmode';\n newLink.href = getUrls()[type];\n\n document.head.append(newLink);\n } else {\n const el = light || dark || document.querySelector('link.nightmode[rel=stylesheet]');\n\n const url = getUrls()[type];\n\n if (url !== el.href) {\n el.href = url;\n el.className = 'nightmode';\n }\n }\n}\n","import app from 'flarum/forum/app';\nimport Themes from '../../common/Themes';\nimport { setTheme } from '../../common/setSelectedTheme';\nimport getTheme from '../getTheme';\n\nexport function getIsLight(theme) {\n return theme === Themes.LIGHT || (theme === Themes.AUTO && !window.matchMedia('(prefers-color-scheme: dark)').matches);\n}\n\nfunction toggleThrough(current) {\n if (current === Themes.AUTO) {\n return Themes.LIGHT;\n }\n\n if (current === Themes.LIGHT) {\n return Themes.DARK;\n }\n\n return Themes.AUTO;\n}\n\nexport function switchTheme() {\n const theme = getTheme();\n const isLight = getIsLight(theme);\n const user = app.session.user;\n\n if (user) {\n const val = isLight ? Themes.DARK : Themes.LIGHT;\n\n if (!!user.preferences().fofNightMode_perDevice) {\n perDevice.set(val);\n setTheme();\n return;\n }\n\n user\n .savePreferences({\n fofNightMode: val,\n })\n .then(() => {\n // need to force-update selected theme (as it's only set\n // on a page load and redraw doesn't count as a apge load)\n setTheme();\n });\n } else {\n const newTheme = toggleThrough(theme);\n\n perDevice.set(newTheme);\n setTheme();\n }\n}\n","import app from 'flarum/forum/app';\nimport { extend } from 'flarum/common/extend';\n\nimport SettingsPage from 'flarum/forum/components/SettingsPage';\nimport SessionDropdown from 'flarum/forum/components/SessionDropdown';\nimport HeaderSecondary from 'flarum/forum/components/HeaderSecondary';\nimport Button from 'flarum/common/components/Button';\nimport LoadingIndicator from 'flarum/common/components/LoadingIndicator';\nimport Select from 'flarum/common/components/Select';\nimport FieldSet from 'flarum/common/components/FieldSet';\nimport Switch from 'flarum/common/components/Switch';\n\nimport { setTheme } from '../common/setSelectedTheme';\nimport fixInvalidThemeSetting from './fixInvalidThemeSetting';\nimport * as perDevice from './helpers/perDeviceSetting';\nimport getTheme from './getTheme';\nimport Themes from '../common/Themes';\nimport { switchTheme, getIsLight } from './helpers/switchTheme';\n\n// custom function for translations makes it a lot cleaner\nconst trans = (key) => app.translator.trans(`fof-nightmode.forum.user.settings.${key}`);\n\nexport default function () {\n extend(SettingsPage.prototype, 'settingsItems', function (items) {\n const { user } = app.session;\n\n const PerDevice = !!user.preferences().fofNightMode_perDevice;\n\n if (PerDevice) {\n fixInvalidThemeSetting();\n }\n\n const doesNotSupportAuto = !window.matchMedia('not all and (prefers-color-scheme), (prefers-color-scheme)').matches;\n\n let currentTheme = getTheme();\n\n const options = { 0: trans('options.auto'), 1: trans('options.day'), 2: trans('options.night') };\n\n if (doesNotSupportAuto) {\n delete options['0'];\n\n if (currentTheme === Themes.AUTO) {\n currentTheme = app.forum.attribute('fofNightMode_autoUnsupportedFallback');\n }\n }\n\n items.add(\n 'fof-nightmode',\n FieldSet.component(\n {\n label: trans('heading'),\n className: 'Settings-theme',\n },\n [\n

{trans('description')}

,\n

{trans('description2')}

,\n doesNotSupportAuto ?

{trans('auto_unsupported')}

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

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

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