Revision 53837634
Added by koszko about 2 years ago
| common/settings_query.js | ||
|---|---|---|
| 8 | 8 |
/* |
| 9 | 9 |
* IMPORTS_START |
| 10 | 10 |
* IMPORT TYPE_PREFIX |
| 11 |
* IMPORT for_each_possible_pattern
|
|
| 11 |
* IMPORT each_url_pattern
|
|
| 12 | 12 |
* IMPORTS_END |
| 13 | 13 |
*/ |
| 14 | 14 |
|
| 15 |
function check_pattern(storage, pattern, multiple, matched) |
|
| 16 |
{
|
|
| 17 |
const settings = storage.get(TYPE_PREFIX.PAGE, pattern); |
|
| 18 |
|
|
| 19 |
if (settings === undefined) |
|
| 20 |
return; |
|
| 21 |
|
|
| 22 |
matched.push([pattern, settings]); |
|
| 23 |
|
|
| 24 |
if (!multiple) |
|
| 25 |
return false; |
|
| 26 |
} |
|
| 27 |
|
|
| 28 | 15 |
function query(storage, url, multiple) |
| 29 | 16 |
{
|
| 30 | 17 |
const matched = []; |
| 31 | 18 |
const cb = p => check_pattern(storage, p, multiple, matched); |
| 32 |
for_each_possible_pattern(url, cb); |
|
| 19 |
for (const pattern of each_url_pattern(url)) {
|
|
| 20 |
const result = [pattern, storage.get(TYPE_PREFIX.PAGE, pattern)]; |
|
| 21 |
if (result[1] === undefined) |
|
| 22 |
continue; |
|
| 23 |
|
|
| 24 |
if (!multiple) |
|
| 25 |
return result; |
|
| 26 |
matched.push(result); |
|
| 27 |
} |
|
| 33 | 28 |
|
| 34 |
return multiple ? matched : (matched[0] || [undefined, undefined]);
|
|
| 29 |
return multiple ? matched : [undefined, undefined];
|
|
| 35 | 30 |
} |
| 36 | 31 |
|
| 37 | 32 |
function query_best(storage, url) |
Also available in: Unified diff
enable whitelisting of `file://' protocol\n\nThis commit additionally also changes the semantics of triple asterisk wildcard in URL path.