-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent_script.js
More file actions
55 lines (39 loc) · 1.42 KB
/
content_script.js
File metadata and controls
55 lines (39 loc) · 1.42 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
(function() {
// 'getFormsData' function, credits go to:
// https://github.com/bgrins/devtools-snippets/tree/master/snippets/formcontrols
function getFormsData(){
var forms = document.querySelectorAll("form");
// credits to :
// https://github.com/bgrins/devtools-snippets/blob/master/snippets/formcontrols/formcontrols.js
for (var i = 0, len = forms.length; i < len; i++) {
var tab = [ ];
["input", "textarea", "select"].forEach(function (control) {
[].forEach.call(forms[i].querySelectorAll(control), function (node) {
tab.push({
"element": node,
"type": node.type,
"name": node.name,
"value": node.value,
"prettyValue": (isNaN(node.value) || node.value === "" ? node.value : parseFloat(node.value))
});
});
});
return tab;
}
}
// use connect for a long-time messaging.
var port = chrome.runtime.connect({name: "formToJSON"});
port.onMessage.addListener(function(msg) {
// background script is looking for forms data.
if(msg.command && msg.command == 'getFormsValues'){
var date = new Date();
data = {
link:window.location.href,
timestamp: date.getTime(),
day: date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear(),
data: getFormsData(),
}
port.postMessage({type:'answer',data});
}
});
})();