1 function toTitleCase (str: string) {
2 return str.charAt(0).toUpperCase() + str.slice(1)
5 // https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts
6 // Don't import all Angular stuff, just copy the code with shame
7 const dictionaryBytes: Array<{max: number, type: string}> = [
8 { max: 1024, type: 'B' },
9 { max: 1048576, type: 'KB' },
10 { max: 1073741824, type: 'MB' },
11 { max: 1.0995116e12, type: 'GB' }
13 function bytes (value) {
14 const format = dictionaryBytes.find(d => value < d.max) || dictionaryBytes[dictionaryBytes.length - 1]
15 const calc = Math.floor(value / (format.max / 1024)).toString()
17 return [ calc, format.type ]
20 function getStoredVolume () {
21 const value = getLocalStorage('volume')
22 if (value !== null && value !== undefined) {
23 const valueNumber = parseFloat(value)
24 if (isNaN(valueNumber)) return undefined
32 function getStoredMute () {
33 const value = getLocalStorage('mute')
34 if (value !== null && value !== undefined) return value === 'true'
39 function getAverageBandwidth () {
40 const value = getLocalStorage('average-bandwidth')
41 if (value !== null && value !== undefined) {
42 const valueNumber = parseInt(value, 10)
43 if (isNaN(valueNumber)) return undefined
51 function saveVolumeInStore (value: number) {
52 return setLocalStorage('volume', value.toString())
55 function saveMuteInStore (value: boolean) {
56 return setLocalStorage('mute', value.toString())
59 function saveAverageBandwidth (value: number) {
60 return setLocalStorage('average-bandwidth', value.toString())
63 function isMobile () {
64 return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent)
67 function buildVideoLink (time?: number) {
68 let href = window.location.href.replace('/embed/', '/watch/')
70 const timeInt = Math.floor(time)
72 if (window.location.search) href += '&start=' + timeInt
73 else href += '?start=' + timeInt
79 function buildVideoEmbed (embedUrl: string) {
80 return '<iframe width="560" height="315" ' +
81 'src="' + embedUrl + '" ' +
82 'frameborder="0" allowfullscreen>' +
86 function copyToClipboard (text: string) {
87 const el = document.createElement('textarea')
89 el.setAttribute('readonly', '')
90 el.style.position = 'absolute'
91 el.style.left = '-9999px'
92 document.body.appendChild(el)
94 document.execCommand('copy')
95 document.body.removeChild(el)
103 saveAverageBandwidth,
113 // ---------------------------------------------------------------------------
115 const KEY_PREFIX = 'peertube-videojs-'
117 function getLocalStorage (key: string) {
119 return localStorage.getItem(KEY_PREFIX + key)
125 function setLocalStorage (key: string, value: string) {
127 localStorage.setItem(KEY_PREFIX + key, value)
128 } catch { /* empty */ }