-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
executable file
·206 lines (190 loc) · 6.72 KB
/
index.html
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Fluent Tab</title>
<!-- Configuration: Change your prefered background image and the sites to display -->
<script>
function logDebugMessage(...args) {
window.DEBUG && console.log(...args)
}
function logErrorMessage(msg, ...args) {
console.error('❌ ' + msg, ...args)
}
function readFile(file) {
return new Promise(res => {
const reader = new FileReader()
reader.addEventListener('load', f => res(f.target.result))
reader.readAsDataURL(file)
})
}
window.backgroundImage = {
_BACKGROUND_IMAGE: './images/background.jpg',
refresh() {
const storedImage = localStorage.getItem('BACKGROUND_IMAGE')
window.backgroundImage._BACKGROUND_IMAGE = storedImage || './images/background.jpg'
document.body.style.backgroundImage = `url(${window.backgroundImage._BACKGROUND_IMAGE})`
},
reset() {
localStorage.removeItem('BACKGROUND_IMAGE')
backgroundImage.refresh()
console.log('⏮ Image reset, using default from now on.')
},
choose() {
let inputEl = document.body.appendChild(
Object.assign(document.createElement('input'), {
type: 'file',
accept: 'image/*',
hidden: true,
})
)
inputEl.addEventListener('change', ({ target }) => {
const [image] = target.files
logDebugMessage(image)
logDebugMessage('⏳ Processing file...')
if (!/^image\//.test(image.type)) {
return logErrorMessage(
`Selected file is not an image! (invalid image.type: ${image.type})`
)
}
if (image.size > 2000000) {
return logErrorMessage(
`Image mustn't be larger than 2MB! (invalid image.size: ${image.size})`
)
}
readFile(image)
.then(bgImageUrl => {
localStorage.setItem('BACKGROUND_IMAGE', bgImageUrl)
backgroundImage.refresh()
console.log('💡 Background image updated.')
})
.catch(error => {
logErrorMessage('Updating background image failed!')
console.error(error)
})
.finally(() => {
inputEl.remove()
inputEl = null
})
})
inputEl.click()
},
}
const defaultSites = [
'https://facebook.com',
'https://github.com',
'https://mobile.twitter.com',
'https://youtube.com',
'https://theverge.com',
'https://dev.to',
'https://medium.com',
'https://thenounproject.com',
]
window.siteConfig = {
_SITES: [],
refresh(isInitial) {
const storedConfig = localStorage.getItem('SITES')
window.siteConfig._SITES = storedConfig ? JSON.parse(storedConfig) : defaultSites
if (window._refreshThumbnails) window._refreshThumbnails()
else !isInitial && console.log('⚠ You might need to refresh the page to see the changes.')
},
reset() {
localStorage.removeItem('SITES')
window.siteConfig.refresh()
console.log('⏮ siteConfig reset, using default sites from now on.')
},
removeSiteAtPosition(...positions) {
window.siteConfig._SITES = window.siteConfig._SITES.filter(
(_, i) => !positions.includes(i + 1)
)
localStorage.setItem('SITES', JSON.stringify(window.siteConfig._SITES))
window.siteConfig.refresh()
const suffix = positions.length > 1 ? 's' : ''
console.log(`🚮 Removed site${suffix} at position${suffix} ${positions.join(', ')}.`)
},
addSite(link) {
try {
const url = new URL(link)
window.siteConfig._SITES.push(url.href)
localStorage.setItem('SITES', JSON.stringify(window.siteConfig._SITES))
window.siteConfig.refresh()
console.log(`🆕 Added thumbnail for ${url.href}.`)
} catch (e) {
logErrorMessage('Site URL is invalid! Did you forget the protocol? (e.g. http://)')
}
},
}
</script>
<!-- End Configuration -->
<link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="./images/favicon-16.png" />
<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
<script src="./index.mjs" type="module"></script>
<link rel="stylesheet" href="./index.css" />
<style>
.invisible > * {
opacity: 0;
}
body::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 50px;
height: 50px;
background: white;
transform: translate(-50%, -50%);
animation: loader 1s ease infinite;
opacity: 0;
pointer-events: none;
transition: opacity 100ms ease-in;
}
.invisible.spinner::after {
opacity: 1;
transition: opacity 100ms 300ms ease-in;
}
@keyframes loader {
0% {
transform: translate(-50%, -50%) scale(0.5) rotate(0deg);
}
50% {
transform: translate(-50%, -50%) scale(1) rotate(90deg);
}
100% {
transform: translate(-50%, -50%) scale(0.5) rotate(0deg);
}
}
</style>
</head>
<body class="invisible">
<script>
window.siteConfig.refresh(true)
window.backgroundImage.refresh()
</script>
<script>
const el = document.createElement('div')
el.style.cssText =
'width:100px;height:100px;overflow:scroll !important;position:absolute;top:-100vh'
document.body.prepend(el)
if (el.offsetWidth - el.clientWidth > 0) document.body.classList.add('has-scrollbar')
el.remove()
</script>
<div class="blur-bg-fallback"></div>
<header>
<h1>Hi, <span contenteditable id="name">friend</span>!</h1>
<img src="./images/smiley.png" alt="Smiley" class="hello-smiley" />
</header>
<main>
<section id="sites"></section>
</main>
<script>
if (location.hostname !== 'localhost' && 'serviceWorker' in navigator) {
navigator.serviceWorker.register('./serviceworker.js', { scope: '/fluent-tab/' }).catch(error => {
console.error(error)
})
}
</script>
</body>
</html>