Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d3fe5d9
remove settings param from filterBrands and runFilterRefiner function…
barrymun Jan 16, 2024
5f0a9e2
merging content_scripts.json and base.json into common/manifest.json …
barrymun Jan 16, 2024
bc24ee0
support for a react-based popup script including all relevant depende…
barrymun Jan 16, 2024
f87c0f5
remove the default-src directive from the csp key - this will fix the…
barrymun Jan 16, 2024
e4bbf79
fix 'Error: Could not establish connection' and 'MUI uncontrolled com…
barrymun Jan 17, 2024
4b9b1b0
complete functionality restored to match the old version using the st…
barrymun Jan 17, 2024
c202a9a
remove deprecated code
barrymun Jan 17, 2024
15bc2a4
including the manifest version in the top right corner of the popup, …
barrymun Jan 17, 2024
1df3efa
un-hide all divs if all search results have been hidden, improve the …
barrymun Jan 17, 2024
ee5f1b6
fix the error: 'Attempting to use a disconnected port object'
barrymun Jan 17, 2024
7b3535a
remove some logging, move the port disconnect logic which should reso…
barrymun Jan 17, 2024
9913b2e
adding production build commands for smaller build sizes, adding Make…
barrymun Jan 17, 2024
6750986
lazy load components to reduce build size, change devtool to false in…
barrymun Jan 17, 2024
0248f71
remove comment extraction when building (like extracting LICENSE file…
barrymun Jan 17, 2024
ede3a65
toggle dark|light mode, include base theme
barrymun Jan 18, 2024
fedf19b
complete rework extension, popup no longer brings up the controls - t…
barrymun Jan 18, 2024
5836ff2
reducing build size to ~1.2mb, only importing components that we need…
barrymun Jan 19, 2024
f04bebf
reducing build size to ~740kb, added box-shadow to abf-toggle-contain…
barrymun Jan 20, 2024
4d6d042
fix issue where the container would 'flicker' when bound to the page …
barrymun Jan 20, 2024
c4e92cf
remove unused function
barrymun Jan 20, 2024
613452d
type safety when using the translations in the tsx components, refact…
barrymun Jan 21, 2024
70f9df0
update lint-staged .ts rule to also include .tsx files, run prettier …
barrymun Jan 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
]
},
"ignorePatterns": ["node_modules/", "dist/", "*.config.js", "scripts/"],
"ignorePatterns": ["node_modules/", "dist/", "*.config.js", "scripts/", "i18n.ts"],
"env": {
"browser": true,
"webextensions": true
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# webpack-bundle-analyzer
report.html
5 changes: 5 additions & 0 deletions @types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module "*.png" {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const value: any;
export = value;
}
11 changes: 11 additions & 0 deletions @types/i18next.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import translation from "assets/_locales/en/messages.json";

const resources = {
translation,
} as const;

declare module 'i18next' {
interface CustomTypeOptions {
resources: typeof resources;
}
}
9 changes: 9 additions & 0 deletions @types/style.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { CSSProp } from "styled-components";

interface MyTheme {}

declare module "react" {
interface Attributes {
css?: CSSProp<MyTheme>;
}
}
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
win-build-gecko:
yarn win-build-gecko

win-build-chromium:
yarn win-build-chromium

nix-build-gecko:
yarn nix-build-gecko

nix-build-chromium:
yarn nix-build-chromium

gecko-dashboard:
yarn nix-build-chromium-dashboard

chromium-dashboard:
yarn nix-build-chromium-dashboard

report:
open report.html
3 changes: 2 additions & 1 deletion engines/chromium/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"background": {
"service_worker": "background.js",
"type": "module"
}
},
"web_accessible_resources": []
}
3 changes: 1 addition & 2 deletions engines/chromium/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const path = require('path');
const CopyPlugin = require("copy-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");

