Skip to content

Commit

Permalink
fix manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
qunash committed Jan 13, 2023
1 parent 30e0012 commit 3e6a6db
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 34 deletions.
9 changes: 5 additions & 4 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import postcssPlugin from "esbuild-style-plugin";
import copyStaticFilesPlugin from "esbuild-copy-files-plugin";

const buildDir = "build";
const minify = process.argv.includes("--minify");

async function deleteBuildDir() {
await fs.remove(buildDir);
}

async function runEsbuild() {
await esbuild.build({
entryPoints: ["src/content-scripts/cs.tsx", "src/background/bg.ts"],
entryPoints: ["src/content-scripts/main_ui.tsx", "src/background/bg.ts"],
outdir: buildDir,
bundle: true,
minify: true,
minify: minify,
treeShaking: true,
define: {
"process.env.NODE_ENV": '"production"',
Expand All @@ -35,9 +36,9 @@ async function runEsbuild() {
},
}),
copyStaticFilesPlugin({
source: ["src/manifest.json", "src/assets/icons"],
source: ["src/manifest.json", "src/assets/"],
target: buildDir,
copyWithFolder: true,
copyWithFolder: false,
}),
],
});
Expand Down
70 changes: 69 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"scripts": {
"build-dev": "node build.mjs",
"build-prod": "node build.mjs --create-zips",
"build-prod": "node build.mjs --create-zips --minify",
"watch": "chokidar src -c \"npm run build-dev\""
},
"eslintConfig": {
Expand All @@ -19,9 +19,12 @@
]
},
"dependencies": {
"lodash-es": "^4.17.21",
"preact": "^10.10.0"
},
"devDependencies": {
"@types/lodash-es": "^4.17.6",
"@types/webextension-polyfill": "^0.10.0",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"archiver": "^5.3.1",
Expand All @@ -35,6 +38,7 @@
"fs-extra": "^11.1.0",
"preact-cli": "^3.4.0",
"tailwindcss": "^3.2.4",
"typescript": "^4.5.2"
"typescript": "^4.5.2",
"webextension-polyfill": "^0.10.0"
}
}
70 changes: 70 additions & 0 deletions src/assets/data/regions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[
{ "value": "wt-wt", "label": "Any region" },
{ "value": "xa-ar", "label": "Saudi Arabia" },
{ "value": "xa-en", "label": "Saudi Arabia (en)" },
{ "value": "ar-es", "label": "Argentina" },
{ "value": "au-en", "label": "Australia" },
{ "value": "at-de", "label": "Austria" },
{ "value": "be-fr", "label": "Belgium (fr)" },
{ "value": "be-nl", "label": "Belgium (nl)" },
{ "value": "br-pt", "label": "Brazil" },
{ "value": "bg-bg", "label": "Bulgaria" },
{ "value": "ca-en", "label": "Canada" },
{ "value": "ca-fr", "label": "Canada (fr)" },
{ "value": "ct-ca", "label": "Catalan" },
{ "value": "cl-es", "label": "Chile" },
{ "value": "cn-zh", "label": "China" },
{ "value": "co-es", "label": "Colombia" },
{ "value": "hr-hr", "label": "Croatia" },
{ "value": "cz-cs", "label": "Czech Republic" },
{ "value": "dk-da", "label": "Denmark" },
{ "value": "ee-et", "label": "Estonia" },
{ "value": "fi-fi", "label": "Finland" },
{ "value": "fr-fr", "label": "France" },
{ "value": "de-de", "label": "Germany" },
{ "value": "gr-el", "label": "Greece" },
{ "value": "hk-tzh", "label": "Hong Kong" },
{ "value": "hu-hu", "label": "Hungary" },
{ "value": "in-en", "label": "India" },
{ "value": "id-id", "label": "Indonesia" },
{ "value": "id-en", "label": "Indonesia (en)" },
{ "value": "ie-en", "label": "Ireland" },
{ "value": "il-he", "label": "Israel" },
{ "value": "it-it", "label": "Italy" },
{ "value": "jp-jp", "label": "Japan" },
{ "value": "kr-kr", "label": "Korea" },
{ "value": "lv-lv", "label": "Latvia" },
{ "value": "lt-lt", "label": "Lithuania" },
{ "value": "xl-es", "label": "Latin America" },
{ "value": "my-ms", "label": "Malaysia" },
{ "value": "my-en", "label": "Malaysia (en)" },
{ "value": "mx-es", "label": "Mexico" },
{ "value": "nl-nl", "label": "Netherlands" },
{ "value": "nz-en", "label": "New Zealand" },
{ "value": "no-no", "label": "Norway" },
{ "value": "pe-es", "label": "Peru" },
{ "value": "ph-en", "label": "Philippines" },
{ "value": "ph-tl", "label": "Philippines (tl)" },
{ "value": "pl-pl", "label": "Poland" },
{ "value": "pt-pt", "label": "Portugal" },
{ "value": "ro-ro", "label": "Romania" },
{ "value": "ru-ru", "label": "Russia" },
{ "value": "sg-en", "label": "Singapore" },
{ "value": "sk-sk", "label": "Slovak Republic" },
{ "value": "sl-sl", "label": "Slovenia" },
{ "value": "za-en", "label": "South Africa" },
{ "value": "es-es", "label": "Spain" },
{ "value": "se-sv", "label": "Sweden" },
{ "value": "ch-de", "label": "Switzerland (de)" },
{ "value": "ch-fr", "label": "Switzerland (fr)" },
{ "value": "ch-it", "label": "Switzerland (it)" },
{ "value": "tw-tzh", "label": "Taiwan" },
{ "value": "th-th", "label": "Thailand" },
{ "value": "tr-tr", "label": "Turkey" },
{ "value": "ua-uk", "label": "Ukraine" },
{ "value": "uk-en", "label": "United Kingdom" },
{ "value": "us-en", "label": "United States" },
{ "value": "ue-es", "label": "United States (es)" },
{ "value": "ve-es", "label": "Venezuela" },
{ "value": "vn-vi", "label": "Vietnam" }
]
27 changes: 27 additions & 0 deletions src/background/bg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Browser from 'webextension-polyfill'


