-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
118 lines (105 loc) · 4.04 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>Raindrop Highlighter</title>
<style>
body {
font-family: monospace;
color: var(--text-color);
background-color: var(--bg-color);
width: 100%;
max-width: 600px;
margin: 1em;
}
h1 {
font-size: 1.5em;
font-weight: bold;
color: #5e81ac;
}
form * {
margin: 1em 0;
}
label {
color: #5e81ac;
font-weight: bold;
}
input, button, textarea {
font-family: inherit;
}
@media (prefers-color-scheme: dark) {
:root {
--text-color: #eceff4;
--bg-color: #2e3440;
}
}
@media (prefers-color-scheme: light) {
:root {
--text-color: #2e3440;
--bg-color: #eceff4;
}
}
</style>
</head>
<body>
<h1>Raindrop Highlighter</h1>
<form>
<label for="url">URL</label><br>
<input type="url" id="url" name="url" size=40><br>
<label for="text">Text</label><br>
<textarea id="text" name="text" cols=40 rows=12 required></textarea><br>
<label for="apiKey">API Key</label><br>
<input type="password" id="apiKey" name="apiKey" size=40><br>
<input type="button" value="Submit" onclick="submitForm()">
</form>
<pre id="response"></pre>
<script>
document.getElementById('apiKey').value = localStorage.getItem('rd_apiKey') || '';
let headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + document.getElementById('apiKey').value
};
function submitForm() {
document.getElementById('response').innerText = '';
localStorage.setItem('rd_apiKey', document.getElementById('apiKey').value);
fetch(`https://api.raindrop.io/rest/v1/raindrops/0?search=${encodeURIComponent(document.getElementById('url').value)}`, {
method: 'GET',
headers: headers
}).then(response => response.json()).then(data => {
if (data.items && data.items[0] && data.items[0]._id) {
let payload = { 'highlights': [{ 'text': document.getElementById('text').value }] };
fetch('https://api.raindrop.io/rest/v1/raindrop/' + data.items[0]._id, {
method: 'PUT',
headers: headers,
body: JSON.stringify(payload)
}).then(response => response.text()).then(data => {
document.getElementById('response').innerText = 'OK';
document.getElementById('text').value = '';
}).catch(error => {
console.error('Error:', error);
document.getElementById('response').innerText = 'Error: ' + error;
});
} else {
let payload = {
'link': document.getElementById('url').value,
'pleaseParse': {},
'highlights': [{ 'text': document.getElementById('text').value }]
};
fetch('https://api.raindrop.io/rest/v1/raindrop', {
method: 'POST',
headers: headers,
body: JSON.stringify(payload)
}).then(response => response.text()).then(data => {
document.getElementById('response').innerText = 'OK';
document.getElementById('text').value = '';
}).catch(error => {
console.error('Error:', error);
document.getElementById('response').innerText = 'Error: ' + error;
});
}
}).catch(error => {
console.error('Error:', error);
});
}
</script>
</body>
</html>