-
Notifications
You must be signed in to change notification settings - Fork 0
/
me.html
134 lines (118 loc) · 4.36 KB
/
me.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="shortcut icon" href="icon-48x48.png">
<meta name="description" content="An open source sheet-to-site template for personal travel log">
<meta name="author" content="Yuin Chien">
<title>Traces Report</title>
<link href="https://fonts.googleapis.com/css?family=EB+Garamond:400,400i,500,500i,700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-18616613-2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-18616613-2');
</script>
</head>
<body class="loading">
<div id="loader"></div>
<div id="sections" class="wip">
<div id="footer"><span class="button" id="button-edit">Edit Sheet ID</span> / <a class="button" href="https://github.com/yuinchien/traces.report" target="_blank">Github</a> / <a class="button" id="link-sheet" target="_blank">Edit Spreadsheet</a> </div>
</div>
<div id="form" class="wip">
<div class="buttons">
<div id="button-cancel" class="button">CANCEL</div>
<div id="button-save" class="button inactive">SAVE</div>
</div>
<div class="wrapper">
<p>Save your <span class="highlight">Google sheet ID</span> using localStorage and access your personal site at <span class="highlight">traces.report/me</span>.</p>
<input type="text" id="input-id" name="fname" placeholder="Sheet ID" autocomplete="off" spellcheck="false">
</div>
</div>
<script src="script.js"></script>
<script>
const load = () => {
let sheetID = localStorage.getItem('sheetID');
document.querySelectorAll('.section').forEach(function(element){
element.remove();
});
fetchTabs(sheetID)
.then(data => {
if(data==-1) {
console.log("clear localStorage");
localStorage.clear();
toggleEdit(true);
document.body.classList.remove('loading');
return;
}
var sheetName = "";
for(title in data) {
if(data[title].index==0) {
sheetName = data[title].title;
break;
}
}
fetchRows(sheetID, sheetName)
.then(data => {
create(data);
createOverview(data);
document.getElementById("link-sheet").setAttribute("href", `https://docs.google.com/spreadsheets/d/${sheetID}/edit#gid=0`);
document.body.classList.remove('loading');
})
})
}
const initEvents = () => {
let input = document.getElementById("input-id");
let sheetID = localStorage.getItem('sheetID');
document.getElementById("button-cancel").addEventListener('click', function(e){
toggleEdit(false);
});
var buttonSave = document.getElementById("button-save");
buttonSave.addEventListener('click', function(e){
sheetID = input.value.trim();
localStorage.setItem("sheetID", sheetID);
document.body.classList.add('loading');
toggleEdit(false);
load();
});
input.addEventListener('input', updateValue);
function updateValue(e) {
buttonSave.classList.toggle("inactive", !e.target.value.length>0);
}
var buttonEdit = document.getElementById("button-edit");
buttonEdit.addEventListener('click', function(e){
toggleEdit(true);
});
}
const toggleEdit = (value) => {
const input = document.getElementById("input-id");
let sheetID = localStorage.getItem('sheetID');
document.getElementById("button-cancel").classList.toggle("hide", !sheetID);
if(value) {
input.value = sheetID || "";
document.body.classList.add("edit");
input.focus();
} else {
document.body.classList.remove("edit");
}
}
const handleClientLoad = () => {
initEvents();
let sheetID = localStorage.getItem('sheetID');
if(!sheetID) {
toggleEdit(true);
document.body.classList.remove('loading');
} else {
load();
}
}
</script>
<script async defer src="https://apis.google.com/js/api.js"
onload="this.onload=function(){};handleClientLoad()"
onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>
</body>