1
|
/**
|
2
|
* part of Hachette
|
3
|
* Informing about activities performed by content script (script injection,
|
4
|
* script blocking).
|
5
|
*
|
6
|
* Copyright (C) 2021 Wojtek Kosior
|
7
|
* Redistribution terms are gathered in the `copyright' file.
|
8
|
*/
|
9
|
|
10
|
/*
|
11
|
* IMPORTS_START
|
12
|
* IMPORT listen_for_connection
|
13
|
* IMPORT CONNECTION_TYPE
|
14
|
* IMPORTS_END
|
15
|
*/
|
16
|
|
17
|
var activities = [];
|
18
|
var ports = new Set();
|
19
|
|
20
|
function report_activity(name, data)
|
21
|
{
|
22
|
const activity = [name, data];
|
23
|
activities.push(activity);
|
24
|
|
25
|
for (const port of ports)
|
26
|
port.postMessage(activity);
|
27
|
}
|
28
|
|
29
|
function report_script(script_data)
|
30
|
{
|
31
|
report_activity("script", script_data);
|
32
|
}
|
33
|
|
34
|
function report_settings(settings)
|
35
|
{
|
36
|
report_activity("settings", settings);
|
37
|
}
|
38
|
|
39
|
function new_connection(port)
|
40
|
{
|
41
|
console.log("new activity info connection!");
|
42
|
|
43
|
ports.add(port);
|
44
|
|
45
|
for (const activity of activities)
|
46
|
port.postMessage(activity);
|
47
|
}
|
48
|
|
49
|
function start_activity_info_server()
|
50
|
{
|
51
|
listen_for_connection(CONNECTION_TYPE.ACTIVITY_INFO, new_connection);
|
52
|
}
|
53
|
|
54
|
/*
|
55
|
* EXPORTS_START
|
56
|
* EXPORT start_activity_info_server
|
57
|
* EXPORT report_script
|
58
|
* EXPORT report_settings
|
59
|
* EXPORTS_END
|
60
|
*/
|