-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbackground.js
118 lines (108 loc) · 3.35 KB
/
background.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var currentSetupKey = null;
var core = {
"getOptions": function(){
var result;
try{
result = JSON.parse(localStorage.settings);
result = result[currentSetupKey];
} catch(e){
result = null;
}
return result;
},
}
function fill(info,tab) {
chrome.tabs.executeScript(null, { file: "jquery-3.1.1.min.js" }, function() {
chrome.tabs.executeScript(null, { file: "faker.js" }, function() {
chrome.tabs.executeScript(null, {code: "var deepAutofillChromeExtensionSettings = " + JSON.stringify(core.getOptions()) + ";"}, function(){
chrome.tabs.executeScript(null, { file: "run.js" }, function () {
chrome.notifications.create(
'name-for-notification',{
type: 'basic',
iconUrl: 'monkey48.png',
title: "OK",
message: "Your HTML form was just filled out by a smart but very wild monkey!"
},
function() {}
);
});
});
});
});
}
function getScheme(info,tab) {
chrome.tabs.executeScript(null, { file: "jquery-3.1.1.min.js" }, function() {
chrome.tabs.executeScript(null, { file: "faker.js" }, function() {
chrome.tabs.executeScript(null, {code: "var deepAutofillChromeExtensionSettings = " + JSON.stringify(tab.url) + ";"}, function(){
chrome.tabs.executeScript(null, { file: "scheme.js" }, function () {
var optionsUrl = chrome.extension.getURL('options.html');
chrome.tabs.create({ 'url': optionsUrl });
chrome.notifications.create(
'name-for-notification',{
type: 'basic',
iconUrl: 'monkey48.png',
title: "Selectors copied",
message: "Simply paste the new configuration to a prefered position in you settings."
},
function() {}
);
});
});
});
});
}
var settings = (localStorage.settings ? JSON.parse(localStorage.settings) : {});
var mainContextMenuItem = chrome.contextMenus.create({
title: "Auto Fill"
});
if (localStorage.settings !== undefined){
for(var key in settings){
if (settings.hasOwnProperty(key)){
var menuSetup = settings[key];
chrome.contextMenus.create({
title: key,
contexts:["page"],
onclick: function(info, tab){
currentSetupKey = key;
fill(info, tab)
},
parentId: mainContextMenuItem
});
}
}
for(var key in settings){
if (settings.hasOwnProperty(key)){
var menuSetup = settings[key];
}
}
}
chrome.contextMenus.create({
title: "Random",
contexts:["page"],
onclick: function(info, tab){
currentSetupKey = null;
fill(info, tab)
}
});
chrome.contextMenus.create({
title: "Get Scheme",
contexts:["page"],
onclick: function(info, tab){
getScheme(info, tab)
}
});
chrome.contextMenus.create({
title: "Options",
contexts:["page"],
onclick: function(info, tab){
var optionsUrl = chrome.extension.getURL('options.html');
chrome.tabs.create({ 'url': optionsUrl });
}
});
chrome.browserAction.onClicked.addListener(
function(tab) {
currentSetupKey = null;
// chrome.tabs.sendMessage(tab.id,{"message":"hide"});
fill(null, tab)
}
);