MCPcopy Create free account
hub / github.com/darkreader/darkreader / set

Method set

src/background/user-storage.ts:203–245  ·  view source on GitHub ↗
($settings: Partial<UserSettings>)

Source from the content-addressed store, hash-verified

201 });
202
203 static set($settings: Partial<UserSettings>): void {
204 if (!UserStorage.settings) {
205 // This path is never taken because Extension always calls UserStorage.loadSettings()
206 // before calling UserStorage.set().
207 logWarn('Could not modify settings because the settings are missing.');
208 return;
209 }
210
211 const filterSiteList = (siteList: string[]) => {
212 if (!Array.isArray(siteList)) {
213 const list: string[] = [];
214 for (const key in (siteList as string[])) {
215 const index = Number(key);
216 if (!isNaN(index)) {
217 list[index] = siteList[key];
218 }
219 }
220 siteList = list;
221 }
222 return siteList.filter((pattern) => {
223 let isOK = false;
224 try {
225 isURLMatched('https://google.com/', pattern);
226 isURLMatched('[::1]:1337', pattern);
227 isOK = true;
228 } catch (err) {
229 logWarn(`Pattern "${pattern}" excluded`);
230 }
231 return isOK && pattern !== '/';
232 });
233 };
234
235 const {enabledFor, disabledFor} = $settings;
236 const updatedSettings = {...UserStorage.settings, ...$settings};
237 if (enabledFor) {
238 updatedSettings.enabledFor = filterSiteList(enabledFor);
239 }
240 if (disabledFor) {
241 updatedSettings.disabledFor = filterSiteList(disabledFor);
242 }
243
244 UserStorage.settings = updatedSettings;
245 }
246}

Callers

nothing calls this directly

Calls 1

logWarnFunction · 0.90

Tested by

no test coverage detected