Skip to content

Commit 90f72ab

Browse files
committed
Refactor constants.ts to use functions for dynamic request initialization and add options.html for API version selection
1 parent 477f5a1 commit 90f72ab

6 files changed

Lines changed: 164 additions & 76 deletions

File tree

public/manifest.json

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
{
2-
"name": "Myket APK Downloader",
3-
"version": "1.1.1",
4-
"author": "Hamidreza Bayat <hamidrezabayat76@gmail.com>",
5-
"description": "Download Myket apps from the browser",
6-
"manifest_version": 3,
7-
"content_scripts": [
8-
{
9-
"matches": [
10-
"*://myket.ir/app/*"
11-
],
12-
"js": [
13-
"scripts/content-script.js"
14-
],
15-
"run_at": "document_end"
16-
}
17-
],
18-
"icons": {
19-
"48": "icons/48x48.png",
20-
"96": "icons/96x96.png"
21-
}
2+
"name": "Myket APK Downloader",
3+
"version": "1.1.1",
4+
"author": "Hamidreza Bayat <hamidrezabayat76@gmail.com>",
5+
"description": "Download Myket apps from the browser",
6+
"manifest_version": 3,
7+
"content_scripts": [
8+
{
9+
"matches": ["*://myket.ir/app/*"],
10+
"js": ["scripts/content-script.js"],
11+
"run_at": "document_end"
12+
}
13+
],
14+
"action": {
15+
"default_title": "Click Me",
16+
"default_popup": "options.html"
17+
},
18+
"permissions": ["storage"],
19+
"icons": {
20+
"48": "icons/48x48.png",
21+
"96": "icons/96x96.png"
22+
}
2223
}

public/manifest_firefox.json

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
{
2-
"name": "Myket APK Downloader",
3-
"version": "1.1.1",
4-
"author": "Hamidreza Bayat <hamidrezabayat76@gmail.com>",
5-
"description": "Download Myket apps from the browser",
6-
"manifest_version": 2,
7-
"content_scripts": [
8-
{
9-
"matches": [
10-
"*://myket.ir/app/*"
11-
],
12-
"js": [
13-
"scripts/content-script.js"
14-
],
15-
"run_at": "document_end"
16-
}
17-
],
18-
"permissions": [
19-
"https://myket.ir/app/*"
20-
],
21-
"browser_specific_settings": {
22-
"gecko": {
23-
"strict_min_version": "102.0"
24-
}
25-
},
26-
"icons": {
27-
"48": "icons/48x48.png",
28-
"96": "icons/96x96.png"
29-
}
2+
"name": "Myket APK Downloader",
3+
"version": "1.1.1",
4+
"author": "Hamidreza Bayat <hamidrezabayat76@gmail.com>",
5+
"description": "Download Myket apps from the browser",
6+
"manifest_version": 2,
7+
"content_scripts": [
8+
{
9+
"matches": ["*://myket.ir/app/*"],
10+
"js": ["scripts/content-script.js"],
11+
"run_at": "document_end"
12+
}
13+
],
14+
"permissions": ["https://myket.ir/app/*", "storage"],
15+
"browser_specific_settings": {
16+
"gecko": {
17+
"strict_min_version": "102.0"
18+
}
19+
},
20+
"icons": {
21+
"48": "icons/48x48.png",
22+
"96": "icons/96x96.png"
23+
}
3024
}

public/options.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Extension Options</title>
6+
<style>
7+
body {
8+
font-family: Arial, sans-serif;
9+
margin: 2em;
10+
}
11+
12+
label, select {
13+
font-size: 1.1em;
14+
}
15+
</style>
16+
</head>
17+
<body>
18+
<h2>Choose API Version</h2>
19+
<label for="api-select">API Version:</label>
20+
<select id="api-select">
21+
<option value="14">14</option>
22+
<option value="15">15</option>
23+
<option value="16">16</option>
24+
<option value="17">17</option>
25+
<option value="18">18</option>
26+
<option value="19">19</option>
27+
<option value="20">20</option>
28+
<option value="21">21</option>
29+
<option value="22">22</option>
30+
<option value="23">23</option>
31+
<option value="24">24</option>
32+
<option value="25">25</option>
33+
<option value="26">26</option>
34+
<option value="27">27</option>
35+
<option value="28">28</option>
36+
<option value="29">29</option>
37+
<option value="30">30</option>
38+
<option value="31">31</option>
39+
<option value="32">32</option>
40+
<option value="33">33</option>
41+
<option value="34">34</option>
42+
<option value="35">35</option>
43+
<option value="36">36</option>
44+
</select>
45+
<button id="save-btn">Save</button>
46+
<p id="status"></p>
47+
<script src="options.js"></script>
48+
</body>
49+
</html>
50+

