/
script-compiled.js
142 lines (132 loc) · 4.47 KB
/
script-compiled.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
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
'use strict';
var request = new Request('./videos.json', { method: 'GET' });
var min = void 0;
var sek = void 0;
var skil = void 0;
var results = document.querySelector('.body');
var div0 = void 0;
var div1 = void 0;
var div2 = void 0;
var div3 = void 0;
var div4 = void 0;
var div5 = void 0;
var link = void 0;
var mynd = void 0;
var h1 = void 0;
var h2 = void 0;
var timinn = void 0;
var p1 = void 0;
var i = void 0;
var j = void 0;
var texti = void 0;
var videoSida = './video.html?id=';
function removeBuffering() {
var buff = document.querySelector('.buff');
var main = document.querySelector('main');
main.removeChild(buff);
}
function buffering() {
var main = document.querySelector('main');
var buff = document.createElement('h1');
var textNode = document.createTextNode('Hleð inn gögn....');
buff.appendChild(textNode);
buff.classList.add('buff');
main.appendChild(buff);
}
function timiSidan(msek) {
var d = new Date();
var timi = d - msek;
if (Math.floor(timi / 1000 / 60 / 60 / 24 / 365) > 0) {
texti = 'Fyrir ' + Math.floor(timi / 1000 / 60 / 60 / 24 / 365) + ' \xE1rum s\xED\xF0an';
return texti;
} else if (Math.floor(timi / 1000 / 60 / 60 / 24 / 30) > 0) {
texti = 'Fyrir ' + Math.floor(timi / 1000 / 60 / 60 / 24 / 30) + ' m\xE1nu\xF0um s\xED\xF0an';
return texti;
} else if (Math.floor(timi / 1000 / 60 / 60 / 24 / 7) > 0) {
texti = 'Fyrir ' + Math.floor(timi / 1000 / 60 / 60 / 24 / 7) + ' vikum s\xED\xF0an';
return texti;
} else if (Math.floor(timi / 1000 / 60 / 60 / 24) > 0) {
texti = 'Fyrir ' + Math.floor(timi / 1000 / 60 / 60 / 24) + ' d\xF6gum s\xED\xF0an';
return texti;
}
texti = 'Fyrir ' + Math.floor(timi / 1000 / 60 / 60) + ' sek s\xED\xF0an';
return texti;
}
function lengdMyndbands(seconds) {
min = Math.floor(seconds / 60);
sek = Math.floor(seconds % 60);
if (sek < 10) {
sek = '0' + sek;
}
if (min < 10) {
min = '0' + min;
}
skil = min + ':' + sek;
return skil;
}
function addText(obj) {
div0 = document.createElement('div');
for (j = 0; j < obj.categories.length; j += 1) {
div1 = document.createElement('div');
div2 = document.createElement('div');
div5 = document.createElement('div');
h1 = document.createElement('h1');
div2.appendChild(h1);
div1.appendChild(div2);
h1.appendChild(document.createTextNode(obj.categories[j].title));
div0.appendChild(div1);
div1.setAttribute('class', 'row kafli');
div2.setAttribute('class', 'col');
div5.setAttribute('class', 'row');
for (i = 0; i < obj.categories[j].videos.length; i += 1) {
div3 = document.createElement('div');
div4 = document.createElement('div');
link = document.createElement('a');
mynd = document.createElement('img');
h2 = document.createElement('h2');
p1 = document.createElement('p');
timinn = document.createElement('div');
div3.appendChild(div4);
div4.appendChild(link);
link.appendChild(mynd);
div4.appendChild(timinn);
div4.appendChild(h2);
div4.appendChild(p1);
div3.setAttribute('class', 'col col-12 col-m-6 col-l-4');
link.setAttribute('href', videoSida + obj.videos[obj.categories[j].videos[i] - 1].id);
div4.setAttribute('class', 'container');
mynd.src = obj.videos[obj.categories[j].videos[i] - 1].poster;
mynd.setAttribute('class', 'mynd');
timinn.setAttribute('class', 'timinn');
mynd.setAttribute('id', obj.videos[obj.categories[j].videos[i] - 1].id);
texti = timiSidan(obj.videos[obj.categories[j].videos[i] - 1].created);
p1.appendChild(document.createTextNode(texti));
h2.appendChild(document.createTextNode(obj.videos[obj.categories[j].videos[i] - 1].title));
texti = lengdMyndbands(obj.videos[obj.categories[j].videos[i] - 1].duration);
timinn.appendChild(document.createTextNode(texti));
div5.appendChild(div3);
}
div0.appendChild(div5);
}
results.appendChild(div0);
var grid = document.querySelector('.body');
removeBuffering();
grid.hidden = false;
}
function setUp() {
fetch(request).then(function (response) {
if (response.status === 200) {
return response.json();
}
throw new Error('Something went wrong on api server!');
}).then(function (response) {
console.debug(response);
var json = response;
addText(json);
}).catch(function (error) {
console.error(error);
});
}
buffering();
document.addEventListener('DOMContentLoaded', setUp);
//# sourceMappingURL=script-compiled.js.map