-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
executable file
·40 lines (37 loc) · 1.47 KB
/
background.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
(function() {
// create button element
const elem = document.createElement('button');
// add id to button
elem.setAttribute('id', 'LeverCopyEmail');
// add text to button
elem.innerText = 'Copy';
// style button
elem.style.cssText = 'display:block; background:#00a1dc;color:white;border:none;border-radius:5px;padding:5px 10px;';
// get the content-link classes in the lever page
const contentLink = document.getElementsByClassName('content-link');
let linkContent;
// loop through the content-link class elements on the page
for (let link in contentLink) {
// find the link that contains the '@' sign to target the email address
if (contentLink[link].getAttribute('href').includes('@')) {
linkContent = contentLink[link];
linkContent.parentElement.appendChild(elem);
// add an event listener to the copy button to copy the email address on click
document.getElementById('LeverCopyEmail').addEventListener('click', function(e){
// prevent the button default
e.preventDefault();
// get the email text
const text = linkContent.innerText;
// capture the email address to clipboard
const input = document.createElement('input');
input.style.position = 'fixed';
input.style.opacity = 0;
input.value = text;
document.body.appendChild(input);
input.select();
document.execCommand('Copy');
document.body.removeChild(input);
});
}
}
})();