var manifest_version = Browser.runtime.getManifest().manifest_version


Browser.runtime.onInstalled.addListener(async () => {
Browser.storage.sync.set({
num_web_results: 3,
web_access: true,
region: "wt-wt",
})
openChatGPTWebpage()
})

function openChatGPTWebpage() {
Browser.tabs.create({
url: "https://chat.openai.com/chat",
})
}

// open chatgpt webpage when extension icon is clicked
if (manifest_version == 2) {
Browser.browserAction.onClicked.addListener(openChatGPTWebpage)
} else {
Browser.action.onClicked.addListener(openChatGPTWebpage)
}
1 change: 0 additions & 1 deletion src/content-scripts/cs.tsx

This file was deleted.

19 changes: 19 additions & 0 deletions src/content-scripts/main_ui.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import '../style/base.css'
import Browser from 'webextension-polyfill'

let isWebAccessOn = true;
var numWebResults = 1
var region = ""

async function getDefaultParams() {

({ num_web_results: numWebResults, web_access: isWebAccessOn, region } = await Browser.storage.sync.get(['num_web_results', 'web_access', 'region']))

console.log(numWebResults, isWebAccessOn, region)
}

async function run() {
await getDefaultParams()
}

run()
30 changes: 7 additions & 23 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,27 @@
"48": "icons/icon48.png",
"128": "icons/icon128.png"
},
"permissions": [
"storage"
],
"host_permissions": [
"https://ddg-webapp-aagd.vercel.app/*"
],
"permissions": ["storage"],
"host_permissions": ["https://ddg-webapp-aagd.vercel.app/*"],
"background": {
"service_worker": "background.js"
"service_worker": "background/bg.js"
},
"action": {},
"content_scripts": [
{
"matches": [
"https://chat.openai.com/chat/*"
],
"js": [
"content-scripts/main_ui.js",
"api.js",
"content-scripts/prompts-window/prompts-window.js"
],
"css": [
"content-scripts/main_ui.css",
"content-scripts/prompts-window/prompts-window.css"
]
"matches": ["https://chat.openai.com/chat/*"],
"js": ["content-scripts/main_ui.js"],
"css": []
}
],
"web_accessible_resources": [
{
"resources": [
"data/default_prompt.txt",
"data/regions.json",
"icons/icon48.png",
"icons/MaterialIcons-Regular.woff2"
],
"matches": [
"https://chat.openai.com/*"
]
"matches": ["https://chat.openai.com/*"]
}
]
}
5 changes: 2 additions & 3 deletions src/manifest.v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
"content_scripts": [
{
"matches": ["https://chat.openai.com/*"],
"js": ["content-scripts/main_ui.js", "api.js", "content-scripts/prompts-window/prompts-winow.js"],
"css": ["content-scripts/main_ui.css", "content-scripts/prompts-window/prompts-window.css"]
"js": ["content-scripts/main_ui.js"],
"css": []
}
],
"web_accessible_resources":
[
"data/default_prompt.txt",
"data/regions.json",
"icons/icon48.png",
"icons/MaterialIcons-Regular.woff2"
Expand Down

0 comments on commit 3e6a6db

Please sign in to comment.