-
Notifications
You must be signed in to change notification settings - Fork 3
/
random-password.user.js
52 lines (48 loc) · 1.82 KB
/
random-password.user.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
// ==UserScript==
// @name random password
// @namespace http://tampermonkey.net/
// @version 0.1
// @description alert a randomly generated password of words and numerals
// @author Josh Parker
// @match https://hryanjones.com/guess-my-word/
// @icon https://www.google.com/s2/favicons?domain=hryanjones.com
// @grant none
// ==/UserScript==
(function randomPassword() {
// eslint-disable-next-line no-undef
const normals = possibleWords.normal;
// eslint-disable-next-line no-undef
const hards = possibleWords.hard;
const randint = (high) => Math.floor(Math.random() * high);
const choose = (arr) => arr[randint(arr.length)];
const wordLengthIs = (n) => (w) => w.length === n;
const wordsOfLength = (n) => normals.filter(wordLengthIs(n)).concat(hards.filter(wordLengthIs(n)));
const fours = wordsOfLength(4);
const fives = wordsOfLength(5);
const randFour = () => choose(fours);
const randFive = () => choose(fives);
const randNum = () => randint(10);
const passComponents = [randFour, randNum, randFive, randNum];
const randPass = Array(8)
.fill()
.map((e, i) => passComponents[i % passComponents.length]())
.join('');
const dotPos = randint(randPass.length);
const dottedRandPass = `${randPass.slice(0, dotPos)}.${randPass.slice(dotPos)}`;
const capSearchPos = randint(dottedRandPass.length - 1);
const alertMessage = "Here's a randomly generated password of words and numerals: ";
for (let i = capSearchPos; i < dottedRandPass.length; i++) {
if (/^[a-z]/.test(dottedRandPass.slice(i))) {
// eslint-disable-next-line no-alert
alert(
alertMessage
+ dottedRandPass.slice(0, i)
+ dottedRandPass[i].toLocaleUpperCase()
+ dottedRandPass.slice(i + 1),
);
return;
}
}
// eslint-disable-next-line no-alert
alert(alertMessage + dottedRandPass);
}());