-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.js
More file actions
102 lines (81 loc) · 2.44 KB
/
settings.js
File metadata and controls
102 lines (81 loc) · 2.44 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function preparePassword(password)
{
const offset = 50;
var alphabet = String.fromCharCode;
var modifedPassword = "";
for (var i = 0; i < password.length; i++)
{
modifedPassword += alphabet(password.charCodeAt(i) + offset);
}
return modifedPassword;
}
function updatePasswords(id, password)
{
function setCurrent(passwords, id, password)
{
var modifedPassword = preparePassword(password);
passwords[id] = modifedPassword;
chrome.storage.sync.set({
passwords: passwords
}, function() {
var status = document.getElementById('status');
status.textContent = 'Изменения сохранены';
setTimeout(function() {
status.textContent = '';
}, 750);
});
}
chrome.storage.sync.get({
passwords: null,
}, function(items) {
if (items.passwords == null)
{
items.passwords = {};
}
setCurrent(items.passwords, id, password);
});
}
function save_options(id) {
var password = document.getElementById('password').value;
//var hashedPassword = SHA256(password);
if (password != '')
{
if ("" == id)
{
return;
}
//TODO get encryption
updatePasswords(id, password);
}
}
function restore_options(id) {
var status = document.getElementById('status');
if ("" == id)
{
status.textContent = 'Сначала зайдите в диалог Вконтакте';
return;
}
document.getElementById('password').removeAttribute("disabled");
document.getElementById('save').removeAttribute("disabled");
chrome.storage.sync.get({
passwords: null,
}, function(items) {
if (items.passwords != null)
{
if (typeof items.passwords[id] !== "undefined")
{
document.getElementById('password').value = items.passwords[id];
}
console.log(items.passwords);
}
});
status.textContent = "Диалога с id:" + id + ".";
}
document.addEventListener('DOMContentLoaded', function ()
{
getID(restore_options);
});
document.getElementById('save').addEventListener('click', function ()
{
getID(save_options);
});