This repository was archived by the owner on Feb 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdevlinks_index.html
55 lines (49 loc) · 1.95 KB
/
devlinks_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
<html>
<head>
<script src='/_ah/channel/jsapi'></script>
</head>
<body>
<script type='text/javascript'>
var connected;
add_link = function() {
var link = encodeURIComponent(document.getElementById('link_input').value);
var namespace = encodeURIComponent(document.getElementById('name_input').value);
var comment = encodeURIComponent(document.getElementById('comment_input').value);
sendMessage('/links/add?link=' + link + '&name={{device_name}}&receiver=' + namespace)
}
markRead = function(link) {
sendMessage('/links/mark_read?links=' + encodeURIComponent(JSON.stringify([link])));
document.getElementById(link).style.display = 'none';
}
update_links = function(link) {
var link_list = document.getElementById('links');
link_list.innerHTML += "<li id=\""+link.id+"\"><a href=\""+link.url+"\" target=\"_blank\">"+link.url+"</a> from "+link.sender+" <a href=\"#\" onClick=\"markRead("+link.id+");\">[x]</a></li>\n";
}
sendMessage = function(path) {
var xhr = new XMLHttpRequest();
xhr.open('POST', path, true);
xhr.send();
}
var token = '{{ channel_id }}';
var channel = new goog.appengine.Channel(token);
var socket = channel.open();
socket.onopen = function() {
window.setTimeout(function() {sendMessage('/channels/connected/{{device_name}}')}, 100);
}
socket.onmessage = function(evt) {
console.log(evt.data);
var o = JSON.parse(evt.data);
if (o.links) {
for(link in o.links)
update_links(o.links[link]);
}
}
</script>
<h1>{{ device }}</h1>
URL: <input id='link_input' type='text'><br />
Target: <input id="name_input" type="text"><br />
Comment: <textarea id="comment_input"></textarea> <input type="button" onclick='add_link()' value="Add" />
<ul id='links'>
</ul>
</body>
</html>