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