Skip to content

Commit 5a513ca

Browse files
authored
Merge pull request #203 from csfloat/revert/auto-trading-cookies
Reverts #201, #202
2 parents 6f9f38e + b5b16ed commit 5a513ca

File tree

13 files changed

+24
-358
lines changed

13 files changed

+24
-358
lines changed

manifest.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"type": "module"
4545
},
4646
"permissions": ["storage", "scripting"],
47-
"optional_permissions": ["cookies", "alarms"],
4847
"host_permissions": [
4948
"*://*.steamcommunity.com/market/listings/730/*",
5049
"*://*.steamcommunity.com/id/*/inventory*",

src/background.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import {Handle} from './lib/bridge/server';
22
import {InternalResponseBundle} from './lib/bridge/types';
33
import MessageSender = chrome.runtime.MessageSender;
4-
import {ClientSend} from './lib/bridge/client';
5-
import {SendCookies} from './lib/bridge/handlers/send_cookies';
6-
import {setupCookieAlarm} from './lib/utils/alarm';
74

85
function unifiedHandler(request: any, sender: MessageSender, sendResponse: (response?: any) => void) {
96
Handle(request, sender)
@@ -23,17 +20,7 @@ function unifiedHandler(request: any, sender: MessageSender, sendResponse: (resp
2320
});
2421
}
2522

26-
function requestPermissions(permissions: string[], sendResponse: any) {
27-
chrome.permissions.request({permissions}, (granted) => sendResponse(granted));
28-
29-
return true;
30-
}
31-
3223
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
33-
if (request.message === 'requestPermissions') {
34-
return requestPermissions(request.permissions, sendResponse);
35-
}
36-
3724
unifiedHandler(request, sender, sendResponse);
3825
return true;
3926
});
@@ -42,7 +29,3 @@ chrome.runtime.onMessageExternal.addListener((request, sender, sendResponse) =>
4229
unifiedHandler(request, sender, sendResponse);
4330
return true;
4431
});
45-
46-
chrome.runtime.onInstalled.addListener(async ({reason}) => {
47-
await setupCookieAlarm(true);
48-
});

src/lib/bridge/client.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {InternalRequestBundle, InternalResponseBundle, RequestHandler, Version}
22
import {isFirefox, runtimeNamespace} from '../utils/detect';
33
import {inPageContext} from '../utils/snips';
44
import {g_PostMessageBus} from '../bus/post_message_bus';
5-
import {DeferredPromise} from '../utils/deferred_promise';
65

