-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.html
103 lines (90 loc) · 3.4 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tab Grenade</title>
<link rel="stylesheet" type="text/css" href="data/pure-nr-min.css">
<link rel="stylesheet" type="text/css" href="data/style.css">
<script src="//www.parsecdn.com/js/parse-1.4.0.min.js"></script>
<script>
Parse.initialize("dibRma54UIQ0UYErXdDV0EPdk32AtUSEBQll0Lc7",
"iwP0ckwxi7g8ZVWVaJwoel61ckdoUbPPuj2OPPXR");
var timeFormat = 'MMMM Do YYYY, h:mm:ss a';
var urlId = window.location.pathname.trim();
urlId = urlId.substr(1, urlId.length)
</script>
<body>
<div class="content">
<div class="header">
<div class="pure-menu pure-menu-open pure-menu-fixed pure-menu-horizontal">
<a class="pure-menu-heading" href="">Tab Grenade</a>
</div>
</div>
<div id="container"></div>
<script>
var TabGroup = Parse.Object.extend("TabGroup");
var query = new Parse.Query(TabGroup);
query.get(urlId, {
success: function(gameScore) {
var tabs = gameScore.attributes.tabs;
var a = document.createElement('a');
var tabsByTime = tabs.reduce(function(prev, curr) {
if (!prev[curr.time])
prev[curr.time] = [];
a.href = curr[1].url;
prev[curr.time].push({
url: curr.url,
title: curr.title,
domain: a.hostname
});
return prev;
}, {});
var sortedKeys = Object.keys(tabsByTime).sort(function(a, b) {
return a - b;
}).reverse();
var container = document.getElementById("container");
var containerFragment = document.createDocumentFragment();
sortedKeys.forEach(function(key) {
var blockFragment = document.createDocumentFragment();
var len = tabsByTime[key].length;
var date = new Date(parseInt(key, 10));
var formattedTime = date.toDateString() + ', ' + date.toTimeString();
var ul = document.createElement('ul');
var h1 = document.createElement('h1');
var info = document.createElement('div');
var createdOn = document.createElement('div');
h1.textContent = len + ( len > 1 ? ' tabs' : ' tab');
info.className = 'info_block';
info.setAttribute('data-id', key);
createdOn.className = 'created_on';
createdOn.textContent = 'Created on ' + formattedTime;
info.appendChild(createdOn);
tabsByTime[key].forEach(function(item) {
var li = document.createElement('li');
var icon = document.createElement('img');
icon.src = 'https://www.google.com/s2/favicons?domain=' + item.domain;
var _a = document.createElement('a');
_a.href = item.url;
_a.target = '_blank';
_a.textContent = item.title;
li.appendChild(icon);
li.appendChild(a);
ul.appendChild(li);
});
blockFragment.appendChild(h1);
blockFragment.appendChild(info);
blockFragment.appendChild(ul);
containerFragment.appendChild(blockFragment);
});
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and description.
document.getElementById("container").textContent =
"There was an error retrieving the tabs :(";
}
});
</script>
</div>
</body>
</html>