Skip to content

Commit ebcec2a

Browse files
authored
Merge pull request #199 from csfloat/feature/annotate-extension-id-firefox
Annotate Extension Version on csfloat.com for Firefox
2 parents 67b653c + e3840ef commit ebcec2a

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {EmptyRequestHandler, SimpleHandler} from './main';
2+
import {RequestType} from './types';
3+
import {AnnotateOfferRequest, AnnotateOfferResponse} from './annotate_offer';
4+
import {runtimeNamespace} from '../../utils/detect';
5+
6+
export interface ExtensionVersionResponse {
7+
version: string;
8+
}
9+
10+
export const ExtensionVersion = new EmptyRequestHandler<ExtensionVersionResponse>(
11+
RequestType.EXTENSION_VERSION,
12+
async (req) => {
13+
const manifest = runtimeNamespace().runtime.getManifest();
14+
return {
15+
version: manifest.version,
16+
};
17+
}
18+
);

src/lib/bridge/handlers/handlers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {StorageRemove} from './storage_remove';
1111
import {RequestType} from './types';
1212
import {FetchExtensionFile} from './fetch_extension_file';
1313
import {AnnotateOffer} from './annotate_offer';
14+
import {ExtensionVersion} from './extension_version';
1415

1516
export const HANDLERS_MAP: {[key in RequestType]: RequestHandler<any, any>} = {
1617
[RequestType.EXECUTE_SCRIPT_ON_PAGE]: ExecuteScriptOnPage,
@@ -24,4 +25,5 @@ export const HANDLERS_MAP: {[key in RequestType]: RequestHandler<any, any>} = {
2425
[RequestType.FETCH_SKIN_MODEL]: FetchSkinModel,
2526
[RequestType.FETCH_EXTENSION_FILE]: FetchExtensionFile,
2627
[RequestType.ANNOTATE_OFFER]: AnnotateOffer,
28+
[RequestType.EXTENSION_VERSION]: ExtensionVersion,
2729
};

src/lib/bridge/handlers/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export enum RequestType {
1010
FETCH_SKIN_MODEL,
1111
FETCH_EXTENSION_FILE,
1212
ANNOTATE_OFFER,
13+
EXTENSION_VERSION,
1314
}

src/lib/page_scripts/csfloat.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {init} from './utils';
2+
import {ClientSend} from '../bridge/client';
3+
import {ExtensionVersion} from '../bridge/handlers/extension_version';
4+
5+
init('src/lib/page_scripts/csfloat.js', main);
6+
7+
async function main() {
8+
// @ts-ignore
9+
window.CSFLOAT_EXTENSION_ENABLED = true;
10+
const resp = await ClientSend(ExtensionVersion, {});
11+
// @ts-ignore
12+
window.CSFLOAT_EXTENSION_VERSION = resp.version;
13+
}

webpack.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ function convertToFirefoxManifest(manifest) {
2929
strict_min_version: '109.0',
3030
},
3131
};
32+
// Allow getting the extension version from CSFloat page in Firefox
33+
cp.content_scripts.push({
34+
matches: ['*://*.csfloat.com/*'],
35+
js: ['src/lib/page_scripts/csfloat.js'],
36+
});
37+
cp.host_permissions.push('*://*.csfloat.com/*');
3238
return cp;
3339
}
3440

0 commit comments

Comments
 (0)