1
|
|
|
$(document).ready(function () { |
2
|
|
|
function closeDoorhanger() { |
3
|
|
|
API.runtime.sendMessage(API.runtime.id, { |
4
|
|
|
method: "passToParent", |
5
|
|
|
args: {'injectMethod': 'closeDoorhanger'} |
6
|
|
|
}); |
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
var dh = $('#password-doorhanger'); |
10
|
|
|
var btn_config = { |
11
|
|
|
'cancel': function () { |
12
|
|
|
return { |
13
|
|
|
text: API.i18n.getMessage('cancel'), |
14
|
|
|
onClickFn: function () { |
15
|
|
|
API.runtime.sendMessage(API.runtime.id, { |
16
|
|
|
method: "passToParent", |
17
|
|
|
args: {'injectMethod': 'closeDoorhanger'} |
18
|
|
|
}); |
19
|
|
|
API.runtime.sendMessage(API.runtime.id, {method: "clearMined"}); |
20
|
|
|
} |
21
|
|
|
}; |
22
|
|
|
}, |
23
|
|
|
'save': function (data) { |
24
|
|
|
var save = API.i18n.getMessage('save'); |
25
|
|
|
var update = API.i18n.getMessage('update'); |
26
|
|
|
var btnText = (data.guid === null) ? save : update; |
27
|
|
|
return { |
28
|
|
|
text: btnText, |
29
|
|
|
onClickFn: function () { |
30
|
|
|
API.runtime.sendMessage(API.runtime.id, {method: "saveMined"}); |
31
|
|
|
dh.find('.toolbar-text').text(API.i18n.getMessage('saving') + '...'); |
32
|
|
|
dh.find('.passman-btn').hide(); |
33
|
|
|
} |
34
|
|
|
}; |
35
|
|
|
}, |
36
|
|
|
'updateUrl': function (data) { |
37
|
|
|
return { |
38
|
|
|
text: 'Update', |
39
|
|
|
onClickFn: function () { |
40
|
|
|
API.runtime.sendMessage(API.runtime.id, {method: "updateCredentialUrl", args: data}); |
41
|
|
|
dh.find('.toolbar-text').text('Saving...'); |
42
|
|
|
dh.find('.passman-btn').hide(); |
43
|
|
|
} |
44
|
|
|
}; |
45
|
|
|
}, |
46
|
|
|
'ignore': function (data) { |
47
|
|
|
return { |
48
|
|
|
text: API.i18n.getMessage('ignore_site'), |
49
|
|
|
onClickFn: function () { |
50
|
|
|
//closeToolbar(); |
51
|
|
|
API.runtime.sendMessage(API.runtime.id, {method: "ignoreSite", args: data.currentLocation}); |
52
|
|
|
dh.find('.toolbar-text').text(API.i18n.getMessage('site_ignored')); |
53
|
|
|
dh.find('.passman-btn').hide(); |
54
|
|
|
setTimeout(function () { |
55
|
|
|
closeDoorhanger(); |
56
|
|
|
}, 3000); |
57
|
|
|
} |
58
|
|
|
}; |
59
|
|
|
} |
60
|
|
|
}; |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
API.runtime.sendMessage(API.runtime.id, {method: "getDoorhangerData"}).then(function (data) { |
64
|
|
|
if (!data) { |
65
|
|
|
return; |
66
|
|
|
} |
67
|
|
|
var buttons = data.buttons; |
68
|
|
|
data = data.data; |
69
|
|
|
var username = (data.username) ? data.username : data.email; |
70
|
|
|
var doorhanger_div = $('<div id="password-toolbar">'); |
71
|
|
|
$('<span>', { |
72
|
|
|
class: 'toolbar-text', |
73
|
|
|
text: data.title + ' ' + username + ' at ' + data.url |
74
|
|
|
}).appendTo(doorhanger_div); |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
$.each(buttons, function (k, button) { |
78
|
|
|
button = btn_config[button](data); |
79
|
|
|
var html_button = $('<button class="passman-btn passnman-btn-success"></button>').text(button.text); |
80
|
|
|
html_button.click(button.onClickFn); |
81
|
|
|
doorhanger_div.append(html_button); |
82
|
|
|
}); |
83
|
|
|
dh.html(doorhanger_div); |
84
|
|
|
}); |
85
|
|
|
|
86
|
|
|
var _this = {}; |
87
|
|
|
|
88
|
|
|
function minedLoginSaved(args) { |
89
|
|
|
// If the login added by the user then this is true |
90
|
|
|
|
91
|
|
|
var saved = API.i18n.getMessage('credential_saved'); |
92
|
|
|
var updated = API.i18n.getMessage('credential_updated'); |
93
|
|
|
var action = (args.updated) ? updated : saved; |
94
|
|
|
$('#password-toolbar').html(action + '!'); |
95
|
|
|
//@TODO update |
96
|
|
|
setTimeout(function () { |
97
|
|
|
closeDoorhanger(); |
98
|
|
|
}, 2500); |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
_this.minedLoginSaved = minedLoginSaved; |
103
|
|
|
API.runtime.onMessage.addListener(function (msg, sender, sendResponse) { |
|
|
|
|
104
|
|
|
//console.log('Method call', msg.method); |
105
|
|
|
if (_this[msg.method]) { |
106
|
|
|
_this[msg.method](msg.args, sender); |
107
|
|
|
} |
108
|
|
|
}); |
109
|
|
|
}); |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.