-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
80 lines (64 loc) · 1.51 KB
/
background.js
File metadata and controls
80 lines (64 loc) · 1.51 KB
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
79
80
'use strict';
const local = typeof browser === 'undefined' ? chrome : browser;
const dataStorage = new DataStorage();
const numberHelper = new NumberHelper(dataStorage);
const listener = new Listener(local);
local.contextMenus.create({
id: "tne-dial",
title: local.i18n.getMessage("contextMenuItemSelectionDial") + " %s",
contexts: ["selection"],
onclick: (info, tab) => {
process(info.selectionText);
}
});
function process(number) {
if (checkNumber(number) === false) {
alert('This is not a telephone number');
return;
}
dataStorage
.load()
.then(() => {
if (isConfigured() === false) {
alert('You must configure plugin before to use it');
return;
}
var sanitized = numberHelper.sanitizeNumber(number);
if (sanitized === null) {
alert('Invalid number');
return;
}
call(sanitized);
});
;
}
function call(number) {
listener
.getChallenge()
.then(({challenge}) => {
const command = new Command();
command
.createCallCommand(challenge, number)
.then((x) => {
listener.sendCommand(x);
});
});
}
function isConfigured()
{
if (
dataStorage.get('username') === ''
|| dataStorage.get('host') === ''
|| dataStorage.get('port') === ''
|| dataStorage.get('securePort') === ''
) {
return false;
}
return true;
}
function checkNumber(number) {
if (number.match(/^\+|\d[\d\s-\.]+$/) === null) {
return false;
}
return true;
}