-
Notifications
You must be signed in to change notification settings - Fork 9
/
autofill2.js
255 lines (172 loc) · 11 KB
/
autofill2.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
// ==UserScript==
// @name AutoFill 2.0
// @namespace http://xaviesteve.com
// @description Fill in the form
// @include http*://*
// @require http://code.jquery.com/jquery-latest.min.js
// @license Creative Commons Attributive Share-Alike 3.0
// ==/UserScript==
// JSON parser - jQuery plugin written by Mark Gibson
// http://jollytoad.googlepages.com/json.js
// $.toJSON(value);
// $.parseJSON(json_str, [safe]);
(function($){var m={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},s={'array':function(x){var a=['['],b,f,i,l=x.length,v;for(i=0;i<l;i+=1){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=','}a[a.length]=v;b=true}}}a[a.length]=']';return a.join('')},'boolean':function(x){return String(x)},'null':function(x){return"null"},'number':function(x){return isFinite(x)?String(x):'null'},'object':function(x){if(x){if(x instanceof Array){return s.array(x)}var a=['{'],b,f,i,v;for(i in x){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=','}a.push(s.string(i),':',v);b=true}}}a[a.length]='}';return a.join('')}return'null'},'string':function(x){if(/["\\\x00-\x1f]/.test(x)){x=x.replace(/([\x00-\x1f\\"])/g,function(a,b){var c=m[b];if(c){return c}c=b.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16)})}return'"'+x+'"'}};$.toJSON=function(v){var f=isNaN(v)?s[typeof v]:s['number'];if(f)return f(v)};$.parseJSON=function(v,safe){if(safe===undefined)safe=$.parseJSON.safe;if(safe&&!/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(v))return undefined;return eval('('+v+')')};$.parseJSON.safe=false})(jQuery);
jQuery(document).ready(function() {
var numprofiles = GM_getValue('af_numprofiles', 1);
var initdatabase = '{"input":{"other":{"value":["loremipsum"],"name":[""]},"search":{"value":[""],"name":["q","search","s"]},"captcha":{"value":[""],"name":["captcha","verif","response","cword","turing","image","security","token","code","validat","human"]},"year":{"value":["1986"],"name":["year","yy","birth","dob"]},"month":{"value":["7"],"name":["month","mm"]},"day":{"value":["23"],"name":["day","dd"]},"age":{"value":["21"],"name":["age"]},"gender":{"value":["male"],"name":["gender","sex"]},"title":{"value":["Dr"],"name":["title"]},"initial":{"value":["GW"],"name":["initial"]},"username":{"value":["garoldwalker"],"name":["user","display","login","nick","id","member","account","name"]},"firstname":{"value":["Garold"],"name":["first","real"]},"middlename":{"value":[""],"name":["middle"]},"lastname":{"value":["Walker"],"name":["last","surname"]},"fullname":{"value":["Garold Walker"],"name":["fullname","full_name"]},"address":{"value":["Dayton, OH 45401"],"name":["address"]},"address2":{"value":[""],"name":["address2"]},"address3":{"value":[""],"name":["address3"]},"address4":{"value":[""],"name":["address4"]},"city":{"value":["Dayton"],"name":["city","town"]},"area":{"value":["51"],"name":["area"]},"state":{"value":["OH"],"name":["state"]},"country":{"value":["United States"],"name":["country","location"]},"zip":{"value":["val1"],"45401":["zip","postal","district"]},"timezone":{"value":["London"],"name":["timezoneoffset"]},"question":{"value":["Who is the best bugger?"],"name":["name1"]},"email":{"value":["[email protected]"],"name":["mail","from"]},"msn":{"value":["[email protected]"],"name":["msn"]},"icq":{"value":["45592738"],"name":["icq"]},"twitter":{"value":["garoldwalker"],"name":["tw"]},"facebook":{"value":["Garold-Walker"],"name":["facebook","fbook","fb"]},"phone":{"value":["5139726287"],"name":["phone","contactno","mob","cell"]},"phone1":{"value":["513"],"name":["phone1"]},"phone2":{"value":["9726"],"name":["phone2"]},"phone3":{"value":["287"],"name":["phone3"]},"fax":{"value":["5139726289"],"name":["fax"]},"company":{"value":["Feel Good Inc."],"name":["company","organization","organisation"]},"position":{"value":["Head of Digital"],"name":["position","occup"]},"identity":{"value":["382014940"],"name":["ident"]},"creditcard":{"value":["4929391046267988"],"name":["credit","card"]},"ccexpirymonth":{"value":["02"],"name":["exp"]},"ccexpiryyear":{"value":["13"],"name":["expyear"]},"hobbie":{"value":["I love to dance!"],"name":["interest","hobbie"]},"web":{"value":["http://xaviesteve.com/"],"name":["web"]},"referrer":{"value":[""],"name":["ref"]},"answer":{"value":["bugmenot"],"name":["answer"]},"password":{"value":["buggybuggy"],"name":["pass","pw","retype","confirm","verify"]}},"checkbox":{"on":["rules","tos","terms","coppa","agree","accept","save","remember","age","legal","confirm","token","login","dst","persistent","cookie"],"off":["adminemail","showemail","receive","pm","news","mail","update","spam","send","offer","agent","disagree","notagree","noagree"]}}';
var database = jQuery.parseJSON( GM_getValue('af_database', initdatabase) );
function autofill() {
// select active profile
var activeprofile = GM_getValue('af_activeprofile', 0);
// unsafeWindow.console.log(name+" "+checkon);
// var value = database[i].value[0];
// INPUTS text and pass
$('input:text,input:password').each(function(index) {
for(var i in database.input) {
// Go through all the different name matches
var names = database.input[i].name;
for(var j in names) {
// If the name matches some part of the name attribute
if ($(this).attr("name").toLowerCase().indexOf( names[j] ) >= 0) {
// Check if the selected profile has a value for it
// and if it is not empty replace the content in the input with it
value = database.input[i].value[ activeprofile ];
if (value) {
$(this).val( value );
} // if value
} // if indexof
} // j names
} // i database
}); // input each
// INPUTS EMPTY text and pass
// Fill in empty ones except Captcha
if (database.input.other.value[ activeprofile ]) {
$('input:text,input:password').each(function(index) {
if (!$(this).val()) {
$(this).val( database.input.other.value[ activeprofile ] );
}
});
}
// CHECKBOXES
$('input:checkbox').each(function(index) {
var name = $(this).attr("name").toLowerCase();
// Check ON?
for(var i in database.checkbox.on) {
var checkon = database.checkbox.on[i];
// Needs to be checked
if (name.indexOf( checkon ) >=0) {
$(this).attr('checked', true);
break;
}
}
// Check OFF?
for(var i in database.checkbox.off) {
var checkoff = database.checkbox.off[i];
// Needs to be unchecked
if (name.indexOf( checkoff ) >=0) {
$(this).removeAttr('checked');
break;
}
}
}); // checkbox each
// RADIOS
// tries to select anything in the ON
// @@@ should avoid checkoffs (agree/disagree will now select disagree)
$('input:radio').each(function(index) {
for(var i in database.checkbox.on) {
$(this).val(database.checkbox.on[i]);
}
});
// var name = $(this).attr("name").toLowerCase();
//var checkon = database.checkbox.on[i];
//$(this).attr('checked', true);
// SELECTS DROPDOWN
// selects the last one for now
$('select').each(function(index) {
var gotselected = 0;
for(var i in database.input) {
// Go through all the different name matches
var names = database.input[i].name;
for(var j in names) {
// select is fillable, now find a valid option
if ($(this).attr("name").toLowerCase().indexOf( names[j] ) >= 0) {
// loop through its options
$(this).find('option').each(function(index) {
// unselect all
$(this).removeAttr("selected");
// see if option value matches database value
if ($(this).html().toLowerCase().indexOf( database.input[i].value[ activeprofile ].toLowerCase() ) >= 0 ||
$(this).val().toLowerCase().indexOf( database.input[i].value[ activeprofile ].toLowerCase() ) >= 0) {
$(this).attr("selected", "selected");
gotselected = 1;
//break;
}
}); // loop through options
} // fillable select
} // j names
} // i database
// if none could be selected then choose the second one
if (gotselected==0) {
$(this).find('option:eq(1)').attr("selected", "selected");
}
});
// CAPTCHA
// Focus on the first captcha field
$('input:text').each(function(index) {
for(var i in database.input.captcha.name) {
// Go through all the captchas name matches
var names = database.input.captcha.name[i];
if ($(this).attr('name').toLowerCase().indexOf( names ) >= 0) {
$(this).val("").focus();
break;
}
}
});
showmessage('AutoFill completed!');
} // function autofill
function menu() {
$('body').append('<div id="autofill_menu" style="background-color: #fbfbfb;border: 1px solid #ccc;border-radius: 10px 10px 10px 10px;font-size: 14px;padding: 10px;position: fixed;right: 20%;text-align: center;top: 10px;width: 60%;z-index: 99999;overflow:scroll;height:500px;"></div>');
var menuhtml = "";
// generate html with variables
menuhtml += '<div style="font-size:24px;font-weight:900;">AutoFill Options</div>';
// Generate html form with database
// Loop through multiple profiles
//for (var profile=0;profile<numprofiles;profile++) {
// menuthml += 'Profile '+(parseInt(profile)+1);
profile = 0;
for(var i in database.input) {
menuhtml += '<div style="display:inline-block;width:31%;margin-bottom:10px;text-align:right;">';
menuhtml += '<label for="af_'+i+'" style="margin-right:5px;">'+i+'</label>';
menuhtml += '<input type="text" id="af_'+i+'" name="'+i+'" value="'+database.input[i].value[ profile ]+'" />';
menuhtml += '</div>';
}
//} // for multiple profiles
menuhtml += '<div text-align:right;><a style="font-size:11px;color:#0085d5;" id="autofill_cancel" href="#">Cancel</a> <a id="autofill_save" href="#" style="font-size:24px;color:#0085d5;">Save changes</a></div>';
$('#autofill_menu').append( menuhtml );
// bind buttons
$('#autofill_save').click(function() {save();$('#autofill_menu').fadeOut();});
$('#autofill_cancel').click(function() {$('#autofill_menu').fadeOut();});
}
function save() {
// @@@ todo
// grab all data from autofill_menu and put into object
$('#autofill_menu input:text').each(function(index) {
//name = $(this).attr('name');
//database.input.;
});
// object to json string
//jsondb = $.toJSON(savedb);
// save to GM
//GM_setValue('af_database', jsondb);
showmessage('AutoFill Options saved!');
}
function showmessage(msg) {
$('body').append('<div id="autofill_msg" style="background-color: #FFC;border: 1px solid #CC6;border-radius: 10px 10px 10px 10px;font-size: 14px;padding: 10px;position: fixed;right: 40%;text-align: center;top: 10px;width: 20%;z-index: 999999;">'+msg+'</div>');
setTimeout(hidemsg, 1500);
}
function hidemsg() {
$('#autofill_msg').fadeOut('slow');
}
GM_registerMenuCommand("Auto-fill - AutoComplete", autofill );
GM_registerMenuCommand("Auto-fill - Options", menu );
}); /* dom ready */