public/options.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// options.js
2+
// Handles saving/loading API version for the extension
3+
4+
document.addEventListener('DOMContentLoaded', () => {
5+
const apiSelect = document.getElementById('api-select');
6+
const saveBtn = document.getElementById('save-btn');
7+
const status = document.getElementById('status');
8+
9+
// Load saved API version
10+
chrome.storage.local.get(['apiVersion'], (result) => {
11+
if (result.apiVersion) {
12+
apiSelect.value = result.apiVersion;
13+
}
14+
});
15+
16+
// Save selected API version
17+
saveBtn.addEventListener('click', () => {
18+
const selectedApi = apiSelect.value;
19+
chrome.storage.local.set({ apiVersion: selectedApi }, () => {
20+
status.textContent = `Saved API version: ${selectedApi}`;
21+
setTimeout(() => status.textContent = '', 1500);
22+
});
23+
});
24+
});
25+

src/constants.ts

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const v1BaseUrl = `${apiServerUrl}/v1/applications`
33
const v2BaseUrl = `${apiServerUrl}/v2/applications`
44
const authUrl = `${apiServerUrl}/v1/devices/authorize/`
55

6-
const headers = new Headers({
6+
const headers: Headers = new Headers({
77
"Content-Type": "application/json",
88
Accept: "application/json",
99
"Myket-Version": "914",
@@ -14,33 +14,43 @@ const headers = new Headers({
1414
"Accept-Encoding": "gzip",
1515
})
1616

17-
const authBody = {
18-
acId: "",
19-
acKey: "",
20-
adId: "82d8810f-e83c-46c0-8bf5-080a83d635c6",
21-
andId: "82ee24cd7aad5173",
22-
api: "29",
23-
brand: "Nokia",
24-
cpuAbis: ["armeabi-v7a", "armeabi"],
25-
dens: 2.625,
26-
deviceModel: "Nokia 7 plus",
27-
deviceName: "B2N_sprout",
28-
deviceType: "normal",
29-
dsize: "300",
30-
hsh: "4e9118e410d75e2ef80aac45357493e397037940",
31-
imei: "",
32-
imsi: "",
33-
manufacturer: "HMD Global",
34-
product: "Onyx_00WW",
35-
supportedAbis: ["arm64-v8a", "armeabi-v7a", "armeabi"],
36-
uuid: "235f746f-3a40-44b7-97b4-01cac934df6d",
17+
function getAuthBody(apiVersion: string) {
18+
return {
19+
acId: "",
20+
acKey: "",
21+
adId: "82d8810f-e83c-46c0-8bf5-080a83d635c6",
22+
andId: "82ee24cd7aad5173",
23+
api: apiVersion,
24+
brand: "Nokia",
25+
cpuAbis: ["armeabi-v7a", "armeabi"],
26+
dens: 2.625,
27+
deviceModel: "Nokia 7 plus",
28+
deviceName: "B2N_sprout",
29+
deviceType: "normal",
30+
dsize: "300",
31+
hsh: "4e9118e410d75e2ef80aac45357493e397037940",
32+
imei: "",
33+
imsi: "",
34+
manufacturer: "HMD Global",
35+
product: "Onyx_00WW",
36+
supportedAbis: ["arm64-v8a", "armeabi-v7a", "armeabi"],
37+
uuid: "235f746f-3a40-44b7-97b4-01cac934df6d",
38+
}
3739
}
3840

39-
const postRequestInit: RequestInit = {
40-
mode: "cors",
41-
headers: headers,
42-
method: "POST",
43-
body: JSON.stringify(authBody),
41+
async function getPostRequestInit(): Promise<RequestInit> {
42+
return new Promise<RequestInit>(resolve => {
43+
chrome.storage.local.get(["apiVersion"], result => {
44+
const apiVersion =
45+
typeof result.apiVersion === "string" ? result.apiVersion : "29"
46+
resolve({
47+
mode: "cors",
48+
headers: headers,
49+
method: "POST",
50+
body: JSON.stringify(getAuthBody(apiVersion)),
51+
})
52+
})
53+
})
4454
}
4555

4656
const requestInit: RequestInit = {
@@ -49,4 +59,11 @@ const requestInit: RequestInit = {
4959
headers: headers,
5060
}
5161

52-
export { v1BaseUrl, v2BaseUrl, authUrl, headers, requestInit, postRequestInit }
62+
export {
63+
v1BaseUrl,
64+
v2BaseUrl,
65+
authUrl,
66+
headers,
67+
requestInit,
68+
getPostRequestInit,
69+
}

src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
authUrl,
3-
postRequestInit,
3+
getPostRequestInit,
44
requestInit,
55
v1BaseUrl,
66
v2BaseUrl,
@@ -43,6 +43,7 @@ function waitForElement(selector: string): Promise<Element> {
4343
}
4444

4545
async function getAuthToken() {
46+
const postRequestInit = await getPostRequestInit()
4647
const response = await fetch(authUrl, postRequestInit)
4748
if (!response.ok) {
4849
const { translatedMessage } =

0 commit comments

Comments
 (0)