/
index.html
669 lines (582 loc) · 20.1 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
$(element).css({
position: 'absolute',
top: (windowHeight - popupHeight) / 2,
left: (windowWidth - popupWidth) / 2,
width: popupWidth,
61
height: popupHeight
62
});
63
} // ui_resize
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
var tutorial_stage = -1;
var tutorial_timer = null;
function end_tutorial_stage()
{
if (tutorial_timer != null)
{
clearTimeout(tutorial_timer);
tutorial_timer = null;
} // if
if (tutorial_stage >= 0)
$('div#tutorial' + tutorial_stage).fadeOut('slow');
} // end_tutorial_stage
function tutorial()
{
end_tutorial_stage();
tutorial_stage++;
var element = $('div#tutorial' + tutorial_stage);
if (element.length == 0)
return; // ran out of tutorial.
var tut = $('div#tutorial' + tutorial_stage);
var target = $(tut.attr('tutorialtarget'));
var left = target.offset().left + 5;
var window_width = document.documentElement.clientWidth;
if ((left + tut.width()) > window_width)
left = (window_width - tut.width()) - 30;
var top = target.offset().top + target.height() + 5;
var window_height = document.documentElement.clientHeight;
if ((top + tut.height()) > window_height)
top = (window_height - tut.height()) - 30;
tut.css({ position: 'absolute', top: top, left: left });
tut.fadeIn('slow');
tutorial_timer = setTimeout('tutorial();', tut.attr('tutorialtimeout'));
} // tutorial
function halt_tutorial()
{
end_tutorial_stage();
tutorial_stage = -1;
} // halt_tutorial
function restart_tutorial()
{
halt_tutorial();
tutorial();
} // restart_tutorial
118
119
function render()
{
120
121
122
123
if (profile == null)
return;
$('img.avatar').attr('src', profile.avatarurl_medium);
124
$('div.nickname').text(profile.nickname);
125
126
127
var gameidx;
for (gameidx in profile.gamelist)
128
{
129
var game = profile.gamelist[gameidx];
130
131
var html = "<tr class='gamerow' profilegameidx='" + gameidx + "'>" +
"<td class='gamecell'>" +
132
"<a href='steam://run/" + game.appid + "'>" +
133
"<img width='123' height='45' src='" + game.logourl + "'/>" +
134
135
"</a><td class='gamecell'>" +
"<h4>" + game.title + "</h4><div class='tagline'>Tags:" +
136
"<div class='taglist' profilegameidx=" + gameidx + ">";
137
138
139
140
141
142
143
144
145
if (game.tags.length == 0)
html += ' (none)';
else
{
var tagidx;
for (tagidx in game.tags)
html += " " + game.tags[tagidx];
} // else
146
html += "</div></div></td></tr>";
147
148
$('table.gametable > tbody:last').append(html);
149
} // for
150
151
152
153
154
$('tr.gamerow').each(function() {
profile.gamelist[$(this).attr('profilegameidx')].element = $(this);
});
155
$('div.taglist').one("click", function() { clicked_taglist($(this)); });
156
$('a#profileurl').attr('href', profile.profileurl);
157
158
$('div.main').show();
end_popover();
159
160
161
162
163
164
165
166
167
168
var has_tags = false;
for (var i in profile.tagmap)
{
has_tags = true;
break;
} // for
if (!has_tags)
restart_tutorial();
169
} // render
170
171
172
173
function process_steam_profile(xml)
{
var prof = $(xml).find('profile');
174
175
var steamid = prof.find('steamid').text();
if (steamid == '0')
176
{
177
popover('#loginpopover');
178
179
180
return null;
} // if
181
182
183
184
185
186
187
if (prof.find('valid').text() == '0')
{
popover('#loginfailurepopover');
return null;
} // if
if (prof.find('private').text() == '1')
188
189
190
191
{
var url = 'http://steamcommunity.com/profiles/' + steamid + '/edit/settings';
$('a#privpage').attr('href', url);
popover('#privateprofilepopover');
192
return null;
193
} // if
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
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(),
215
filter: '',
216
tagmap: new Object()
217
218
219
220
221
}
prof.find('weblink').each(function(){
retval['weblinks'].push({
title: $(this).find('title').text(),
222
url: $(this).find('url').text()
223
224
225
226
});
})
prof.find('game').each(function(){
227
var game = {
228
229
230
231
appid: $(this).find('appid').text(),
title: $(this).find('title').text(),
logourl: $(this).find('logourl').text(),
storeurl: $(this).find('storeurl').text(),
232
tagmatchcount: 0,
233
element: null,
234
tags: new Array
235
236
237
};
$(this).find('tag').each(function(){
238
239
240
241
242
var t = $(this).text().toLowerCase();
game.tags.push(t);
if (retval.tagmap[t] == null)
retval.tagmap[t] = new Array();
retval.tagmap[t].push(game);
243
});
244
245
246
retval['gamelist'].push(game);
});
247
248
249
250
251
252
253
if (retval['gamelist'].length == 0)
{
popover('#noappspopover');
return null;
} // if
254
255
256
return retval;
} // process_steam_profile
257
var run_filter_timer = null;
258
259
260
function run_filter()
{
// stop any pending filter runs.
261
262
clearTimeout(run_filter_timer);
run_filter_timer = null;
263
264
265
266
267
268
269
270
271
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();
272
filter = filter.replace(/^\s*|\s*$/g, '');
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
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];
304
game.tagmatchcount++;
305
306
307
308
309
310
311
} // 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];
312
if (game.tagmatchcount != filtertags.length)
313
314
315
game.element.hide();
else
game.element.show();
316
game.tagmatchcount = 0; // reset this for next time.
317
318
} // for
} // run_filter
319
320
function focus_filter_textbox()
321
{
322
// blank out the filter textbox when focused if it has default text.
323
324
325
326
327
328
var widget = $('input.tagfilter');
if (widget && !widget.attr('filter_cleared'))
{
widget.attr('filter_cleared', true);
widget.val('');
} // if
329
330
} // focus_filter_textbox
331
function typing_in_filter()
332
333
334
{
// we only update the filter when it's been more than X ms, in case the
// list is massive.
335
336
if (run_filter_timer != null)
clearTimeout(run_filter_timer);
337
run_filter_timer = setTimeout('run_filter();', 50);
338
} // typing_in_filter
339
340
341
342
function save_tags(appid, tagstr)
{
// we only allow a-z, 0-9, and spaces. So URI encode the spaces.
343
var tagstrurl = tagstr.replace(/ /g, '%20');
344
345
346
347
348
349
350
351
352
353
354
355
356
357
$.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;
358
359
360
361
362
363
364
365
366
367
368
369
// !!! 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
370
371
372
373
374
375
376
if (game == null)
return;
var element = game.element.find('div.taglist');
if (element == null)
return;
377
// !!! FIXME: get this from the stylesheet
378
379
element.css('color', '#FFFFFF');
element.one("click", function() { clicked_taglist($(this)); });
380
}
381
382
383
});
} // save_tags
384
function process_tag_edit(element, tagstr)
385
{
386
tagstr = tagstr.toLowerCase();
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
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.
442
save_tags(game.appid, tagstr);
443
444
445
446
447
// Kill the text input widget, go back to regular text.
if (tagstr == '')
tagstr = '(none)';
parentdiv.html(' ' + tagstr);
448
// !!! FIXME: get this from the stylesheet
449
parentdiv.css('color', '#777777');
450
451
452
453
454
455
456
457
458
459
460
461
} // 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 = '';
462
463
464
var html = "<input type='text' autocapitalize='off' size='100'" +
" class='tagedit' name='tagedit'" +
" value='" + tagstr + "'/>";
465
466
467
element.html(html);
editor = $("input.tagedit");
468
469
470
471
472
473
474
475
476
477
478
479
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);
});
480
481
editor.focus();
} // clicked_taglist
482
483
484
// kick off AJAX load of user profile when document is ready for action.
$(document).ready(function(){
485
486
487
488
489
$(window).resize( function() { ui_resize(); } );
// Mobile Safari (etc?) orientation support.
window.onorientationchange = function() { ui_resize(); }
490
popover('#loadingmessage');
491
492
493
494
$.ajax({
type: "GET",
url: "steamprofile.php",
dataType: "xml",
495
error: function() { popover('#loginfailurepopover'); },
496
497
498
success: function(xml) {
profile = process_steam_profile(xml);
render();
499
}
500
501
});
});
502
503
504
505
506
-->
</script>
</head>
<body>
507
<div class='main'>
508
509
510
<div class="global_header">
<img class='avatar' width='64' height='64' src='loading.gif'/>
<div class='nickname'></div>
511
512
<div class='controls'>
<div class='searchbox'>
513
514
<input type='text' autocapitalize='off'
class='tagfilter' name='filter'
515
516
517
518
519
520
521
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'>
522
<center>
523
[
524
<a href='javascript:restart_tutorial();'>help</a>
525
526
527
528
529
-
<a target='_blank' href='http://hg.icculus.org/icculus/steamtags'>source code</a>
-
<a target='_blank' id='profileurl' href='xxx'>profile</a>
-
530
531
<a href='mailto:icculus@icculus.org?subject=Steam%20Tags%20Feedback'>feedback</a>
-
532
533
<a href='auth.php?logout=1'>logout</a>
]
534
535
536
<br/>
[ <a target='_blank' href='http://steampowered.com/'> Powered by Steam</a> ]
</center>
537
</div>
538
</div>
539
</div>
540
541
<table class='gametable'><tbody></tbody></table>
<div class="global_footer"></div>
542
</div>
543
544
<div id='loadingmessage'>
545
<center>Loading your Steam Community profile...</center>
546
547
</div>
548
<div class='popover' id='loginpopover'>
549
<center>
550
<p>This website lets you organize and filter your Steam purchases
551
552
through tags you choose. You can categorize and file your games
thousands of different ways.</p>
553
554
555
556
557
<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/>
558
559
560
<p><a href='auth.php'>
Click here to log in through steamcommunity.com</a></p>
</center>
561
</div>
562
563
<div class='popover' id='loginfailurepopover'>
564
<center>
565
566
567
<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>
568
569
<p>If this problem persists, feel free to
<a href='mailto:icculus@icculus.org'>ask Ryan about it</a>.</p>
570
<br/>
571
<p><a href='http://store.steampowered.com/'>
572
Click here to shop for games on Steam in the meantime.</a></p>
573
</center>
574
575
</div>
576
<div class='popover' id='privateprofilepopover'>
577
<center>
578
579
580
581
582
583
584
<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/>
585
<p><a id='privpage' href='xxx'>
586
Click here to go to your steamcommunity.com settings.</a></p>
587
</center>
588
589
</div>
590
<div class='popover' id='noappspopover'>
591
<center>
592
593
594
595
596
<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/>
597
<p><a href='http://store.steampowered.com'>
598
Click here to go shopping!</a></p>
599
</center>
600
601
</div>
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
<div class='tutorial' id='tutorial0'
tutorialtarget='div.taglist:first' tutorialtimeout='15000'>
<center>
<p>Click a game's tags, and then you can edit them.</p>
<br/>
<p>Just type in some simple words, separated with spaces. Describe
the game.</p>
<br/>
<p>If this game were <a target='_blank' href='http://store.steampowered.com/app/26800'>Braid</a>, you might type in:</p>
<p><code>platformer indie puzzle steamplay</code></p>
<p>Or <a target='_blank' href='http://store.steampowered.com/app/1250'>Killing Floor</a> might be:</p>
<p><code>fps multiplayer zombies</code></p>
<br/>
<p>Use any words you like to describe the game. You'll be able to
find this game later through these words.</p>
<br/>
<p>When you're done, just click elsewhere to save.</p>
</center>
</div>
<div class='tutorial' id='tutorial1'
tutorialtarget='div.searchbox' tutorialtimeout='10000'>
<center>
625
<p>Next, type in some tags up here.</p>
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
<br/>
<p>The list of games will filter down to exactly match the tags you
typed, as you type them.</p>
<p>Now you can find your games based on arbitrary criteria you choose!</p>
</center>
</div>
<div class='tutorial' id='tutorial2'
tutorialtarget='td.gamecell > a > img:first' tutorialtimeout='8000'>
<center>
<p>Click a game's icon to launch it.</p>
<br/>
<p>This will tell the Steam client to install and run the game.</p>
<p>You'll need to have Steam installed for this to work.</p>
</center>
</div>
<div class='tutorial' id='tutorial3'
tutorialtarget='img.avatar' tutorialtimeout='3000'>
<center>
This is you. A beautiful and unique snowflake.
</center>
</div>
<div class='tutorial' id='tutorial4'
tutorialtarget='div.navbar' tutorialtimeout='10000'>
<center>
<p>Here are some various useful links.</p>
<br/>
<p>Definitely consider clicking the 'feedback' one and telling Ryan
what you think. Javascript hacker? Grab the source code. Bored?
Buy something ('Powered by Steam'). Done? Logout.</p>
<br/>
<p>Clicking 'help' reruns this tutorial.</p>
</center>
<br/>
<p align='right'>Have fun!</p>
<p align='right'>--ryan.</p>
</div>
666
<div id='backgroundpopover'></div>
667
668
</body>
</html>