-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
86 lines (71 loc) · 2.34 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
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-57622-13']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
var template = 'Cvccvc99';
function generatePasswords(template, number) {
var chars = {}
chars['l'] = 'abcdefghijklmnoprstuvwxyz';
chars['U'] = chars['l'].toUpperCase();
chars['v'] = 'aeiouy';
chars['V'] = chars['v'].toUpperCase();
chars['c'] = 'bcdfghjklmnprstvwxz';
chars['C'] = chars['c'].toUpperCase();
chars['9'] = '0123456789';
chars['#'] = '!@#$%^&*_-+=()[]{}';
chars['a'] = chars['l'] + chars['9'];
chars['A'] = chars['a'].toUpperCase();
var i, c, possible;
var passwords = [];
for (i = 0; i < number; i++) {
password = '';
for (c = 0; c < template.length; c++) {
possible = chars[template.charAt(c)];
password += possible.charAt(Math.floor(Math.random() * possible.length));
}
passwords.push(password);
}
return passwords;
}
function doPasswords() {
passwords = generatePasswords(template, 10);
var passwordlist = $("ul#passwords");
$.each(passwords, function(i, password) {
passwordlist.append($("<li>").text(password));
});
}
doPasswords();
$('#passwords').on('click', 'li', function() {
var range = document.createRange();
range.selectNode(this);
window.getSelection().addRange(range);
var successful = false;
try {
// Now that we've selected the anchor text, execute the copy command
successful = document.execCommand('copy');
} catch(err) {
successful = false;
// whatever
}
if (!successful) {
prompt("Your browser does not support insta-copy. Sorry.", $(this).text());
}
// Remove the selections - NOTE: Should use
// removeRange(range) when it is supported
window.getSelection().removeAllRanges();
});
function disableSelect(e) { return false; }
function reEnable() { return true; }
document.onselectstart=disableSelect;
if (window.sidebar){
document.onmousedown=disableSelect
document.onclick=reEnable
}
$('.more').on('click', function() {
$('#passwords li').remove();
doPasswords();
});