const rootPath = path.resolve('./');
const baseConfig = require(`${rootPath}/webpack.config.js`);
Expand All @@ -10,7 +9,7 @@ module.exports = (env, argv) => {
return {
...baseConfig(env, argv),
plugins: [
new CleanWebpackPlugin(),
...baseConfig(env, argv).plugins,
new CopyPlugin({
patterns: [
...defaultCopyPluginPatterns,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"name": "Amazon Brand Filter",
"manifest_version": 3,
"default_locale": "en",
"icons": {
"16": "icons/abf-disabled-16.png",
"32": "icons/abf-disabled-32.png",
"48": "icons/abf-disabled-48.png",
"128": "icons/abf-disabled-128.png"
},
"permissions": ["storage", "activeTab"],
Expand Down
23 changes: 0 additions & 23 deletions engines/common/manifest/content-scripts.json

This file was deleted.

16 changes: 16 additions & 0 deletions engines/common/matches.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
"*://*.amazon.com/*",
"*://*.amazon.ca/*",
"*://*.amazon.cn/*",
"*://*.amazon.co.jp/*",
"*://*.amazon.com/*",
"*://*.amazon.com.au/*",
"*://*.amazon.com.mx/*",
"*://*.amazon.co.uk/*",
"*://*.amazon.de/*",
"*://*.amazon.es/*",
"*://*.amazon.fr/*",
"*://*.amazon.in/*",
"*://*.amazon.it/*",
"*://*.amazon.nl/*"
]
4 changes: 4 additions & 0 deletions engines/common/web-accessible-resources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"resources": ["container.css", "controls.html", "toggle.html"],
"matches": []
}
2 changes: 1 addition & 1 deletion engines/gecko/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"type": "module"
},
"content_security_policy": {
"extension_pages": "default-src 'self'; script-src 'self'; object-src 'none'; connect-src https://raw.githubusercontent.com/chris-mosley/AmazonBrandFilterList/main/brands.txt https://api.github.com/repos/chris-mosley/AmazonBrandFilterList/releases/latest;"
"extension_pages": "script-src 'self'; object-src 'none'; connect-src https://raw.githubusercontent.com/chris-mosley/AmazonBrandFilterList/main/brands.txt https://api.github.com/repos/chris-mosley/AmazonBrandFilterList/releases/latest;"
},
"web_accessible_resources": [
{
Expand Down
3 changes: 1 addition & 2 deletions engines/gecko/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const path = require('path');
const CopyPlugin = require("copy-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");

const rootPath = path.resolve('./');
const baseConfig = require(`${rootPath}/webpack.config.js`);
Expand All @@ -10,7 +9,7 @@ module.exports = (env, argv) => {
return {
...baseConfig(env, argv),
plugins: [
new CleanWebpackPlugin(),
...baseConfig(env, argv).plugins,
new CopyPlugin({
patterns: [
...defaultCopyPluginPatterns,
Expand Down
36 changes: 28 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,55 @@
{
"name": "AmazonBrandFilter",
"description": "Filters out all unknown brands from Amazon search results.",
"version": "0.5.0",
"keywords": [],
"author": "",
"license": "MIT",
"private": true,
"devDependencies": {
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@fontsource/roboto": "^5.0.8",
"@jest/globals": "^29.7.0",
"@mui/icons-material": "^5.15.5",
"@mui/material": "^5.15.4",
"@mui/types": "^7.2.13",
"@types/chrome": "^0.0.237",
"@types/jest": "^29.5.11",
"@types/lodash": "^4.14.202",
"@types/react": "^18.2.48",
"@types/react-dom": "^18.2.18",
"@types/web": "^0.0.130",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"clean-webpack-plugin": "^4.0.0",
"copy-webpack-plugin": "^11.0.0",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.5.2",
"husky": "^8.0.3",
"i18next": "^23.7.16",
"jest": "^29.7.0",
"lint-staged": "^13.2.2",
"lodash": "^4.17.21",
"prettier": "2.8.8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^14.0.0",
"run-script-os": "^1.1.6",
"terser-webpack-plugin": "^5.3.10",
"ts-jest": "^29.1.1",
"ts-loader": "^9.4.3",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"typescript": "^5.1.3",
"web-ext": "^7.6.2",
"webextension-polyfill-ts": "^0.26.0",
"webpack": "^5.86.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"lodash": "^4.17.21"
"webpack-bundle-analyzer": "^4.10.1",
"webpack-cli": "^5.1.4",
"webpack-dashboard": "^3.3.8"
},
"lint-staged": {
"src/**/*.ts": [
"prettier --write \"src/**/*.ts\""
"src/**/*.{ts,tsx}": [
"prettier --write \"src/**/*.{ts,tsx}\""
],
"src/**/*.json": [
"prettier --write \"src/**/*.json\""
Expand All @@ -56,8 +70,14 @@
"lint": "yarn eslint src/**/*.ts",
"test": "jest",
"win-build-gecko": "Remove-Item dist -Recurse -Force; webpack --mode development --config engines/gecko/webpack.config.js; node scripts\\post-build-update-manifest.js",
"win-build-gecko-prod": "Remove-Item dist -Recurse -Force; webpack --mode production --config engines/gecko/webpack.config.js; node scripts\\post-build-update-manifest.js",
"win-build-chromium": "Remove-Item dist -Recurse -Force; webpack --mode development --config engines/chromium/webpack.config.js; node scripts\\post-build-update-manifest.js",
"win-build-chromium-prod": "Remove-Item dist -Recurse -Force; webpack --mode production --config engines/chromium/webpack.config.js; node scripts\\post-build-update-manifest.js",
"nix-build-gecko": "rm -rf dist && webpack --mode development --config engines/gecko/webpack.config.js && node scripts/post-build-update-manifest.js",
"nix-build-chromium": "rm -rf dist && webpack --mode development --config engines/chromium/webpack.config.js && node scripts/post-build-update-manifest.js"
"nix-build-gecko-prod": "rm -rf dist && webpack --mode production --config engines/gecko/webpack.config.js && node scripts/post-build-update-manifest.js",
"nix-build-gecko-dashboard": "rm -rf dist && webpack-dashboard -- webpack --mode production --config engines/gecko/webpack.config.js && node scripts/post-build-update-manifest.js",
"nix-build-chromium": "rm -rf dist && webpack --mode development --config engines/chromium/webpack.config.js && node scripts/post-build-update-manifest.js",
"nix-build-chromium-prod": "rm -rf dist && webpack --mode production --config engines/chromium/webpack.config.js && node scripts/post-build-update-manifest.js",
"nix-build-chromium-dashboard": "rm -rf dist && webpack-dashboard -- webpack --mode production --config engines/chromium/webpack.config.js && node scripts/post-build-update-manifest.js"
}
}
46 changes: 38 additions & 8 deletions scripts/post-build-update-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,54 @@ const path = require("path");

const rootPath = path.resolve("./");
const packageJson = require(`${rootPath}/package.json`);
const baseManifestJson = require(`${rootPath}/engines/common/manifest/base.json`);
const contentScriptsJson = require(`${rootPath}/engines/common/manifest/content-scripts.json`);
const manifestFilePath = path.resolve(__dirname, `${rootPath}/dist/manifest.json`);

let commonManifestJson = require(`${rootPath}/engines/common/manifest.json`);
let commonMatchesJson = require(`${rootPath}/engines/common/matches.json`);
let commonWebAccessibleResourcesJson = require(`${rootPath}/engines/common/web-accessible-resources.json`);

try {
// read the manifest file
// the base file from whichever engine is being built will exist before this script runs
let manifest = JSON.parse(fs.readFileSync(manifestFilePath));

// update the relevant keys
manifest.version = packageJson.version;
manifest.name = packageJson.name;
manifest.description = packageJson.description;
manifest = { ...manifest, ...baseManifestJson, ...contentScriptsJson };
// update the matches in the web_accessible_resources json
commonWebAccessibleResourcesJson = {
...commonWebAccessibleResourcesJson,
matches: commonMatchesJson,
};

// set the content_scripts and set the matches
commonManifestJson = {
...commonManifestJson,
content_scripts: [
{
matches: commonMatchesJson,
js: ["content.js"],
},
],
};

// take required keys from package.json
// manifest web_accessible_resources needs to be updated at this point
// also include the common manifest json
manifest = {
...manifest,
version: packageJson.version,
description: packageJson.description,
web_accessible_resources: [...manifest.web_accessible_resources, commonWebAccessibleResourcesJson],
...commonManifestJson,
};

// write the updated manifest file
fs.writeFileSync(manifestFilePath, JSON.stringify(manifest, null, 2));

console.log(`Version updated to ${packageJson.version} in manifest.json.`);

// move the analyzer report.html out of the dist folder if it exists
if (fs.existsSync(`${rootPath}/dist/report.html`)) {
fs.renameSync(`${rootPath}/dist/report.html`, `${rootPath}/report.html`);
console.log(`Moved 'report.html' to ${rootPath}`);
}
} catch (error) {
console.error(`Error updating manifest.json: ${error.message}`);
}
9 changes: 9 additions & 0 deletions src/assets/_locales/de/messages.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"introduction": {
"message": "Amazon Brand Filter",
"warning": "Um diese Erweiterung zu nutzen, musst du auf einer Amazon-Marktplatzseite sein (z. B. amazon.com, amazon.co.uk, amazon.de usw.)",
"description": "Um loszulegen, klicke auf die Schaltfläche unten rechts auf der Seite!"
},
"popup_enabled": {
"message": "Aktivieren Sie Amazon Brand Filter",
"description": "Aktivieren Sie Amazon Brand Filter"
Expand Down Expand Up @@ -58,5 +63,9 @@
"popup_help_translate": {
"message": "Help translate",
"description": "Link to help translate the extension"
},
"popup_all_results_filtered": {
"message": "Alle Ergebnisse werden angezeigt, da alle Elemente gefiltert wurden",
"description": "Nachricht, die angezeigt wird, wenn alle Ergebnisse gefiltert sind"
}
}
9 changes: 9 additions & 0 deletions src/assets/_locales/en/messages.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"introduction": {
"message": "Amazon Brand Filter",
"warning": "To use this extension, you must be on an Amazon marketplace site (e.g. amazon.com, amazon.co.uk, amazon.de, etc.)",
"description": "To get started, click on the button in the bottom right of the page!"
},
"popup_enabled": {
"message": "Enable Amazon Brand Filter",
"description": "Enable Amazon Brand Filter"
Expand Down Expand Up @@ -58,5 +63,9 @@
"popup_help_translate": {
"message": "Help translate",
"description": "Link to help translate the extension"
},
"popup_all_results_filtered": {
"message": "Showing all results as all items have been filtered",
"description": "Message to show when all results are filtered"
}
}
9 changes: 9 additions & 0 deletions src/assets/_locales/es/messages.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"introduction": {
"message": "Amazon Brand Filter",
"warning": "Para utilizar esta extensión, debes estar en un sitio web de Amazon (por ejemplo, amazon.com, amazon.co.uk, amazon.de, etc.)",
"description": "Para comenzar, haz clic en el botón en la parte inferior derecha de la página!"
},
"popup_enabled": {
"message": "Activar Amazon Brand Filter",
"description": "Activar el filtro de marcas de Amazon"
Expand Down Expand Up @@ -58,5 +63,9 @@
"popup_help_translate": {
"message": "Help translate",
"description": "Link to help translate the extension"
},
"popup_all_results_filtered": {
"message": "Mostrando todos los resultados ya que todos los elementos han sido filtrados",
"description": "Mensaje a mostrar cuando todos los resultados están filtrados"
}
}
Loading