From 58f4740da444c3c24778a86be0777a3a95d4a008 Mon Sep 17 00:00:00 2001 From: Step7750 Date: Sat, 25 Oct 2025 12:15:24 -0600 Subject: [PATCH] Removes Deprecated "Trade Proof" Button It's had no relevance for ~2 years. However, that hasn't stopped users from citing it repeatedly. --- src/lib/components/trade_history/helpers.ts | 122 ------------------ .../components/trade_history/trade_proof.ts | 47 ------- src/lib/page_scripts/trade_history.ts | 1 - 3 files changed, 170 deletions(-) delete mode 100644 src/lib/components/trade_history/helpers.ts delete mode 100644 src/lib/components/trade_history/trade_proof.ts diff --git a/src/lib/components/trade_history/helpers.ts b/src/lib/components/trade_history/helpers.ts deleted file mode 100644 index 508d95e9..00000000 --- a/src/lib/components/trade_history/helpers.ts +++ /dev/null @@ -1,122 +0,0 @@ -function historyRowHashcode(row: HTMLElement): string { - const text = row.innerText.replace(/\W/g, ''); - - /* Based on https://stackoverflow.com/a/8831937 (Java's hashCode() method) */ - if (text.length === 0) { - return ''; - } - - let hash = 0; - for (let i = 0; i < text.length; i++) { - const char = text.charCodeAt(i); - hash = (hash << 5) - hash + char; - hash = hash & hash; - } - - return hash.toString(); -} - -function getTimestampFromTrade(row: HTMLElement): number | null { - const dateDiv = row.querySelector('.tradehistory_date'); - if (!dateDiv) { - return null; - } - - const date = dateDiv.firstChild!.nodeValue!.trim(); - const time = (dateDiv.querySelector('.tradehistory_timestamp')! as HTMLElement).innerText; - - const d = new Date(date); - const pure = time.replace('am', '').replace('pm', ''); - let hours = parseInt(pure.split(':')[0]); - const minutes = parseInt(pure.split(':')[1]); - if (time.includes('pm') && hours !== 12) { - /* Prevent 12:XXpm from getting 12 hours added */ - hours += 12; - } else if (time.includes('am') && hours === 12) { - /* Prevent 12:XXam from getting 12 hours instead of being 0 */ - hours -= 12; - } - - d.setHours(hours); - d.setMinutes(minutes); - return d.getTime() / 1000; -} - -async function hasTradeBeforeTime(hashCode: string, timestamp: number): Promise { - const resp = await fetch( - `${location.protocol}//${location.host}${location.pathname}?after_time=${timestamp}&l=english`, - { - credentials: 'same-origin', - } - ); - - const body = await resp.text(); - - if (body.includes('too many requests')) { - alert('You need to wait a couple seconds before generating the proof due to Valve rate-limits'); - throw 'Too many requests'; - } - - const doc = new DOMParser().parseFromString(body, 'text/html'); - const rows = doc.querySelectorAll('.tradehistoryrow') as NodeListOf; - - for (const row of rows) { - const thisCode = historyRowHashcode(row); - if (thisCode === hashCode) { - return true; - } - } - - return false; -} - -async function fetchEnglishRow(index: number): Promise { - let queryParams = location.search; - if (queryParams === '') { - queryParams = '?l=english'; - } else { - queryParams += '&l=english'; - } - - /* Forces us to fetch the english version of the row at a given index no matter what */ - const resp = await fetch(`${location.protocol}//${location.host}${location.pathname}${queryParams}`, { - credentials: 'same-origin', - }); - - const body = await resp.text(); - - const doc = new DOMParser().parseFromString(body, 'text/html'); - const rows = doc.querySelectorAll('.tradehistoryrow'); - return rows[index] as HTMLElement; -} - -/** - * Returns the listing time of the row at {@param index} - * @param index Index of the trade history row on the page - */ -export async function fetchListingTime(index: number): Promise { - const node = await fetchEnglishRow(index); - const hashCode = historyRowHashcode(node); - - const timestamp = getTimestampFromTrade(node); - if (!timestamp) { - throw 'failed timestamp creation'; - } - - let left = 0, - right = 60; - let amt = 0; - while (left < right && amt < 5) { - const middle = left + Math.floor((right - left) / 2); - const hasTrade = await hasTradeBeforeTime(hashCode, timestamp + middle); - if (hasTrade) { - right = middle; - } else { - left = middle; - } - amt++; - } - - /* Hello to all the reversers */ - return timestamp + Math.floor((right + left) / 2); -} diff --git a/src/lib/components/trade_history/trade_proof.ts b/src/lib/components/trade_history/trade_proof.ts deleted file mode 100644 index 014badee..00000000 --- a/src/lib/components/trade_history/trade_proof.ts +++ /dev/null @@ -1,47 +0,0 @@ -import {html} from 'lit'; - -import {state} from 'lit/decorators.js'; -import {CustomElement, InjectAppend, InjectionMode} from '../injectors'; -import {FloatElement} from '../custom'; -import {fetchListingTime} from './helpers'; -import '../common/ui/steam-button'; - -@CustomElement() -@InjectAppend('.tradehistoryrow .tradehistory_content', InjectionMode.CONTINUOUS) -export class TradeProof extends FloatElement { - @state() - private proofNumber: number | undefined; - - @state() - private isProcessing = false; - - async connectedCallback() { - super.connectedCallback(); - } - - render() { - return this.proofNumber - ? html` Proof: ${this.proofNumber} ` - : html` - - - `; - } - - private async onClick() { - this.isProcessing = true; - - const index = $J('.tradehistoryrow').index($J(this).parent().parent()); - try { - this.proofNumber = await fetchListingTime(index); - } catch (e) { - alert( - "Failed to parse time, make sure you're on an english version of the page by appending ?l=english to the url" - ); - } - this.isProcessing = false; - } -} diff --git a/src/lib/page_scripts/trade_history.ts b/src/lib/page_scripts/trade_history.ts index e48c8aad..9ae1e51f 100644 --- a/src/lib/page_scripts/trade_history.ts +++ b/src/lib/page_scripts/trade_history.ts @@ -1,5 +1,4 @@ import {init} from './utils'; -import '../components/trade_history/trade_proof'; init('src/lib/page_scripts/trade_history.js', main);