forked from SteamDatabase/steamdb.info-issues
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSteamDatabase.user.js
442 lines (362 loc) · 13.3 KB
/
SteamDatabase.user.js
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
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
379
380
381
382
383
384
385
386
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
442
// ==UserScript==
// @version 1.6.5
// @name Steam Database Integration
// @description Adds Steam Database link across Steam Community and Store
// @homepage http://steamdb.info
// @namespace http://steamdb.info/userscript/
// @icon http://steamdb.info/static/logo_144px.png
// @match http://store.steampowered.com/app/*
// @match http://store.steampowered.com/sub/*
// @match http://store.steampowered.com/video/*
// @match http://steamcommunity.com/app/*
// @match http://steamcommunity.com/games/*
// @match http://steamcommunity.com/id/*
// @match http://steamcommunity.com/profiles/*
// @match http://steamcommunity.com/sharedfiles/filedetails*
// @match http://steamcommunity.com/workshop/browse*
// @match http://steamcommunity.com/workshop/discussions*
// @updateURL https://github.com/SteamDatabase/SteamDatabase/raw/master/SteamDatabase.user.js
// ==/UserScript==
var mainURL = 'http://steamdb.info',
pathName = location.pathname,
element,
container,
IMAGE_PROFILE = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAACTElEQVR42p2UO2hTURjHr/XRQCtSWnyAOBWEVumQRXBSqTiUOqiL6CBZBCedpEtAhEJXoUPERbDo0slSUDSWFBQMQiSQ182TvG8Sktw8m3t7/J2QDKGxtl748f/O97rnfPdwFeUfjxDiDFyuVquTyv88FI92Op2bpmm+gi/YDsMwbuMfP3ATiq7BN9AoNkH0tITvZ6vVkg2PDS0ul8sTzWbzRrvd/gw7IPaD3O+NRuMuDafgiJLNZsfq9foizg1o8jZxCNo0/Eq9Tc5iBMOq6/omKg6JUavVXGzg6sDxaDYL65VKRUMNvpQYgkmsyCi20Ov7fq1CoTBP4goNg2CCkOBLoqulUmkhGo1aBgrtdvuI1+s9QfB+sVh8nc/nbTSzuN3u4xRN03QJ/za6jM7I2LD87rA1TXtBYhmEhOBv9An+c3KG/Reqqno6l8vdIf6DuAG7oLN+290V3U+xuEeSA9LYspnBS37Bc+xb6FNw9WICu0LuGjyIx+MTA8eU5yYwl06n34CeyWQEuoMWoNlbt+A9WP1+/8k9Q5Zdw+HwhWQyOSkvWCgUOo/tgEQqldIhg/0hkUhcGpaveDyeMZyLsAEqiZ/Qx5FI5CIJR9E51g/Z7RX5AdCz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t0NVWAgEUBdAxUTFAMTDo7o4ZyjFAUcHC/v/f0OV58N5nH+fsT9jGj9QpSSnjVzpp059kGi2ZAQknGbRkz0jKoiU3IimHlvwtSXm0NB5IaqClOSWpiZbahKQaWux7kmy0FO9IKqKlNSaphZbCNUkFtFSHJFXRUr4gqYyWUleKh6Prc/PL4Ug8GjnqOlEJLfVzkupoqXSkHfdiKBAMuIKroVis40QVtFyShpaecrC3vbFkLqyseXZNs+dIaLkiDS19JWH5972bW5bPOjxO9B0JLTekoeWJNLQ8k4aWF9LQMiMNLW+koeWVNLS8k4aWD9LQ8kkaWr5IQ0v7kaS2QUT/9Q1Dy8tw8txFbQAAAABJRU5ErkJggg==';
var SteamDB =
{
CurrentAppID: 0,
RegexAppID: /\/([0-9]{1,6})/g,
FindAppID: function( )
{
element = pathName.match( SteamDB.RegexAppID );
if( element )
{
SteamDB.CurrentAppID = element[ 0 ].substr( 1 );
}
},
/**
* Game hubs
*/
InjectGameHub: function( bSharedFile )
{
container = document.querySelector( '.apphub_OtherSiteInfo' );
if( !container )
{
return;
}
if( bSharedFile )
{
element = document.querySelector( '.apphub_sectionTab' );
if( !element )
{
return;
}
SteamDB.CurrentAppID = element.href.match( SteamDB.RegexAppID )[ 0 ].substring( 1 );
}
element = document.createElement( 'a' );
element.className = 'btn_blue_white_innerfade btn_medium';
element.href = mainURL + '/app/' + SteamDB.CurrentAppID + '/';
element.target = '_blank';
element.innerHTML = '<span>Steam Database</span>';
if( bSharedFile )
{
// Steam piston blocks button, and can't be clicked
element.style.position = 'relative';
element.style.zIndex = 1000;
}
container.insertBefore( element, container.firstChild );
},
/**
* Official game groups
*/
InjectGameGroup: function( )
{
// Some game groups fancy custom urls
if( !SteamDB.CurrentAppID )
{
// Let's try to find game hub link, what possibly could go wrong?
container = document.querySelector( 'a[href*="http://steamcommunity.com/app/"]' );
if( !container )
{
return;
}
SteamDB.CurrentAppID = container.href.match( SteamDB.RegexAppID )[ 0 ].substring( 1 );
}
container = document.querySelector( '#rightActionBlock' );
if( !container )
{
return;
}
element = document.createElement( 'div' );
element.className = 'actionItem';
element.innerHTML = '<div class="actionItemIcon"><img src="' + IMAGE_GROUP + '" width="16" height="16" alt=""></div><a class="linkActionMinor" target="_blank" href="' + mainURL + '/app/' + SteamDB.CurrentAppID + '/">View on Steam Database</a>';
container.insertBefore( element, null );
// While we're here, let's fix this annoyance
element = document.querySelector( '#oggLogo img' );
if( element )
{
element.style.height = '208px';
}
},
/**
* App store page
*/
InjectStoreApp: function( )
{
container = document.querySelector( '#demo_block .block_content_inner' );
if( !container )
{
return;
}
element = document.createElement( 'div' );
element.className = 'demo_area_button';
element.innerHTML = '<a class="game_area_wishlist_btn" target="_blank" href="' + mainURL + '/app/' + SteamDB.CurrentAppID + '/" style="background-image:url(' + IMAGE_STORE + ')">View on Steam Database</a>';
container.insertBefore( element, container.firstChild );
// Find each "add to cart" button
container = document.querySelectorAll( 'input[name="subid"]' );
var i = 0, appid = 0;
for( i = 0; i < container.length; i++ )
{
element = container[ i ];
appid = element.value; // It's subid, but let's reuse things
element = element.parentElement.parentElement;
element.insertAdjacentHTML( 'beforeEnd', '<a class="steamdb_sub_link" target="_blank" href="'+ mainURL + '/sub/' + appid + '/" style="' + ( element.querySelector( '.game_area_purchase_game_dropdown_left_panel' ) ? '' : 'float:left;' ) + 'color:#898A8C">View on Steam Database <i>(' + appid + ')</i></a>' );
}
// While we're here, let's fix this broken url
element = document.querySelector( '.apphub_OtherSiteInfo a' );
if( element && element.href.charAt( 26 ) === '/' )
{
element.href = element.href.replace( /\/\/app\//, '/app/' ) + '/';
}
if( !document.querySelector( '.game_area_purchase_game_dropdown_selection' ) )
{
// There are no dropdowns, so don't bother hooking
return;
}
element = document.createElement( 'script' );
element.id = 'steamdb_dropdown_hook';
element.type = 'text/javascript';
element.appendChild( document.createTextNode( '(' + SteamDB.InjectAppSubscriptions + ')();' ) );
document.head.appendChild( element );
},
/**
* Package store page
*/
InjectStorePackage: function( )
{
container = document.querySelector( '.share' );
if( !container )
{
return;
}
element = document.createElement( 'div' );
element.className = 'demo_area_button';
element.innerHTML = '<a class="game_area_wishlist_btn" target="_blank" href="' + mainURL + '/sub/' + SteamDB.CurrentAppID + '/" style="background-image:url(' + IMAGE_STORE + ')">View on Steam Database</a>';
container.insertBefore( element, container.firstChild );
},
/**
* Trailer/movie store page
*/
InjectStoreVideo: function( )
{
container = document.querySelector( '.game_details .block_content_inner' );
if( !container )
{
return;
}
element = document.createElement( 'div' );
element.innerHTML = '<a class="game_area_wishlist_btn" target="_blank" href="' + mainURL + '/app/' + SteamDB.CurrentAppID + '/" style="background-image:url(' + IMAGE_STORE + ')">View on Steam Database</a>';
container.insertBefore( element, null );
},
/**
* Profile page
*/
InjectProfile: function( )
{
container = document.querySelector( '#profile_action_dropdown .popup_body' );
if( !container )
{
return;
}
// Can't access g_rgProfileData inside sandbox
var steamID = pathName.match( /^\/(id|profiles)\/([^\s/]+)\/?$/ );
if( !steamID )
{
// wtf?
return;
}
element = document.createElement( 'a' );
element.href = mainURL + '/calculator/?player=' + steamID[ 2 ];
element.target = '_blank';
element.className = 'popup_menu_item';
element.innerHTML = '<img src="' + IMAGE_PROFILE + '"> SteamDB Calculator';
container.insertBefore( element, null );
},
/**
* Inventory page
*/
InjectProfileInventory: function( )
{
if( !document.getElementById( 'inventory_link_753' ) )
{
// There is no Steam inventory, so don't bother hooking
return;
}
element = document.createElement( 'script' );
element.id = 'steamdb_inventory_hook';
element.type = 'text/javascript';
element.appendChild( document.createTextNode( '(' + SteamDB.InsaneInventoryHackery + ')();' ) );
document.head.appendChild( element );
},
/**
* This function is injected into DOM
*/
InsaneInventoryHackery: function( )
{
var i, link, SteamDB_Hackery_PopulateActions = window.PopulateActions;
window.PopulateActions = function( elActions, rgActions, item )
{
var foundState = 0;
try
{
if( item.appid == 753 )
{
if( rgActions )
{
for( i = 0; i < rgActions.length; i++ )
{
link = rgActions[ i ];
if( link.steamdb )
{
foundState = 2;
break;
}
else if( link.link && link.link.match( /\.com\/(app|sub)\// ) )
{
foundState = 1;
}
}
if( foundState === 1 )
{
for( i = 0; i < rgActions.length; i++ )
{
link = rgActions[ i ].link;
if( !link )
{
continue;
}
link = link.match( /\.com\/(app|sub)\/([0-9]{1,6})/ );
if( link )
{
rgActions.push( {
steamdb: true,
link: 'http://steamdb.info/' + link[ 1 ] + '/' + link[ 2 ] + '/', // mainURL is not accessible from here
name: 'View on Steam Database'
} );
foundState = 2;
break;
}
}
}
}
else if( !item.actions && item.type === 'Gift' ) // This function gets called with owner_actions too
{
item.actions = rgActions = [ {
steamdb: true,
link: 'http://steamdb.info/search/?a=sub&q=' + encodeURIComponent( item.name ), // mainURL is not accessible from here
name: 'Search on Steam Database'
} ];
foundState = 2;
}
}
}
catch( e )
{
// Don't break website functionality if something fails above
console.log( e );
}
SteamDB_Hackery_PopulateActions( elActions, rgActions, item );
// We want our links to be open in new tab
if( foundState === 2 )
{
link = elActions.querySelector( '.item_action[href^="http://steamdb.info"]' );
if( link )
{
link.target = '_blank';
}
}
};
},
/**
* This function is injected into store's app page
*/
InjectAppSubscriptions: function( )
{
var link, SteamDB_Hackery_dropdownSelectOption = window.dropdownSelectOption;
window.dropdownSelectOption = function( dropdownName, subId, inCart )
{
try
{
link = document.getElementById('add_to_cart_' + dropdownName + '_description_text');
link = link.parentNode.querySelector( '.steamdb_sub_link' );
link.href = 'http://steamdb.info/sub/' + subId + '/';
link.innerHTML = 'View on Steam Database <i>(' + subId + ')</i>';
}
catch( e )
{
// Don't break website functionality if something fails above
}
SteamDB_Hackery_dropdownSelectOption( dropdownName, subId, inCart );
};
}
};
if( location.hostname === 'steamcommunity.com' )
{
if( pathName.match( /^\/app\// ) )
{
SteamDB.FindAppID( );
SteamDB.InjectGameHub( false );
}
else if( pathName.match( /^\/sharedfiles\/filedetails\/?$/ ) || pathName.match( /^\/workshop\/(browse|discussions)\/?/ ) )
{
SteamDB.InjectGameHub( true );
}
else if( pathName.match( /^\/games\// ) )
{
SteamDB.FindAppID( );
SteamDB.InjectGameGroup( );
}
else if( pathName.match( /^\/(id|profiles)\/[^\s/]+\/?$/ ) )
{
SteamDB.InjectProfile( );
}
else if( pathName.match( /^\/(id|profiles)\/[^\s/]+\/inventory/ ) )
{
SteamDB.InjectProfileInventory( );
}
}
else
{
// Did we hit an error page?
container = document.getElementById( 'error_box' );
if( container )
{
container.insertAdjacentHTML( 'beforeEnd', '<br><br><a target="_blank" href="'+ mainURL + '/app/' + SteamDB.CurrentAppID + '/">View on Steam Database</a>' );
return;
}
SteamDB.FindAppID( );
if( pathName.match( /^\/app\// ) )
{
SteamDB.InjectStoreApp( );
}
else if( pathName.match( /^\/sub\// ) )
{
SteamDB.InjectStorePackage( );
}
else if( pathName.match( /^\/video\// ) )
{
SteamDB.InjectStoreVideo( );
}
}