1 import { is18nLocale, isDefaultLocale } from '../../../../shared/models/i18n/i18n'
3 function toTitleCase (str: string) {
4 return str.charAt(0).toUpperCase() + str.slice(1)
7 // https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts
8 // Don't import all Angular stuff, just copy the code with shame
9 const dictionaryBytes: Array<{max: number, type: string}> = [
10 { max: 1024, type: 'B' },
11 { max: 1048576, type: 'KB' },
12 { max: 1073741824, type: 'MB' },
13 { max: 1.0995116e12, type: 'GB' }
15 function bytes (value) {
16 const format = dictionaryBytes.find(d => value < d.max) || dictionaryBytes[dictionaryBytes.length - 1]
17 const calc = Math.floor(value / (format.max / 1024)).toString()
19 return [ calc, format.type ]
22 function getStoredVolume () {
23 const value = getLocalStorage('volume')
24 if (value !== null && value !== undefined) {
25 const valueNumber = parseFloat(value)
26 if (isNaN(valueNumber)) return undefined
34 function getStoredMute () {
35 const value = getLocalStorage('mute')
36 if (value !== null && value !== undefined) return value === 'true'
41 function getAverageBandwidth () {
42 const value = getLocalStorage('average-bandwidth')
43 if (value !== null && value !== undefined) {
44 const valueNumber = parseInt(value, 10)
45 if (isNaN(valueNumber)) return undefined
53 function saveVolumeInStore (value: number) {
54 return setLocalStorage('volume', value.toString())
57 function saveMuteInStore (value: boolean) {
58 return setLocalStorage('mute', value.toString())
61 function saveAverageBandwidth (value: number) {
62 return setLocalStorage('average-bandwidth', value.toString())
65 function isMobile () {
66 return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent)
69 function buildVideoLink (time?: number) {
70 let href = window.location.href.replace('/embed/', '/watch/')
72 const timeInt = Math.floor(time)
74 if (window.location.search) href += '&start=' + timeInt
75 else href += '?start=' + timeInt
81 function buildVideoEmbed (embedUrl: string) {
82 return '<iframe width="560" height="315" ' +
83 'src="' + embedUrl + '" ' +
84 'frameborder="0" allowfullscreen>' +
88 function copyToClipboard (text: string) {
89 const el = document.createElement('textarea')
91 el.setAttribute('readonly', '')
92 el.style.position = 'absolute'
93 el.style.left = '-9999px'
94 document.body.appendChild(el)
96 document.execCommand('copy')
97 document.body.removeChild(el)
105 saveAverageBandwidth,
115 // ---------------------------------------------------------------------------
117 const KEY_PREFIX = 'peertube-videojs-'
119 function getLocalStorage (key: string) {
121 return localStorage.getItem(KEY_PREFIX + key)
127 function setLocalStorage (key: string, value: string) {
129 localStorage.setItem(KEY_PREFIX + key, value)
130 } catch { /* empty */ }