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