forked from Farow/userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
email-filler.user.js
54 lines (42 loc) · 1.12 KB
/
email-filler.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
53
54
// ==UserScript==
// @name Email filler
// @namespace https://github.com/Farow/userscripts
// @description Fills your email on input and text fields
// @include *
// @version 1.0.0
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
const emails = [
'work.email@example.com',
'personal.email@example.com',
];
document.addEventListener('keypress', keypress);
function keypress (event) {
if (event.code != 'KeyE') {
return;
}
if (!event.ctrlKey) {
return;
}
if (event.target.tagName != 'INPUT' && event.target.tagName != 'TEXTAREA') {
return;
}
fill_email(event.target);
event.preventDefault();
}
function fill_email (target) {
const email = emails.shift();
/* save the selection as it gets reset when changing the input value */
const selection_start = target.selectionStart;
target.value = (
/* before selection */
target.value.substring(0, selection_start) +
/* replace selection */
email +
/* after selection */
target.value.substring(target.selectionEnd)
);
target.setSelectionRange(selection_start, selection_start + email.length);
emails.push(email);
}