-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
79 lines (70 loc) · 2.1 KB
/
main.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
//
// Open links to external resources in a new tab.
//
$(document).ready(makeAllExternalLinksOpenInNewTab);
function makeAllExternalLinksOpenInNewTab(){
$('a[href^="http://"], a[href^="https://"]').attr('target','_blank');
}
//
// Automatically switch light / dark themes based on system preferences.
//
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)')
function updateTheme() {
const theme = prefersDarkMode.matches ? 'dark' : 'light'
document.documentElement.setAttribute('data-theme', theme)
}
updateTheme();
prefersDarkMode.addEventListener('change', () => updateTheme());
//
// Insert the content of news.html at the beginning of 'newsContainer' div.
//
$(function(){
fetch($('#newsContainer').attr('data-src') + '?t=' + new Date().getTime(), {})
.then(function (response) {
return response.text();
})
.then(function (data) {
$('#newsContainer').prepend(data);
makeAllExternalLinksOpenInNewTab();
})
.catch(function (err) {
console.log(err);
});
});
//
// Transform the markdown content of schedule.md to HTML, then replace the content of 'scheduleContainer' div with the HTML.
//
const markdown = new remarkable.Remarkable({
html: true, // Enable HTML tags in source
});
$(function(){
fetch($('#scheduleContainer').attr('data-src') + '?t=' + new Date().getTime(), {})
.then(function (response) {
return response.text();
})
.then(function (data) {
$('#scheduleContainer').html(markdown.render(data));
makeAllExternalLinksOpenInNewTab();
})
.catch(function (err) {
console.log(err);
});
});
//
// Increment the counter
//
$(function(){
if (window.location.hostname === 'localhost') {
return;
}
fetch('https://count.cab/hit/8CkvG1pF1f', {})
.then(function (response) {
return response.json();
})
.then(function (json) {
// console.log(json);
})
.catch(function (err) {
console.log(err);
});
});