76
function canUseSendMessage() {
87
// Not supported in Firefox Page Context
@@ -23,23 +22,21 @@ export async function ClientSend<Req, Resp>(handler: RequestHandler<Req, Resp>,
2322
};
2423

2524
if (canUseSendMessage()) {
26-
const promise = new DeferredPromise<Resp>();
27-
28-
// @ts-ignore Bad types
29-
runtimeNamespace().runtime.sendMessage(
30-
(typeof window !== 'undefined' && window.CSFLOAT_EXTENSION_ID) || chrome.runtime.id,
31-
bundle,
25+
return new Promise((resolve, reject) => {
3226
// @ts-ignore Bad types
33-
(resp: InternalResponseBundle) => {
34-
if (resp?.response) {
35-
promise.resolve(resp.response);
36-
} else {
37-
promise.reject(resp?.error);
27+
runtimeNamespace().runtime.sendMessage(
28+
window.CSFLOAT_EXTENSION_ID || chrome.runtime.id,
29+
bundle,
30+
// @ts-ignore Bad types
31+
(resp: InternalResponseBundle) => {
32+
if (resp?.response) {
33+
resolve(resp.response);
34+
} else {
35+
reject(resp?.error);
36+
}
3837
}
39-
}
40-
);
41-
42-
return promise.promise();
38+
);
39+
});
4340
} else {
4441
// Fallback to postmessage bus for browsers that don't implement
4542
// specs fully

src/lib/bridge/handlers/handlers.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import {RequestType} from './types';
1212
import {FetchExtensionFile} from './fetch_extension_file';
1313
import {AnnotateOffer} from './annotate_offer';
1414
import {ExtensionVersion} from './extension_version';
15-
import {SendCookies} from './send_cookies';
16-
import {HasPermissions} from './has_permissions';
17-
import {MetaSettings} from './meta_settings';
18-
import {ProveTradesToken} from './prove_trades_token';
1915

2016
export const HANDLERS_MAP: {[key in RequestType]: RequestHandler<any, any>} = {
2117
[RequestType.EXECUTE_SCRIPT_ON_PAGE]: ExecuteScriptOnPage,
@@ -30,8 +26,4 @@ export const HANDLERS_MAP: {[key in RequestType]: RequestHandler<any, any>} = {
3026
[RequestType.FETCH_EXTENSION_FILE]: FetchExtensionFile,
3127
[RequestType.ANNOTATE_OFFER]: AnnotateOffer,
3228
[RequestType.EXTENSION_VERSION]: ExtensionVersion,
33-
[RequestType.SEND_COOKIES]: SendCookies,
34-
[RequestType.HAS_PERMISSIONS]: HasPermissions,
35-
[RequestType.META_SETTINGS]: MetaSettings,
36-
[RequestType.PROVE_TRADES_TOKEN]: ProveTradesToken,
3729
};

src/lib/bridge/handlers/has_permissions.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/lib/bridge/handlers/meta_settings.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/lib/bridge/handlers/prove_trades_token.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/lib/bridge/handlers/send_cookies.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/lib/bridge/handlers/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,4 @@ export enum RequestType {
1111
FETCH_EXTENSION_FILE,
1212
ANNOTATE_OFFER,
1313
EXTENSION_VERSION,
14-
SEND_COOKIES,
15-
HAS_PERMISSIONS,
16-
META_SETTINGS,
17-
PROVE_TRADES_TOKEN,
1814
}

src/lib/components/trade_history/trade_proof.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import {CustomElement, InjectAppend, InjectionMode} from '../injectors';
55
import {FloatElement} from '../custom';
66
import {fetchListingTime} from './helpers';
77
import '../common/ui/steam-button';
8-
import {ProveTradesToken} from '../../bridge/handlers/prove_trades_token';
9-
import {ClientSend} from '../../bridge/client';
108

119
@CustomElement()
1210
@InjectAppend('.tradehistoryrow .tradehistory_content', InjectionMode.CONTINUOUS)
1311
export class TradeProof extends FloatElement {
1412
@state()
15-
private message: string | undefined;
13+
private proofNumber: number | undefined;
1614

1715
@state()
1816
private isProcessing = false;
@@ -22,12 +20,12 @@ export class TradeProof extends FloatElement {
2220
}
2321

2422
render() {
25-
return this.message
26-
? html` <span>${this.message}</span> `
23+
return this.proofNumber
24+
? html` <span>Proof: ${this.proofNumber}</span> `
2725
: html`
2826
<csfloat-steam-button
2927
@click="${this.onClick}"
30-
.text="${this.isProcessing ? 'Proving...' : 'Prove Trade on CSFloat'}"
28+
.text="${this.isProcessing ? 'Computing Proof...' : 'CSFloat Proof'}"
3129
>
3230
</csfloat-steam-button>
3331
`;
@@ -36,17 +34,14 @@ export class TradeProof extends FloatElement {
3634
private async onClick() {
3735
this.isProcessing = true;
3836

39-
const token = document
40-
.getElementById('application_config')
41-
?.getAttribute('data-loyalty_webapi_token')
42-
?.replace('"', '')
43-
.replace('"', '');
44-
37+
const index = $J('.tradehistoryrow').index($J(this).parent().parent());
4538
try {
46-
const resp = await ClientSend(ProveTradesToken, {token});
47-
this.message = resp.message;
48-
} catch (e: any) {
49-
alert(e.toString());
39+
this.proofNumber = await fetchListingTime(index);
40+
} catch (e) {
41+
alert(
42+
"Failed to parse time, make sure you're on an english version of the page by appending ?l=english to the url"
43+
);
5044
}
45+
this.isProcessing = false;
5146
}
5247
}

0 commit comments

Comments
 (0)