-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcontent.js
57 lines (56 loc) · 1.88 KB
/
content.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
var port = browser.runtime.connect(
{ name: 'passhash-content' }
);
var fieldmarker = 1;
var fieldmarkerhighlight = 1;
port.onMessage.addListener(function(m){
if(m.action == 'sethash') {
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; ++i) {
if (inputs[i].getAttribute('type') == 'password') {
inputs[i].value = m.hash;
}
}
}
else if(m.action == 'init') {
fieldmarker = m.fieldmarker;
fieldmarkerhighlight = m.fieldmarkerhighlight;
if($('input[type=password]').length) {
port.postMessage({action: 'enablePageAction', id: $('input[type=password]')[0].id});
}
$('input[type=password]').each(function(i){
if(fieldmarker == 1 && $(this).is(':visible')) {
var input_id = $(this)[0].id;
var $pwdbtn = $('<div></div>', {'id': 'pwdbtn-' + i, 'class': 'pwdbtn'});
$pwdbtn.html(' # ');
$pwdbtn.css({
'position': 'absolute',
'width': '20px',
'font-size': $(this).css('font-size'),
'font-weight': 'bold',
'padding': '5px',
'margin-left': $(this).width()-5 + 'px',
'text-align': 'center',
'color': $(this).css('color'),
'cursor': 'pointer',
'z-index': 1000
});
if(fieldmarkerhighlight == 1) {
$pwdbtn.css({
'border': 'thin solid #80c080',
'background-color': '#eeffee',
'margin-left': $(this).width()+30 + 'px',
'color': '#609060'
});
}
$pwdbtn.on('click', function(e) {
port.postMessage({action: 'openPopup', id: input_id, domain: document.location.hostname});
});
$(this).before($pwdbtn);
}
$(this).on('contextmenu', function(e){
port.postMessage({action: 'setid', id: $(this)[0].id, domain: document.location.hostname});
});
})
}
});