forked from SteamDatabase/steamdb.info-issues
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSteamDatabase.user.js
More file actions
172 lines (137 loc) · 5.29 KB
/
SteamDatabase.user.js
File metadata and controls
172 lines (137 loc) · 5.29 KB
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
// ==UserScript==
// @version 2.0.1
// @name Steam Database Integration
// @description Adds Steam Database links on Steam Store
// @homepage https://steamdb.info/
// @namespace https://steamdb.info/extension/
// @icon https://steamdb.info/static/logos/256.png
// @match *://store.steampowered.com/app/*
// @match *://store.steampowered.com/sub/*
// @updateURL https://github.com/SteamDatabase/SteamDatabase/raw/master/SteamDatabase.user.js
// @grant none
// ==/UserScript==
//
// This userscript is very stripped down.
// Please check https://steamdb.info/extension/ to see if we have a proper extension for your browser
//
(function()
{
'use strict';
var mainURL = 'https://steamdb.info',
pathName = location.pathname,
element,
container,
SteamDB =
{
CurrentAppID: 0,
RegexAppID: /\/([0-9]{1,6})\/?/,
FindAppID: function( )
{
element = pathName.match( SteamDB.RegexAppID );
if( element )
{
SteamDB.CurrentAppID = element[ 1 ];
}
},
/**
* App store page
*/
InjectStoreApp: function( )
{
container = document.querySelector( '#demo_block' );
if( !container )
{
return;
}
var link = document.createElement( 'a' );
link.className = 'btnv6_blue_hoverfade btn_medium btn_steamdb';
link.target = '_blank';
link.href = mainURL + '/app/' + SteamDB.CurrentAppID + '/';
element = document.createElement( 'span' );
element.dataset.storeTooltip = 'View on Steam Database';
link.appendChild( element );
var image = document.createElement( 'img' );
image.className = 'ico16';
image.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAAh1BMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////9qkf8RAAAALHRSTlMA9av6xf1BBfHZkl9bVzAMz6+mK929a0smIxXj1Zl2ZDwZuLWFfkY3Acefe8hESa8AAADdSURBVBjTPZDZloQgDEQDCgKCCu67vffM8P/fNxFOd70lJ7lVCaCm3P00RMj215Rw6uKYD5rdnc5uAihEbCQv8+LmuM0F0NiRz2yrp55vniLpuTmrTshwXyvmF6jzIgMoTWFsEuY7gD+SKN0/bASQHacX+7g1LFq0nV0GxF8Rk9VG8wGBV8RLzw746mBeQu49W3WdnZN6RUAOoEXAVFUwFBqAC9orSYKbVD0VHFKfAqocxzNtKFMM9/7Q353HFsedSuEJWZGrCrc5wNjGmPGcdowf22naENKkdL9g+Q+kmBjmtA/0IQAAAABJRU5ErkJggg==';
element.appendChild( image );
container.insertBefore( link, 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>' );
}
if( document.querySelector( '.game_area_purchase_game_dropdown_selection' ) )
{
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( '.game_meta_data' );
if( !container )
{
return;
}
element = document.createElement( 'span' );
element.appendChild( document.createTextNode( 'View on Steam Database' ) );
var link = document.createElement( 'a' );
link.className = 'action_btn';
link.target = '_blank';
link.href = mainURL + '/sub/' + SteamDB.CurrentAppID + '/';
link.appendChild( element );
element = document.createElement( 'div' );
element.className = 'block';
element.appendChild( link );
container.insertBefore( element, container.firstChild );
},
/**
* This function is injected into store's app page
*/
InjectAppSubscriptions: function( )
{
var link, original_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 = 'https://steamdb.info/sub/' + subId + '/';
link.innerHTML = 'View on Steam Database <i>(' + subId + ')</i>';
}
catch( e )
{
// Don't break website functionality if something fails above
}
original_dropdownSelectOption( dropdownName, subId, inCart );
};
}
};
SteamDB.FindAppID( );
// 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>' );
}
else if( pathName.match( /^\/app\// ) )
{
SteamDB.InjectStoreApp( );
}
else if( pathName.match( /^\/sub\// ) )
{
SteamDB.InjectStorePackage( );
}
}());