-
Notifications
You must be signed in to change notification settings - Fork 0
/
share.html
97 lines (95 loc) · 3.67 KB
/
share.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<title>MMVI FlowNotes</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js" crossorigin="anonymous"></script>
<script>
$().ready(function() {
let url = new URL(window.location);
let content = '';
if (url.searchParams.get('title')) content += url.searchParams.get('title') + '\n';
if (url.searchParams.get('url')) content += url.searchParams.get('url') + '\n';
if (url.searchParams.get('text')) content += url.searchParams.get('text');
$('#content').val(content);
$('#content').height($('#content').prop('scrollHeight'));
$('#save-new').on('click', function() {
sendToServer({ req: 'add', content: $('#content').val() });
});
$('#modal-body').on('click', '.append-to', function() {
let content = $('#content').val();
if (!content.endsWith('\n')) content += '\n';
if ($('#separator').is(':checked')) {
content = '\n---\n\n' + content;
localStorage.setItem('flownotes-appendwithseparator', 'true');
}
sendToServer({ req: 'append', id: $(this).data('id'), content: content });
});
if (localStorage.getItem('flownotes-appendwithseparator') === 'true') $('#separator').prop('checked', 'true');
sendToServer({ req: 'settings', mode: 'share' });
});
function sendToServer(data) {
$.post({ url: 'data.php', data: JSON.stringify(data), contentType: 'application/json' }).done(parseFromServer).fail(offline);
}
function replacePage(url) {
window.history.replaceState(null, '', url);
window.history.go();
}
function parseFromServer(data, textStatus, xhr) {
if (xhr.status != 200) return offline(xhr);
if (data.error) return offline(data.error);
if (data.alert) alert(data.alert);
$('#status').css('opacity', '0');
if (data.needpass || data.logout) { // Not logged in; refer to main app to handle login procedure
window.location = './#share';
}
if (data.switchnote) {
$('#modal-body').empty().append(
'<p class="ok">Content saved to note with id ' + data.switchnote + '</p>' +
'<p><input type="button" class="modal-button" value="View note" onclick="replacePage(\'./#' + data.switchnote + '\')"></p>'
);
}
if (data.append) {
$('#modal-body').empty().append(
"<p class=\"ok\">Content appended to note '" + data.append.title + "'</p>" +
'<p><input type="button" class="modal-button" value="View note" onclick="replacePage(\'./#' + data.append.id + '\')"></p>'
);
}
if (data.appendnotes) {
for (let note of data.appendnotes) {
$('#appendnotes').append('<p><input type="button" class="append-to modal-button" value="Append to note \'' + note.title + '\'" data-id="' + note.id + '"></p>');
}
}
}
function offline(msg = 'No network connection') {
if (typeof msg != 'string') {
if (msg.status) msg = 'Error from server: ' + msg.status + ' (' + msg.statusText + ')';
else msg = 'No network connection';
}
$('#status').html(msg).css('opacity', 1);
}
</script>
<style>
#content { border: none; margin-top: 0.5rem; min-width: 75vw; }
.ok { font-size: 1.5rem; color: rgb(0, 200, 0); }
</style>
</head>
<body>
<div id="panels"></div>
<div id="modal-overlay">
<div>
<h1>Save to flownotes</h1>
<textarea id="content"></textarea>
<div id="modal-body">
<p><input type="button" id="save-new" class="modal-button" value="Save as new note"></p>
<hr>
<p><input type="checkbox" id="separator"> Append with separator</p>
<div id="appendnotes"></div>
</div>
</div>
</div>
<div id="status" class="nointeraction">Loading...</div>
</body>
</html>