]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/misc/utils.ts
Fix tests
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / misc / utils.ts
CommitLineData
f3aaa9a9
C
1// Thanks: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
2
15a7387d
C
3import { AuthService } from '../../core/auth'
4
f3aaa9a9
C
5function getParameterByName (name: string, url: string) {
6 if (!url) url = window.location.href
7 name = name.replace(/[\[\]]/g, '\\$&')
8
9 const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)')
10 const results = regex.exec(url)
11
12 if (!results) return null
13 if (!results[2]) return ''
14
15 return decodeURIComponent(results[2].replace(/\+/g, ' '))
16}
17
cd83ea1b
C
18function viewportHeight () {
19 return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)
20}
21
15a7387d
C
22function populateAsyncUserVideoChannels (authService: AuthService, channel: any[]) {
23 return new Promise(res => {
24 authService.userInformationLoaded
25 .subscribe(
26 () => {
27 const user = authService.getUser()
28 if (!user) return
29
30 const videoChannels = user.videoChannels
31 if (Array.isArray(videoChannels) === false) return
32
33 videoChannels.forEach(c => channel.push({ id: c.id, label: c.name }))
34
35 return res()
36 }
37 )
38 })
39}
40
f3aaa9a9 41export {
cd83ea1b 42 viewportHeight,
15a7387d
C
43 getParameterByName,
44 populateAsyncUserVideoChannels
f3aaa9a9 45}