This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
thing.html
240 lines (218 loc) · 6.56 KB
/
thing.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<!DOCTYPE html>
<html>
<head>
<style rel="stylesheet" type="text/css">
body {
width: 100%;
overflow: hidden;
}
body, * {
margin: 0;
padding: 0;
font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
line-height: 1.28;
font-size: 11px;
color: #666;
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
#wrapper {
background: white;
border: 1px solid #ccc;
}
.user {
display: inline-block;
width: 50px;
height: 70px;
margin-right: 5px;
vertical-align: top;
text-align: center;
overflow: hidden;
}
.user:nth-child(5n) {
margin-right: 0;
}
.user img {
background: #ccc;
width: 48px;
height: 48px;
margin-right: 5px;
}
.user span {
font-size: 9px;
}
.section {
margin: 10px;
}
.section.header {
margin: 0;
padding-bottom: 10px;
padding: 10px;
background: rgb(249, 248, 238);
border-bottom: 1px solid rgb(239, 235, 224);
}
.section.header span {
font-size: 14px;
font-weight: bold;
}
.section.top .title-and-button {
margin-left: 5px;
vertical-align: top;
display: inline-block;
max-width: 219px;
}
.section.top .title {
display: block;
font-weight: bold;
font-size: 16px;
}
.section.top .logo {
border: 1px solid #ccc;
display: inline-block;
vertical-align: top;
}
.section.top .logo img {
vertical-align: top;
}
.section.top .logo:hover {
text-decoration: none;
}
.section.people p {
margin-bottom: 5px;
}
.section.people {
min-height: 100px;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
padding-top: 5px;
}
.section.footer a {
padding-left: 20px;
background: url(http://flattr.com/_img/favicon.ico) no-repeat center left;
display: block;
line-height: 16px;
}
</style>
</head>
<body>
<div id="wrapper">
<div class="section header">
<span>Support with microdonations</span>
</div>
<div class="section top">
<a class="logo" href="#" target="_blank">
</a>
<div class="title-and-button">
<a class="title" href="#" target="_blank"></a>
<a class="FlattrButton" rev="flattr;button:compact" href="#"></a>
</div>
</div>
<div class="section people">
<p class="flattrs_user_count">
</p>
<ul>
</ul>
</div>
<div class="section footer">
<a href="https://flattr.com/" target="_blank">Flattr - Social microdonations</a>
</div>
</div>
<script type="text/javascript">
var showHeader = location.href.indexOf('noheader') === -1;
if (!showHeader) {
document.querySelector('.section.header').style.display = 'none';
}
function injectFlattrScript() {
var s = document.createElement('script');
var t = document.getElementsByTagName('script')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://api.flattr.com/js/0.6/load.js?mode=auto&popout=0';
t.parentNode.insertBefore(s, t);
}
function extractThingIdFromUrl(url) {
var matches = url.match('thing=([0-9]*)');
var ret = false;
if (matches && matches.length === 2) {
ret = matches[1];
}
return ret;
}
var thingId = extractThingIdFromUrl(location.href);
var xhr = new XMLHttpRequest();
var url = 'https://api.flattr.com/rest/v2/things/' + thingId + '?full';
xhr.open('GET', url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200 || xhr.status == 304) {
var response = JSON.parse(xhr.responseText);
document.querySelector('.top .title').innerHTML = response.title;
document.querySelector('.top .title').setAttribute('href', response.link);
document.querySelector('.top .logo').setAttribute('href', response.link);
document.querySelector('.top .FlattrButton').setAttribute('href', response['url']);
var img = document.createElement('img');
img.setAttribute('width', '40');
img.setAttribute('height', '40');
img.setAttribute('src', response.image);
document.querySelector('.top .logo').appendChild(img);
switch (response.flattrs_user_count) {
case 0:
document.querySelector('.flattrs_user_count').innerHTML = 'Be the first one to donate to <strong>' + response.title + '</strong>';
break;
case 1:
document.querySelector('.flattrs_user_count').innerHTML = '<strong>' + response.flattrs_user_count + '</strong> person has donated to <strong>' + response.title + '</strong>';
break;
default:
document.querySelector('.flattrs_user_count').innerHTML = '<strong>' + response.flattrs_user_count + '</strong> people have donated to <strong>' + response.title + '</strong>';
break;
}
injectFlattrScript();
loadLatestSupporters(thingId);
}
};
xhr.send();
function createUserHtml(user) {
var a = document.createElement('a');
var img = document.createElement('img');
var username = document.createElement('span');
a.setAttribute('href', user.link);
a.setAttribute('target', '_blank');
a.setAttribute('class', 'user');
img.setAttribute('src', user.avatar);
username.innerHTML = user.firstname || user.username;
a.appendChild(img);
a.appendChild(username);
return a;
}
function loadLatestSupporters(thingId) {
var xhr = new XMLHttpRequest();
var url = 'https://api.flattr.com/rest/v2/things/' + thingId + '/flattrs?full';
xhr.open('GET', url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200 || xhr.status == 304) {
var response = JSON.parse(xhr.responseText);
var i = 0;
var user;
var fragment = document.createDocumentFragment();
var addedUsers = 0;
for (i = 0; i < response.length; i += 1) {
user = response[i]['owner'];
if (user.avatar) {
fragment.appendChild(createUserHtml(user));
addedUsers += 1;
if (addedUsers === 15) {
break;
}
}
}
document.querySelector('.section.people ul').appendChild(fragment);
}
};
xhr.send();
}
</script>
</body>
</html>