-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
122 lines (106 loc) · 3.82 KB
/
index.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
(function(){
var settings;
var inputs = document.querySelectorAll("input")
var hash = document.getElementById("hash")
var key = document.querySelector("#key")
var tag = document.querySelector("#tag")
var unmask = document.querySelector("#unmask")
var unmasklabel = document.querySelector("#unmasklabel")
var settings = document.querySelector("#settings")
var options = document.querySelector("#options")
var bump = document.querySelector("#bump")
var hint = document.querySelector("#hint")
function generateConfig(e) {
var cfg = '';
var elements = document.querySelectorAll("input");
for(var i = 0, element; element = elements[i]; i++) {
if(element.checked === true && element.id != 'unmask'){
cfg += element.value;
}
}
return cfg;
}
var notyf = new Notyf();
function copyTextToClipboard() {
if(!hash.value.length){
return
}
// hash.select();
if( document.execCommand('copy') ){
notyf.confirm('Password copied to clipboard');
}
else{
notyf.confirm('Unable to copy password to clipboard, press CTRL+C manually');
}
}
function main() {
var cfg = generateConfig()
var num = cfg.replace( /^\D+/g, '');
var elements = document.querySelectorAll("input");
for(var i = 0, element; element = elements[i]; i++) {
if(typeof element.type !== 'undefined' && element.type == 'radio') {
element.checked = element.value == num ? true : false;
}
else if (typeof element.type !== 'undefined' && element.type == 'checkbox' && element.id != 'unmask') {
element.checked = cfg.indexOf(element.value) != -1 ? true : false;
}
}
unmask.classList.remove('hidden');
unmasklabel.classList.remove('hidden');
bump.addEventListener('click', function(e){
tag.value = PassHashCommon.bumpSiteTag(tag.value);
hashChange()
});
unmask.addEventListener('click', function(e){
if(this.checked) {
key.setAttribute('type', 'text');
}
else {
key.setAttribute('type', 'password');
}
});
options.addEventListener('click', function(e){
if(settings.classList.contains('hidden')){
settings.classList.remove('hidden');
options.value = 'Options <<';
}
else {
settings.classList.add('hidden');
options.value = 'Options >>';
}
});
function hashChange(e){
var cfg = generateConfig();
var hashWordSize = cfg.replace( /^\D+/g, '');
var requireDigit = ( cfg.indexOf('d') != -1 ? true : false );
var requirePunctuation = ( cfg.indexOf('p') != -1 ? true : false );
var requireMixedCase = ( cfg.indexOf('m') != -1 ? true : false );
var restrictSpecial = ( cfg.indexOf('r') != -1 ? true : false );
var restrictDigits = ( cfg.indexOf('g') != -1 ? true : false );
var hashValue = ''
var hintValue = '$$'
if(key.value && tag.value) {
hashValue = PassHashCommon.generateHashWord(tag.value, key.value, hashWordSize, requireDigit, requirePunctuation, requireMixedCase, restrictSpecial, restrictDigits);
}
if(key.value) {
hintValue = PassHashCommon.generateHashWord(key.value, key.value, 2, true, false, true, false, false);
}
hint.innerText = hintValue
hash.value = hashValue
}
function selectAll(){
this.setSelectionRange(0, this.value.length)
}
Array.from(inputs).forEach(function(input){
input.addEventListener('input', hashChange);
input.addEventListener('change', hashChange);
})
hash.addEventListener('click', selectAll)
hash.addEventListener('focus', selectAll)
hash.addEventListener('focus', copyTextToClipboard);
setTimeout(function(){
document.querySelector('.pwdbtn').remove()
},1000)
}
main()
})()