1
|
/**
|
2
|
* Myext querying page settings with regard to wildcard records
|
3
|
*
|
4
|
* Copyright (C) 2021 Wojtek Kosior
|
5
|
* Redistribution terms are gathered in the `copyright' file.
|
6
|
*/
|
7
|
|
8
|
/*
|
9
|
* IMPORTS_START
|
10
|
* IMPORT make_once
|
11
|
* IMPORT get_storage
|
12
|
* IMPORT TYPE_PREFIX
|
13
|
* IMPORT for_each_possible_pattern
|
14
|
* IMPORTS_END
|
15
|
*/
|
16
|
|
17
|
var storage;
|
18
|
|
19
|
async function init(fun)
|
20
|
{
|
21
|
storage = await get_storage();
|
22
|
|
23
|
return fun;
|
24
|
}
|
25
|
|
26
|
function check_pattern(pattern, multiple, matched)
|
27
|
{
|
28
|
const settings = storage.get(TYPE_PREFIX.PAGE, pattern);
|
29
|
|
30
|
if (settings === undefined)
|
31
|
return;
|
32
|
|
33
|
matched.push([pattern, settings]);
|
34
|
|
35
|
if (!multiple)
|
36
|
return false;
|
37
|
}
|
38
|
|
39
|
function query(url, multiple)
|
40
|
{
|
41
|
const matched = [];
|
42
|
for_each_possible_pattern(url, p => check_pattern(p, multiple, matched));
|
43
|
|
44
|
return multiple ? matched : (matched[0] || [undefined, undefined]);
|
45
|
}
|
46
|
|
47
|
function query_best(url)
|
48
|
{
|
49
|
return query(url, false);
|
50
|
}
|
51
|
|
52
|
function query_all(url)
|
53
|
{
|
54
|
return query(url, true);
|
55
|
}
|
56
|
|
57
|
const get_query_best = make_once(() => init(query_best));
|
58
|
const get_query_all = make_once(() => init(query_all));
|
59
|
|
60
|
/*
|
61
|
* EXPORTS_START
|
62
|
* EXPORT get_query_best
|
63
|
* EXPORT get_query_all
|
64
|
* EXPORTS_END
|
65
|
*/
|