-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote.html
More file actions
148 lines (122 loc) · 5.58 KB
/
note.html
File metadata and controls
148 lines (122 loc) · 5.58 KB
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
143
144
145
146
147
148
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>loading...</title>
<link rel="icon" type="image/x-icon" href="favicon.png">
<link rel="stylesheet" href="main.css?12">
<style>
#note {
padding: 5px;
position: absolute;
width: calc(100% - 44px);
height: 400px;
border: var(--content-border);
margin-left: 50%;
top: 175px;
transform: translate(-50%);
}
#title {
white-space: nowrap;
overflow: hidden;
width: calc(100% - 190px);
}
#edit {
display: none;
}
#menubar {
padding: 5px;
position: absolute;
width: calc(100% - 44px);
height: 50px;
border: var(--content-border);
margin-left: 50%;
top: 100px;
transform: translate(-50%);
}
#menubar button {
margin-top: 6px;
margin-left: 6px;
}
</style>
</head>
<body>
<header>
<svg onclick="history.back()" id="back" xmlns="http://www.w3.org/2000/svg" width="40" height="40" fill="currentColor" class="bi bi-arrow-left-short" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M12 8a.5.5 0 0 1-.5.5H5.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L5.707 7.5H11.5a.5.5 0 0 1 .5.5"/>
</svg>
<h1 id="title">...</h1>
<svg onclick="location.href = 'login.html'" id="profile" xmlns="http://www.w3.org/2000/svg" width="36" height="36" fill="currentColor" class="bi bi-person" viewBox="0 0 16 16">
<path d="M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6Zm2-3a2 2 0 1 1-4 0 2 2 0 0 1 4 0Zm4 8c0 1-1 1-1 1H3s-1 0-1-1 1-4 6-4 6 3 6 4Zm-1-.004c-.001-.246-.154-.986-.832-1.664C11.516 10.68 10.289 10 8 10c-2.29 0-3.516.68-4.168 1.332-.678.678-.83 1.418-.832 1.664h10Z"/>
</svg>
<button onclick="dropdown();" id="new">Create</button>
<div id="dropdown" class="dropdown-content">
<a href="create-set.html">Create New Set</a>
<a href="create-note.html">Create New Note</a>
</div>
</header>
<div id="menubar">
<input id="copy" type="text" value="" style="display: none;">
<button id="copyBtn" onclick="copy()">Copy Share Link</button>
<button id="edit" onclick="">Edit</button>
</div>
<div id="note">
<p></p>
</div>
<script type="text/javascript" src="purify.min.js"></script>
<script src="main.js?v1"></script>
<script>
const noteDiv = document.getElementById('note');
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const id = urlParams.get('id');
if (!id) {
alert('invalid note id');
location.href = 'index.html';
}
window.addEventListener('load', async () => {
let response = await fetcher(`/notes/get/${id}`);
if (response.status == 201) {
let json = await response.json();
// TODO:--------add display of json.creator
// update ui elements with data retrieved
document.getElementById('title').innerText = json.title;
document.title = json.title;
document.getElementById('copy').value = `https://flashstudy.org/note.html?id=${id}`;
let cleanNote = DOMPurify.sanitize(json.note);
noteDiv.innerHTML += cleanNote;
// check auth and allow editing if user is owner
let authResponse = await fetcher(`/auth/check`);
let result = await authResponse.text();
if (result != 'A token is required for authentication' && result != 'Invalid Token') {
let authJson = JSON.parse(result);
if (authJson.username == json.creator) {
// user is owner of set, allow editing
let editButton = document.getElementById('edit');
editButton.style.display = 'inline-block';
editButton.onclick = () => {
location.href = `edit-note.html?id=${id}`;
};
}
}
} else {
// id given in urlparams is either invalid or server bug has occured
alert('invalid note id');
location.href = 'index.html';
}
});
function copy() {
let text = document.getElementById('copy');
text.select();
text.setSelectionRange(0, 99999);
navigator.clipboard.writeText(text.value);
document.getElementById('copy').innerText = 'copied.';
setTimeout(() => {
document.getElementById('copy').innerText = 'Copy Share Link';
}, 1000);
}
</script>
</body>
</html>