-
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathprofile.js
More file actions
104 lines (86 loc) · 2.63 KB
/
profile.js
File metadata and controls
104 lines (86 loc) · 2.63 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
'use strict';
GetOption( {
'profile-gamecovers': true,
'profile-calculator': true,
'enhancement-award-popup-url': true,
}, ( items ) =>
{
if( items[ 'enhancement-award-popup-url' ] && window.location.search.includes( 'award' ) )
{
const script = document.createElement( 'script' );
script.id = 'steamdb_profile_award';
script.type = 'text/javascript';
script.src = GetLocalResource( 'scripts/community/profile_award_injected.js' );
document.head.appendChild( script );
}
if( items[ 'profile-gamecovers' ] )
{
const script = document.createElement( 'script' );
script.id = 'steamdb_profile_gamecovers';
script.type = 'text/javascript';
script.dataset.appLogo = GetLocalResource( 'icons/applogo.svg' );
script.src = GetLocalResource( 'scripts/community/profile_gamecovers_injected.js' );
document.head.appendChild( script );
}
if( !items[ 'profile-calculator' ] )
{
return;
}
// Can't access g_rgProfileData inside sandbox :(
let steamID = '';
let isCommunityID = false;
// If we can, use abuseID
/** @type {HTMLInputElement} */
const abuseIDInput = document.querySelector( '#abuseForm > input[name=abuseID]' );
if( abuseIDInput )
{
steamID = abuseIDInput.value;
isCommunityID = true;
}
else
{
// Fallback to url if we can't
steamID = location.pathname.match( /^\/(?:id|profiles)\/([^\s/]+)\/?/ )[ 1 ];
isCommunityID = /^\/profiles/.test( location.pathname );
}
let container = document.querySelector( '#profile_action_dropdown .popup_body' );
let url = GetHomepage() + 'calculator/';
if( isCommunityID )
{
url += `${steamID}/`;
}
else
{
url += `?player=${steamID}`;
}
if( container )
{
const image = document.createElement( 'img' );
image.className = 'steamdb_popup_icon';
image.src = GetLocalResource( 'icons/white.svg' );
const element = document.createElement( 'a' );
element.href = url;
element.className = 'popup_menu_item';
element.appendChild( image );
element.appendChild( document.createTextNode( '\u00a0 ' + _t( 'steamdb_calculator' ) ) );
container.insertBefore( element, null );
}
else
{
container = document.querySelector( '.profile_header_actions' );
if( container )
{
const image = document.createElement( 'img' );
image.src = GetLocalResource( 'icons/white.svg' );
image.className = 'steamdb_self_profile';
const text = document.createElement( 'span' );
text.dataset.tooltipText = _t( 'steamdb_calculator' );
text.appendChild( image );
const element = document.createElement( 'a' );
element.className = 'btn_profile_action btn_medium';
element.href = url;
element.appendChild( text );
container.appendChild( element );
}
}
} );