Skip to content

Commit

Permalink
Initial Auto Trading with Cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
Step7750 committed Apr 4, 2024
1 parent 9eb6847 commit 09d59c4
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
2 changes: 2 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"type": "module"
},
"permissions": ["storage", "scripting"],
"optional_permissions": ["cookies"],
"optional_host_permissions": ["https://steamcommunity.com/"],
"host_permissions": [
"*://*.steamcommunity.com/market/listings/730/*",
"*://*.steamcommunity.com/id/*/inventory*",
Expand Down
2 changes: 2 additions & 0 deletions src/lib/bridge/handlers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {RequestType} from './types';
import {FetchExtensionFile} from './fetch_extension_file';
import {AnnotateOffer} from './annotate_offer';
import {ExtensionVersion} from './extension_version';
import {SendCookies} from './send_cookies';

export const HANDLERS_MAP: {[key in RequestType]: RequestHandler<any, any>} = {
[RequestType.EXECUTE_SCRIPT_ON_PAGE]: ExecuteScriptOnPage,
Expand All @@ -26,4 +27,5 @@ export const HANDLERS_MAP: {[key in RequestType]: RequestHandler<any, any>} = {
[RequestType.FETCH_EXTENSION_FILE]: FetchExtensionFile,
[RequestType.ANNOTATE_OFFER]: AnnotateOffer,
[RequestType.EXTENSION_VERSION]: ExtensionVersion,
[RequestType.SEND_COOKIES]: SendCookies,
};
53 changes: 53 additions & 0 deletions src/lib/bridge/handlers/send_cookies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {SimpleHandler} from './main';
import {RequestType} from './types';

export interface SendCookiesRequest {
verify_only?: boolean;
}

export interface SendCookiesResponse {}

export const SendCookies = new SimpleHandler<SendCookiesRequest, SendCookiesResponse>(
RequestType.SEND_COOKIES,
async (req) => {
console.log('cookies 123');
// @ts-ignore MV3 returns a promise
const hasPermission = (await chrome.permissions.contains({
permissions: ['cookies'],
origins: ['https://steamcommunity.com/'],
})) as boolean;

console.log(hasPermission);

if (!hasPermission) {
// @ts-ignore MV3 returns a promise
const granted = (await chrome.permissions.request({
permissions: ['cookies'],
origins: ['https://steamcommunity.com/'],
})) as boolean;
if (!granted) {
throw new Error('failed to grant permission, cannot proceed');
}
}

if (req.verify_only) {
return {} as SendCookiesResponse;
}

const cookies = await chrome.cookies.getAll({
domain: 'steamcommunity.com',
});

console.log(cookies);

return {} as SendCookiesResponse;
// const resp = await fetch(`https://csfloat.com/api/v1/me/steam-cookies`, {
// credentials: 'include',
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json',
// },
// body: JSON.stringify(req),
// });
}
);
1 change: 1 addition & 0 deletions src/lib/bridge/handlers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export enum RequestType {
FETCH_EXTENSION_FILE,
ANNOTATE_OFFER,
EXTENSION_VERSION,
SEND_COOKIES,
}
28 changes: 27 additions & 1 deletion src/lib/components/trade_offer/auto_fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {Observe} from '../../utils/observers';

import '../common/ui/steam-button';
import {AppId, ContextId} from '../../types/steam_constants';
import {SendCookies} from '../../bridge/handlers/send_cookies';

@CustomElement()
@InjectBefore('div.trade_area')
Expand Down Expand Up @@ -105,6 +106,31 @@ export class AutoFill extends FloatElement {
`;
}

renderAutoManageTradeOffers() {
return html`
<div class="container" style="margin: 20px 0 20px 0;">
<div>
<div class="float-icon">
<img
src="https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/79/798a12316637ad8fbb91ddb7dc63f770b680bd19_full.jpg"
style="height: 32px;"
/>
</div>
<span class="item-name"> Automatically Create Offers </span>
<div class="sale-info">Allow CSFloat to automatically track and create offers.</div>
</div>
<csfloat-steam-button
.text="${'Enable Auto Trading'}"
@click="${() => this.enableAutoTrading()}"
></csfloat-steam-button>
</div>
`;
}

async enableAutoTrading() {
await ClientSend(SendCookies, {});
}

renderBulkAutoFillDialog(rawTrades: Trade[]): HTMLTemplateResult {
// Remove items already included and non-pending
const fTrades = rawTrades
Expand Down Expand Up @@ -198,7 +224,7 @@ export class AutoFill extends FloatElement {

return html`
${this.renderBulkAutoFillDialog(tradesToBuyer)} ${tradesToBuyer.map((e) => this.renderAutoFillDialog(e))}
${this.showWarningDialog()}
${this.showWarningDialog()} ${this.renderAutoManageTradeOffers()}
`;
}

Expand Down

0 comments on commit 09d59c4

Please sign in to comment.