(input = {}, options = {})
| 815 | } |
| 816 | |
| 817 | function buildPersistentSettingsPayload(input = {}, options = {}) { |
| 818 | const { fillDefaults = false, requireKnownKeys = false } = options; |
| 819 | if (!input || typeof input !== 'object' || Array.isArray(input)) { |
| 820 | throw new Error('\u914d\u7f6e\u5185\u5bb9\u683c\u5f0f\u65e0\u6548\u3002'); |
| 821 | } |
| 822 | |
| 823 | const normalizedInput = { ...input }; |
| 824 | if (normalizedInput.autoStepDelaySeconds === undefined) { |
| 825 | const legacyAutoStepDelaySeconds = resolveLegacyAutoStepDelaySeconds(normalizedInput); |
| 826 | if (legacyAutoStepDelaySeconds !== undefined) { |
| 827 | normalizedInput.autoStepDelaySeconds = legacyAutoStepDelaySeconds; |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | const payload = {}; |
| 832 | let matchedKeyCount = 0; |
| 833 | for (const key of PERSISTED_SETTING_KEYS) { |
| 834 | if (normalizedInput[key] !== undefined) { |
| 835 | payload[key] = normalizePersistentSettingValue(key, normalizedInput[key]); |
| 836 | matchedKeyCount += 1; |
| 837 | } else if (fillDefaults) { |
| 838 | payload[key] = normalizePersistentSettingValue(key, PERSISTED_SETTING_DEFAULTS[key]); |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | if (requireKnownKeys && matchedKeyCount === 0) { |
| 843 | throw new Error('\u914d\u7f6e\u6587\u4ef6\u4e2d\u6ca1\u6709\u53ef\u8bc6\u522b\u7684\u914d\u7f6e\u5185\u5bb9\u3002'); |
| 844 | } |
| 845 | |
| 846 | if (payload.cloudflareDomains) { |
| 847 | const domains = normalizeCloudflareDomains(payload.cloudflareDomains); |
| 848 | if (payload.cloudflareDomain && !domains.includes(payload.cloudflareDomain)) { |
| 849 | domains.unshift(payload.cloudflareDomain); |
| 850 | } |
| 851 | payload.cloudflareDomains = domains; |
| 852 | } |
| 853 | if (payload.cloudflareTempEmailDomains) { |
| 854 | const domains = normalizeCloudflareTempEmailDomains(payload.cloudflareTempEmailDomains); |
| 855 | if (payload.cloudflareTempEmailDomain && !domains.includes(payload.cloudflareTempEmailDomain)) { |
| 856 | domains.unshift(payload.cloudflareTempEmailDomain); |
| 857 | } |
| 858 | payload.cloudflareTempEmailDomains = domains; |
| 859 | } |
| 860 | |
| 861 | return payload; |
| 862 | } |
| 863 | |
| 864 | async function getPersistedSettings() { |
| 865 | const stored = await chrome.storage.local.get([...PERSISTED_SETTING_KEYS, ...LEGACY_AUTO_STEP_DELAY_KEYS]); |
no test coverage detected