-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
146 lines (123 loc) · 5.84 KB
/
main.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
console.log("this is main.js"+$("form"));
var randomtextcontent = "The order of battle of the Croatian Special Police in 1991–95 included up to 30 individual special forces units subordinated to the Ministry of the Interior. The special police (logo pictured) was created around the Ministry of the Interior's existing airborne special forces unit following an open revolt of the Croatian Serbs against the Government of Croatia in August 1990. It further developed with the increasing involvement of the Yugoslav People's Army in the conflict, supporting the Croatian Serbs. The conflict escalated into the Croatian War of Independence in 1991. The special police took part in the first clashes of the war in Pakrac and at the Plitvice Lakes. As Croatia had no army, the 3,000-strong special forces became the country's most effective fighting force. Even though several special police units were transformed into the Croatian National Guard (later renamed the Croatian Army) in 1991, the special police continued to operate throughout the war as special forces units supporting virtually all army operations.";
var randomNames = ["Sherrell Basel",
"Elijah Markell",
"Bree Gunnell",
"Matha Rhymes",
"Roxann Mcquillen",
"Jermaine Demyan",
"Tresa Eure",
"Annika Flowers",
"Carrie Thorsen",
"Angla Briese",
"Erwin Losh",
"Mandy Langstaff",
"Gidget Spinelli",
"Kia Collelo",
"Sandi Borgman",
"Marth Peets",
"Tashia Beisner",
"Chelsey Nowlen",
"Jude Monreal",
"Zada Suman"];
init();
function init(){
console.log("init function");
var checkboxnames = [];
var radioboxnames = [];
$('form *').filter(':input').each(function(){
//your code here
var ele = $(this);
console.log(ele+ele.css('display'));
if(ele.css('display') != 'none'){
console.log(ele);
// store it so that we can use it in password confirmation field also
var password = generatePassword();
var type = ele.attr('type');
console.log("its type is"+type+" tag is "+ele.prop("tagName"));
if(type == "text"){
ele.val(randomNames[Math.round(Math.random()*19)]);
}
else if(type == "number"){
ele.val(Math.random()*100);
}
else if(type == "password"){
console.log("pass = "+password);
ele.val(password);
}
else if(type == "checkbox"){
//get the checkbox name for grouping elements
var checkname = ele.attr('name');
console.log("checkbox name = "+checkname);
//if once iterated it will be in array so will avoid repeating same group again
if(checkboxnames.indexOf(checkname) == -1){
$("input[name='"+checkname+"']").each( function () {
//check value will be either 0 or 1 randomly
var checkvalue = Math.round(Math.random()*1);
console.log(checkvalue);
if(checkvalue == 1)
$(this).attr('checked',true);
else
$(this).removeAttr('checked');
console.log($(this).val()+checkvalue);
});
//push each checkbox group name to array thus preventing
//repeatation of looping to same group again
checkboxnames.push(checkname);
}
}
else if(type == "radio"){
//get the checkbox name for grouping elements
var radioname = ele.attr('name');
console.log("radio name = "+radioname);
//if once iterated it will be in array so will avoid repeating same group again
if(radioboxnames.indexOf(radioname) == -1){
$("input[name='"+radioname+"']").each( function () {
//radio value will be either 0 or 1 randomly
var radiovalue = Math.round(Math.random()*1);
console.log(radiovalue);
if(radiovalue == 1)
$(this).attr('checked',true);
else
$(this).removeAttr('checked');
console.log($(this).val()+radiovalue);
});
//push each radiobox group name to array thus preventing
//repeatation of looping to same group again
radioboxnames.push(radioname);
}
}
else if(ele.prop("tagName") == "SELECT"){
var randomindex = Math.round(Math.random()*ele.children('option').length);
if(typeof ele[0][randomindex] !== 'undefined')
ele[0][randomindex].selected = 'selected';
}
}
});
radioboxnames = [];
}
//to generate random password
function generatePassword() {
var length = 10,
charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
retVal = "";
for (var i = 0, n = charset.length; i < length; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * n));
}
return retVal;
}
//Where el is the DOM element you'd like to test for visibility
function isHidden(el) {
return (el.offsetParent === null)
}
//
//chrome.runtime.onMessage.addListener(
// function(request, sender, sendResponse) {
// console.log(sender.tab ?
// "from a content script:" + sender.tab.url :
// "from the extension");
// if (request.type == "initclick")
// sendResponse("got init click");
//
// init();
// });