Skip to content

Commit 0b134ec

Browse files
committed
fix store links opening in steam browser, add custom NicePrice icon
1 parent 87e5a03 commit 0b134ec

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

shared/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function escapeHtml(str: string): string {
2323
}
2424

2525
export const ICONS = {
26-
tag: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#67c1f5" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20.59 13.41l-7.17 7.17a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z"/><line x1="7" y1="7" x2="7.01" y2="7"/></svg>',
26+
tag: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="4" width="22" height="16" rx="3" fill="#67c1f5" fill-opacity="0.15" stroke="#67c1f5" stroke-width="1.5"/><path d="M7 15V9l4 6V9" stroke="#67c1f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M14.5 9h2.5a2 2 0 1 1 0 4H14.5V9zm0 6v-2h3" stroke="#67c1f5" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>',
2727
retail: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#beee11" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg>',
2828
key: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#f5a623" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"/></svg>',
2929
clock: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#8f98a0" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>',

webkit/index.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const STYLES_ID = 'niceprice-store-css';
99
const SIDEBAR_SEL = 'div.rightcol.game_meta_data';
1010
const URL_POLL_INTERVAL = 500;
1111

12+
const openExt = (url: string) => window.open(`steam://openurl_external/${url}`);
13+
1214
function 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

Comments
 (0)