-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (29 loc) · 793 Bytes
/
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
const main = () => {
const disp = window.pageYOffset > 1000 ? 'block' : 'none';
const upBtn = document.createElement('div');
upBtn.setAttribute('class', 'up-button');
upBtn.setAttribute('title', 'UP');
upBtn.style.display = disp;
upBtn.innerText = "UP";
const image = document.createElement('img');
image.src = chrome.extension.getURL('icons/go_up_arrow.png');
upBtn.append(image);
document.getElementsByTagName("body")[0].append(upBtn);
upBtn.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: "smooth"
});
});
window.addEventListener('scroll', () => {
if (window.pageYOffset > 400) {
upBtn.style.display = 'block';
}
else {
upBtn.style.display = 'none';
}
});
};
(() => {
main();
})();