-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
68 lines (59 loc) · 1.66 KB
/
index.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
//*mobile check*//
const isMobile = function() {
const match = window.matchMedia('(pointer:coarse)');
return (match && match.matches && window.innerWidth <= 480);
};
const isFirefox = (/Firefox/i.test(navigator.userAgent));
const random = function(version) {
//random is 0 ~ 1
//version is integer, output is in em
return 0.6*(0.5*Math.random() + version) + 'em';
};
//*dark mode check*//
window.addEventListener('load', startup);
window.addEventListener('resize', showDimensions);
function startup() {
renderElements();
showDimensions();
}
function renderElements() {
if(document.querySelector('.data'))
{
let pageElements = JSON.parse(document.querySelector('.data').textContent);
let pageList = document.querySelector('.page-list');
if(pageList != null)
{
pageList.innerHTML = '';
}
let group = '';
for(let page of pageElements)
{
if(group != page.group) {
let br = document.createElement('br');
pageList.appendChild(br);
group = page.group;
let grp = document.createElement('div');
grp.classList.add('group');
grp.innerText = group;
pageList.appendChild(grp);
}
// add page
let url = document.createElement('a');
url.classList.add('subset');
url.classList.add('box');
url.classList.add('shadowed');
url.style.fontSize = random(page.priority);
if(page.isLocal)
url.classList.add('local');
url.href = page.url;
url.innerText = page.title;
pageList.appendChild(url);
}
}
}
function showDimensions() {
if(document.querySelector('.dimensions') != null)
{
document.querySelector('.dimensions').innerText = window.innerWidth + 'px by ' + window.innerHeight + 'px';
}
}