-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path_globals.js
78 lines (68 loc) · 2.66 KB
/
_globals.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
Firefox addon "Save Screenshot"
Copyright (C) 2020 Manuel Reimer <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';
// Function which handles sending the "take screenshot" message to the active
// tab. Includes error handling with error notification.
async function SendMessage(aJsonMessage) {
const tabs = await browser.tabs.query({active: true, currentWindow: true});
const message = JSON.parse(aJsonMessage);
message.type = "TakeScreenshot";
try {
await browser.tabs.sendMessage(tabs[0].id, message);
}
catch(e) {
console.log("SaveScreenshot message sending error: " + e);
browser.notifications.create("error-notification", {
"type": "basic",
"title": browser.i18n.getMessage("errorTitleFailedSending"),
"message": browser.i18n.getMessage("errorTextFailedSending")
});
}
}
// Function to generate list with menu entries based on the user settings.
async function GetMenuList() {
const prefs = await Storage.get();
if (prefs.formats.length == 1 && prefs.regions.length == 1)
return [];
const formats = [
{id: "png", label: "PNG"},
{id: "jpg", label: "JPEG"},
{id: "copy", label: browser.i18n.getMessage("format_copy_label")}
];
const regions = [
{id: "full", label: browser.i18n.getMessage("region_full_label")},
{id: "viewport", label: browser.i18n.getMessage("region_viewport_label")},
{id: "selection", label: browser.i18n.getMessage("region_selection_label")}
];
let template = "$REGION ($FORMAT)";
if (prefs.formats.length == 1)
template = "$REGION";
else if (prefs.regions.length == 1)
template = "$FORMAT";
let list = [];
for (let region of regions) {
if (!prefs.regions.includes(region.id))
continue;
for (let format of formats) {
if (!prefs.formats.includes(format.id))
continue;
list.push({
label: template.replace("$REGION", region.label).replace("$FORMAT", format.label),
data: '{"format": "' + format.id + '", "region": "' + region.id + '"}'
});
}
}
return list;
}