-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
32 lines (26 loc) · 1.06 KB
/
content.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
let savedScrollPosition = null;
document.addEventListener('click', function(e) {
let target = e.target;
while (target.tagName !== 'A' && target.parentElement) {
target = target.parentElement;
}
if (target.tagName === 'A' && target.href.indexOf('.html#') !== -1) {
savedScrollPosition = e.pageY - 10;
let backButton = document.getElementById('scrollBackButton');
if (backButton) {
backButton.style.display = 'block';
} else {
backButton = document.createElement('button');
backButton.textContent = 'Go back';
backButton.id = 'scrollBackButton';
document.body.appendChild(backButton);
backButton.style.position = 'fixed';
backButton.style.bottom = '20px';
backButton.style.left = '20px';
backButton.addEventListener('click', function() {
window.scrollTo(0, savedScrollPosition);
backButton.style.display = 'none';
});
}
}
});