@@ -9,6 +9,8 @@ const STYLES_ID = 'niceprice-store-css';
99const SIDEBAR_SEL = 'div.rightcol.game_meta_data' ;
1010const URL_POLL_INTERVAL = 500 ;
1111
12+ const openExt = ( url : string ) => window . open ( `steam://openurl_external/${ url } ` ) ;
13+
1214function ensureStyles ( ) {
1315 if ( document . getElementById ( STYLES_ID ) ) return ;
1416 const el = document . createElement ( 'style' ) ;
@@ -30,8 +32,10 @@ function ensureStyles() {
3032.nps-na { font-size:11px; color:#556b7e; font-style:italic; }
3133.nps-div { height:1px; background:rgba(255,255,255,.06); margin:2px 0; }
3234.nps-ftr { padding:8px 14px; border-top:1px solid rgba(255,255,255,.04); background:rgba(0,0,0,.1); }
33- .nps-ftr a { color:#67c1f5; font-size:11px; text-decoration:none; }
34- .nps-ftr a:hover { color:#fff; }
35+ .nps-ftr a, .nps-link { color:#67c1f5; font-size:11px; text-decoration:none; cursor:pointer; }
36+ .nps-ftr a:hover, .nps-link:hover { color:#fff; }
37+ .nps-row.clickable { cursor:pointer; border-radius:2px; padding:4px 8px; margin:-4px -8px; }
38+ .nps-row.clickable:hover { background:rgba(255,255,255,.06); }
3539.nps-msg { padding:10px 14px; color:#556b7e; font-size:12px; }
3640.nps-msg a { color:#67c1f5; }
3741` ;
@@ -46,8 +50,16 @@ function findRef(sidebar: Element) {
4650 return sidebar . querySelector ( '[id*="steamdb"],[class*="steamdb"]' ) || sidebar . firstChild ;
4751}
4852
49- function priceRow ( icon : string , label : string , value : string , cls : string ) {
50- if ( value ) return `<div class="nps-row"><span class="nps-row-icon">${ icon } </span><span class="nps-row-label">${ label } </span><span class="nps-val ${ cls } ">${ value } </span></div>` ;
53+ function wireClicks ( el : HTMLElement ) {
54+ el . querySelectorAll < HTMLElement > ( '[data-url]' ) . forEach ( d =>
55+ d . addEventListener ( 'click' , ( ) => d . dataset . url && openExt ( d . dataset . url ) )
56+ ) ;
57+ }
58+
59+ function priceRow ( icon : string , label : string , value : string , cls : string , url ?: string ) {
60+ const clickable = url ? ' clickable' : '' ;
61+ const dataUrl = url ? ` data-url="${ url } "` : '' ;
62+ if ( value ) return `<div class="nps-row${ clickable } "${ dataUrl } ><span class="nps-row-icon">${ icon } </span><span class="nps-row-label">${ label } </span><span class="nps-val ${ cls } ">${ value } </span></div>` ;
5163 return `<div class="nps-row"><span class="nps-row-icon">${ icon } </span><span class="nps-row-label">${ label } </span><span class="nps-na">N/A</span></div>` ;
5264}
5365
@@ -70,7 +82,8 @@ async function inject(appId: number) {
7082 if ( ! el ) return ;
7183 if ( resp . error === 'no_api_key' || resp . error === 'invalid_api_key' ) {
7284 const msg = resp . error === 'no_api_key' ? 'API key required' : 'Invalid API key' ;
73- el . innerHTML = `${ header ( false ) } <div class="nps-msg">${ msg } — <a href="https://gg.deals/api/" target="_blank">Get a free key</a></div>` ;
85+ el . innerHTML = `${ header ( false ) } <div class="nps-msg">${ msg } — <span class="nps-link" data-url="https://gg.deals/api/">Get a free key</span></div>` ;
86+ wireClicks ( el ) ;
7487 } else {
7588 const msgEl = el . querySelector ( '.nps-msg' ) ;
7689 if ( msgEl ) msgEl . textContent = resp . error === 'rate_limited' ? 'Rate limited' : 'Could not load' ;
@@ -94,8 +107,8 @@ async function inject(appId: number) {
94107
95108 const retail = fmt ( p . currentRetail , cur ) ;
96109 const keyshop = fmt ( p . currentKeyshops , cur ) ;
97- let rows = priceRow ( ICONS . retail , 'Best retail' , retail , 'retail' ) ;
98- rows += priceRow ( ICONS . key , 'Best keyshop' , keyshop , 'keyshop' ) ;
110+ let rows = priceRow ( ICONS . retail , 'Best retail' , retail , 'retail' , safeUrl ) ;
111+ rows += priceRow ( ICONS . key , 'Best keyshop' , keyshop , 'keyshop' , safeUrl ) ;
99112
100113 const histParts = [
101114 fmt ( p . historicalRetail , cur ) && `Retail: ${ fmt ( p . historicalRetail , cur ) } ` ,
@@ -108,8 +121,9 @@ async function inject(appId: number) {
108121 document . getElementById ( ID ) ?. remove ( ) ;
109122 const w = document . createElement ( 'div' ) ;
110123 w . id = ID ;
111- w . innerHTML = `${ header ( ) } <div class="nps-body"><div class="nps-rows">${ rows } </div></div><div class="nps-ftr"><a href=" ${ safeUrl } " target="_blank" >View all deals on GG.deals →</a ></div>` ;
124+ w . innerHTML = `${ header ( ) } <div class="nps-body"><div class="nps-rows">${ rows } </div></div><div class="nps-ftr"><span class="nps-link" data-url=" ${ safeUrl } ">View all deals on GG.deals →</span ></div>` ;
112125 sidebar . insertBefore ( w , findRef ( sidebar ) ) ;
126+ wireClicks ( w ) ;
113127 } catch ( e ) {
114128 console . error ( 'NicePrice: store inject failed' , e ) ;
115129 document . getElementById ( ID ) ?. remove ( ) ;
0 commit comments