-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapps.htm
94 lines (85 loc) · 3.3 KB
/
apps.htm
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
<!DOCTYPE html>
<html>
<head>
<title>Apps</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
var api = "https://moylgrove-history.azurewebsites.net/api/apps";
var cookedUser = "";
$(function () {
$("#userAgent").text(navigator.userAgent.match(/Android [689]/)?"yes":"no");
$.get(api, function (data, status) {
if (data.length > 0) {
var table = document.createElement("TABLE");
for (var i = 0, t; t = data[i]; i++) {
var row = table.insertRow(-1);
row.insertCell(-1).innerHTML = t.User;
row.insertCell(-1).innerHTML = "<a target='appview' href='" + t.Link + "'>" + t.App + "</a>";
}
$("#appList").empty();
$("#appList").append(table);
}
});
cookedUser = getCookie("user");
if (cookedUser) $("#userName").val(cookedUser);
});
function addItem() {
var link = $("#link").val().trim().replace("/edit", "");
var key = link.match(/\/[^\/]{30,100}/)[0].substring(1);
var s = { PartitionKey: "span1", RowKey: key, user: $("#userName").val().trim(), app: $("#appName").val().trim(), link: link };
if (s.user && s.app && s.link) {
$("button").hide();
var ss = JSON.stringify(s);
$.ajax({
url: api, type: "post", data: ss,
headers: {
'content-type': 'application/json'
},
success: function (data) {
if (!cookedUser) setCookie("user", s.user, 3);
location.reload(true);
}
});
}
}
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
document.cookie = cname + "=" + cvalue + "; expires=" + d.toUTCString();
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
</script>
</head>
<body>
<table>
<tr>
<th>Your name</th>
<th>App name</th>
<th>Link</th>
<th></th>
</tr>
<tr id="inputRow">
<td><input type="text" id="userName" /></td>
<td><input type="text" id="appName" /></td>
<td><input type="text" id="link" /></td>
<td><button onclick="addItem()">+</button></td>
</tr>
</table>
<div id="appList"></div>
<div id="userAgent"></div>
</body>
</html>