-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
117 lines (79 loc) · 3.45 KB
/
script.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const starRepoButton = document.querySelector('.starRepoButton')
let quickAccess = document.querySelector('.quickAccess-wrapper');
let scrollToTopButton = document.querySelector('.scrollToTopButton');
document.addEventListener('DOMContentLoaded', function () {
// Show scrollToTop, quickAccess & starRepoButton after scrolling a bit
window.addEventListener('scroll', function () {
if (window.scrollY > 200) {
quickAccess.style.display = 'flex';
scrollToTopButton.style.display = 'flex';
starRepoButton.style.display = 'flex';
} else {
quickAccess.style.display = 'none';
scrollToTopButton.style.display = 'none';
starRepoButton.style.display = 'none';
}
});
// Open & close quick access
quickAccess.addEventListener('mouseenter', (e)=>{
let quickAccessDetails = document.querySelector('.quickAccess-wrapper details');
console.log(quickAccessDetails);
quickAccessDetails.open = true
})
quickAccess.addEventListener('mouseleave', (e)=>{
let quickAccessDetails = document.querySelector('.quickAccess-wrapper details');
quickAccessDetails.open = false
})
// Show Quick Access despite of the scroll position if mouse enters that area
document.addEventListener('mousemove', e=>{
if (e.x >= 800 && e.y <= 80) {
quickAccess.style.display = 'flex'
}
})
// Scroll to top functionality
scrollToTopButton.addEventListener('click', function () {
window.scrollTo({
top: 0,
// Smooth scroll to top when the scroll indicator is clicked
behavior: 'smooth'
});
});
// Subscribe dialog functionality
const subscribeDialog = document.querySelector('.subscribeDialog')
subscribeDialog.style.display = 'none'
console.log(subscribeDialog);
const chromeInstallLink = document.querySelector('.chromeWebstoreLink')
chromeInstallLink.addEventListener('click', (e) => {
// e.preventDefault()
subscribeDialog.showModal()
subscribeDialog.style.display = 'flex'
})
const closeSubscribeDialogButton = subscribeDialog.querySelector('.closeSubscribeDialogButton')
console.log(closeSubscribeDialogButton);
window.addEventListener('keydown', e=>{
if (e.key == "Escape" && subscribeDialog.style.display=='flex') {
subscribeDialog.close()
subscribeDialog.style.display = 'none'
}
})
closeSubscribeDialogButton.addEventListener('click', (e) => {
subscribeDialog.close()
subscribeDialog.style.display = 'none'
})
});
const switchModeButton = document.querySelector('.switchMode')
const productHuntLinkImg = document.querySelector('.productHuntLink img')
switchModeButton.addEventListener('click', ()=>{
const root = document.querySelector('html')
if (root.classList.contains('dark')) {
root.classList.remove('dark')
productHuntLinkImg.src = (productHuntLinkImg.src).replace("theme=dark", "theme=light")
}
else{
root.classList.add('dark')
productHuntLinkImg.src = (productHuntLinkImg.src).replace("theme=light", "theme=dark")
}
})
starRepoButton.addEventListener('click', ()=>{
window.open("https://github.com/mywebshortcuts/mywebshortcuts", "_blank")
})