/
index.html
538 lines (468 loc) · 16 KB
1
2
3
<!doctype html>
<html>
<head>
4
<title>Steam Tags</title>
5
<link href="style.css" rel="stylesheet" type="text/css" />
6
7
8
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
<!--
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var profile = null; // all the user state.
var current_popover = null;
function end_popover()
{
if (current_popover != null)
{
$(current_popover).fadeOut("slow");
$("#backgroundpopover").fadeOut("slow");
current_popover = null;
} // if
} // end_popover
function popover(element)
{
if (current_popover != null)
$(current_popover).fadeOut("slow");
current_popover = element;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
ui_resize(); // make this sane.
$("#backgroundpopover").css('opacity', '0.7');
$("#backgroundpopover").fadeIn('slow');
$(element).fadeIn('slow');
// I guess this doesn't actually recalculate the element sizes until the
// scripts are idle, so do a short timeout so it rechecks this after
// the layout has a chance to catchup.
setTimeout('ui_resize();', 10);
} // popover
function ui_resize()
{
var element = current_popover;
if (element == null)
return;
$('#backgroundpopover').css('height', windowHeight);
48
49
50
51
52
53
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var popupWidth = windowWidth / 2;
$(element).css('width', popupWidth);
54
var popupHeight = $(element).children().height();
55
56
57
58
59
60
61
62
$(element).css({
position: 'absolute',
top: (windowHeight - popupHeight) / 2,
left: (windowWidth - popupWidth) / 2,
width: popupWidth,
height: popupHeight,
});
63
} // ui_resize
64
65
66
function render()
{
67
68
69
70
if (profile == null)
return;
$('img.avatar').attr('src', profile.avatarurl_medium);
71
$('div.nickname').text(profile.nickname);
72
73
74
var gameidx;
for (gameidx in profile.gamelist)
75
{
76
var game = profile.gamelist[gameidx];
77
78
var html = "<tr class='gamerow' profilegameidx='" + gameidx + "'>" +
"<td class='gamecell'>" +
79
"<img width='123' height='45' src='" + game.logourl + "'/>" +
80
"<td class='gamecell'>" +
81
82
83
"<h4><a href='steam://run/" + game.appid + "'>" +
game.title + "</a></h4><div class='tagline'>Tags:" +
"<div class='taglist' profilegameidx=" + gameidx + ">";
84
85
86
87
88
89
90
91
92
if (game.tags.length == 0)
html += ' (none)';
else
{
var tagidx;
for (tagidx in game.tags)
html += " " + game.tags[tagidx];
} // else
93
html += "</div></div></td></tr>";
94
95
$('table.gametable > tbody:last').append(html);
96
} // for
97
98
99
100
101
$('tr.gamerow').each(function() {
profile.gamelist[$(this).attr('profilegameidx')].element = $(this);
});
102
$('div.taglist').one("click", function() { clicked_taglist($(this)); });
103
$('a#profileurl').attr('href', profile.profileurl);
104
105
106
$('div.main').show();
end_popover();
} // render
107
108
109
110
function process_steam_profile(xml)
{
var prof = $(xml).find('profile');
111
112
var steamid = prof.find('steamid').text();
if (steamid == '0')
113
{
114
popover('#loginpopover');
115
116
117
return null;
} // if
118
119
120
121
122
123
124
if (prof.find('valid').text() == '0')
{
popover('#loginfailurepopover');
return null;
} // if
if (prof.find('private').text() == '1')
125
126
127
128
{
var url = 'http://steamcommunity.com/profiles/' + steamid + '/edit/settings';
$('a#privpage').attr('href', url);
popover('#privateprofilepopover');
129
return null;
130
} // if
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
var retval = {
nickname: prof.find('nickname').text(),
steamid: prof.find('steamid').text(),
name: prof.find('name').text(),
profileurl: prof.find('profileurl').text(),
onlinestate: prof.find('onlinestate').text(),
statemsg: prof.find('statemsg').text(),
avatarurl_small: prof.find('avatarurl_small').text(),
avatarurl_medium: prof.find('avatarurl_medium').text(),
avatarurl_large: prof.find('avatarurl_large').text(),
vacbanned: (prof.find('vacbanned').text() != '0'),
membersince: prof.find('membersince').text(),
rating: prof.find('rating').text(),
hoursplayed_2weeks: prof.find('hoursplayed_2weeks').text(),
headline: prof.find('headline').text(),
location: prof.find('location').text(),
realname: prof.find('realname').text(),
summary: prof.find('summary').text(),
weblinks: new Array(),
gamelist: new Array(),
152
153
filter: '',
tagmap: new Object(),
154
155
156
157
158
159
160
161
162
163
}
prof.find('weblink').each(function(){
retval['weblinks'].push({
title: $(this).find('title').text(),
url: $(this).find('url').text(),
});
})
prof.find('game').each(function(){
164
var game = {
165
166
167
168
appid: $(this).find('appid').text(),
title: $(this).find('title').text(),
logourl: $(this).find('logourl').text(),
storeurl: $(this).find('storeurl').text(),
169
tagmatchcount: 0,
170
element: null,
171
172
173
174
tags: new Array,
};
$(this).find('tag').each(function(){
175
176
177
178
179
var t = $(this).text().toLowerCase();
game.tags.push(t);
if (retval.tagmap[t] == null)
retval.tagmap[t] = new Array();
retval.tagmap[t].push(game);
180
});
181
182
183
retval['gamelist'].push(game);
});
184
185
186
187
188
189
190
if (retval['gamelist'].length == 0)
{
popover('#noappspopover');
return null;
} // if
191
192
193
return retval;
} // process_steam_profile
194
var run_filter_timer = null;
195
196
197
function run_filter()
{
// stop any pending filter runs.
198
199
clearTimeout(run_filter_timer);
run_filter_timer = null;
200
201
202
203
204
205
206
207
208
var filter = '';
var widget = $('input.tagfilter');
// ignore text in box if we haven't focused it yet.
if (widget && widget.attr('filter_cleared'))
filter = widget.val();
filter = filter.toLowerCase();
209
filter = filter.replace(/^\s*|\s*$/g, '');
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
if (profile.filter == filter)
return; // fast path: nothing's changed.
profile.filter = filter;
// fast path: can we just show everything?
if (filter == '') // just show everything.
{
$('tr.gamerow').show();
return;
} // if
var filtertags = filter.split(' ');
for (var t in filtertags)
{
// fast path: can we just hide everything?
if (profile.tagmap[filtertags[t]] == null)
{
$('tr.gamerow').hide(); // no rows match this tag.
return;
} // if
} // for
for (var t in filtertags)
{
var tag = filtertags[t];
for (var i in profile.tagmap[tag])
{
var game = profile.tagmap[tag][i];
241
game.tagmatchcount++;
242
243
244
245
246
247
248
} // for
} // for
// okay, now we have a list of games that should be filtered.
for (var i in profile.gamelist)
{
var game = profile.gamelist[i];
249
if (game.tagmatchcount != filtertags.length)
250
251
252
game.element.hide();
else
game.element.show();
253
game.tagmatchcount = 0; // reset this for next time.
254
255
} // for
} // run_filter
256
257
function focus_filter_textbox()
258
{
259
// blank out the filter textbox when focused if it has default text.
260
261
262
263
264
265
var widget = $('input.tagfilter');
if (widget && !widget.attr('filter_cleared'))
{
widget.attr('filter_cleared', true);
widget.val('');
} // if
266
267
} // focus_filter_textbox
268
function typing_in_filter()
269
270
271
{
// we only update the filter when it's been more than X ms, in case the
// list is massive.
272
273
if (run_filter_timer != null)
clearTimeout(run_filter_timer);
274
run_filter_timer = setTimeout('run_filter();', 50);
275
} // typing_in_filter
276
277
278
279
function save_tags(appid, tagstr)
{
// we only allow a-z, 0-9, and spaces. So URI encode the spaces.
280
var tagstrurl = tagstr.replace(/ /g, '%20');
281
282
283
284
285
286
287
288
289
290
291
292
293
294
$.ajax({
type: 'GET',
url: 'savetags.php?appid=' + appid + '&tags=' + tagstrurl,
dataType: "xml",
success: function(xml) {
// !!! FIXME: we leave the tags dead if this fails for any reason.
var resxml = $(xml).find('result');
if ((resxml == null) || (resxml.text() != '1'))
return;
var appidxml = $(xml).find('appid');
if (appidxml == null)
return;
295
296
297
298
299
300
301
302
303
304
305
306
// !!! FIXME: we can just upvalue here, right? Why iterate?
var appid = appidxml.text();
var game = null;
for (var i in profile.gamelist)
{
if (profile.gamelist[i].appid == appid)
{
game = profile.gamelist[i];
break;
} // if
} // for
307
308
309
310
311
312
313
if (game == null)
return;
var element = game.element.find('div.taglist');
if (element == null)
return;
314
// !!! FIXME: get this from the stylesheet
315
316
317
318
319
320
element.css('color', '#FFFFFF');
element.one("click", function() { clicked_taglist($(this)); });
},
});
} // save_tags
321
function process_tag_edit(element, tagstr)
322
{
323
tagstr = tagstr.toLowerCase();
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
tagstr = tagstr.replace(/^\s*|\s*$/g, '');
tagstr = tagstr.replace(/\s+/g, ' ');
tagstr = tagstr.replace(/[^a-z0-9 ]/g, '');
// remove duplicate tags...
var dupetags = tagstr.split(' ');
var tags = new Array();
for (var i in dupetags)
{
var dupe = false;
for (var j in tags)
{
if (dupetags[i] == tags[j])
{
dupe = true;
break;
} // if
} // for
if (!dupe)
tags.push(dupetags[i]);
} // for
tagstr = tags.join(' ');
// update profile.gamelist[gameidx].tags and profile.tagmap...
var parentdiv = element.parent();
var gameidx = parentdiv.attr('profilegameidx');
var game = profile.gamelist[gameidx];
for (var i in game.tags)
{
var t = game.tags[i];
var gamelist = profile.tagmap[t];
for (var j = 0; j < gamelist.length; j++)
{
if (gamelist[j] == game)
{
gamelist.splice(j, 1);
j--;
} // if
} // for
if (gamelist.length == 0)
profile.tagmap[t] = null;
} // for
for (var i in tags)
{
var t = tags[i];
if (profile.tagmap[t] == null)
profile.tagmap[t] = new Array();
profile.tagmap[t].push(game);
} // for
game.tags = tags;
// Push the updated tags back to the server for storage.
379
save_tags(game.appid, tagstr);
380
381
382
383
384
// Kill the text input widget, go back to regular text.
if (tagstr == '')
tagstr = '(none)';
parentdiv.html(' ' + tagstr);
385
// !!! FIXME: get this from the stylesheet
386
parentdiv.css('color', '#777777');
387
388
389
390
391
392
393
394
395
396
397
398
} // process_tag_edit
function clicked_taglist(element)
{
var editor = $("input.tagedit");
if (editor)
editor.blur(); // that should kill it.
var tagstr = element.text().replace(/^\s*|\s*$/g, '');
if (tagstr == '(none)')
tagstr = '';
399
var html = "<input size='100' class='tagedit' name='tagedit' type='text'" +
400
"value='" + tagstr + "' autocomplete='off'/>";
401
402
403
element.html(html);
editor = $("input.tagedit");
404
405
406
407
408
409
410
411
412
413
414
415
editor.blur(function() { process_tag_edit($(this), $(this).val()); });
editor.change(function() { process_tag_edit($(this), $(this).val()); });
editor.keyup(function(e) {
if (e.keyCode != 27)
return;
// revert to original tags on escape.
var parentdiv = $(this).parent();
var gameidx = parentdiv.attr('profilegameidx');
var game = profile.gamelist[gameidx];
var tagstr = game.tags.join(' ');
process_tag_edit($(this), tagstr);
});
416
417
editor.focus();
} // clicked_taglist
418
419
420
// kick off AJAX load of user profile when document is ready for action.
$(document).ready(function(){
421
422
423
424
425
$(window).resize( function() { ui_resize(); } );
// Mobile Safari (etc?) orientation support.
window.onorientationchange = function() { ui_resize(); }
426
popover('#loadingmessage');
427
428
429
430
$.ajax({
type: "GET",
url: "steamprofile.php",
dataType: "xml",
431
error: function() { popover('#loginfailurepopover'); },
432
433
434
435
436
437
success: function(xml) {
profile = process_steam_profile(xml);
render();
},
});
});
438
439
440
441
442
-->
</script>
</head>
<body>
443
<div class='main'>
444
445
446
<div class="global_header">
<img class='avatar' width='64' height='64' src='loading.gif'/>
<div class='nickname'></div>
447
448
449
450
451
452
453
454
455
456
<div class='controls'>
<div class='searchbox'>
<input class='tagfilter' name='filter' type='text'
onFocus='focus_filter_textbox();'
onBlur='run_filter();'
onChange='run_filter();'
onKeyDown='typing_in_filter();'
value='Enter filter tags' size='22' autocomplete='off'/>
</div>
<div class='navbar'>
457
<center>
458
459
460
461
462
463
464
465
466
[
<a target='_blank' href='http://store.steampowered.com/'>buy games</a>
-
<a target='_blank' href='http://hg.icculus.org/icculus/steamtags'>source code</a>
-
<a target='_blank' id='profileurl' href='xxx'>profile</a>
-
<a href='auth.php?logout=1'>logout</a>
]
467
468
469
<br/>
[ <a target='_blank' href='http://steampowered.com/'> Powered by Steam</a> ]
</center>
470
</div>
471
</div>
472
</div>
473
474
<table class='gametable'><tbody></tbody></table>
<div class="global_footer"></div>
475
</div>
476
477
<div id='loadingmessage'>
478
<center>Loading your Steam Community profile...</center>
479
480
</div>
481
<div class='popover' id='loginpopover'>
482
<center>
483
<p>This website lets you organize and filter your Steam purchases
484
485
through tags you choose. You can categorize and file your games
thousands of different ways.</p>
486
487
488
489
490
<br/>
<p>You need to log in to Steam Community to access this page.</p>
<p>Your password will only be supplied to the Steam website. This
website will never have access to your login information.</p>
<br/>
491
492
493
<p><a href='auth.php'>
Click here to log in through steamcommunity.com</a></p>
</center>
494
</div>
495
496
<div class='popover' id='loginfailurepopover'>
497
<center>
498
499
500
<p>We're having trouble accessing your Steam Community profile.</p>
<br/>
<p>This is probably a temporary network glitch. Please try again later.</p>
501
502
<p>If this problem persists, feel free to
<a href='mailto:icculus@icculus.org'>ask Ryan about it</a>.</p>
503
<br/>
504
<p><a href='http://store.steampowered.com/'>
505
Click here to shop for games on Steam in the meantime.</a></p>
506
</center>
507
508
</div>
509
<div class='popover' id='privateprofilepopover'>
510
<center>
511
512
513
514
515
516
517
<p>Your Steam Community profile appears to be set to private.</p>
<br/>
<p>You need to change your Steam Community settings to access this page.</p>
<p>The "profile status" must be set to "public."</p>
<p>Please note that this will let everyone see your information!</p>
<p>Unfortunately, it's the only way this site can see it, too.</p>
<br/>
518
<p><a id='privpage' href='xxx'>
519
Click here to go to your steamcommunity.com settings.</a></p>
520
</center>
521
522
</div>
523
<div class='popover' id='noappspopover'>
524
<center>
525
526
527
528
529
<p>You don't seem to own any games!</p>
<br/>
<p>This website isn't very useful if you don't have something to
organize.</p>
<br/>
530
<p><a href='http://store.steampowered.com'>
531
Click here to go shopping!</a></p>
532
</center>
533
534
</div>
535
<div id='backgroundpopover'></div>
536
537
</body>
</html>