Skip to content

Commit

Permalink
It is now possible to output as a Chrome/Firefox extension
Browse files Browse the repository at this point in the history
  • Loading branch information
ryo-fujinone committed Mar 24, 2024
1 parent dabbd4c commit 23d190c
Show file tree
Hide file tree
Showing 4 changed files with 1,018 additions and 0 deletions.
67 changes: 67 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import archiver from "archiver";
import fs from "fs-extra";
import path from "path";

const extName = "auto-hide-next-up-card";

const distDir = "dist";
const chromeExtDir = path.join(distDir, "chrome");
const firefoxExtDir = path.join(distDir, "firefox");

const pkgMetadata = JSON.parse(fs.readFileSync("package.json", "utf-8"));
const pkgVersion = pkgMetadata.version;
const baseArchiveName = `${extName}_${pkgVersion}`;

const prepareSrc = (parentDir) => {
if (!fs.existsSync(parentDir)) {
fs.mkdirSync(parentDir, { recursive: true });
}
const targetDir = path.join(parentDir, "ext");
if (fs.existsSync(targetDir)) {
fs.rmSync(targetDir, { recursive: true });
}
fs.copySync("src/", targetDir);
fs.copySync("LICENSE", path.join(targetDir, "LICENSE"));
return targetDir;
};

const buildChromeExt = async () => {
const targetDir = prepareSrc(chromeExtDir);
const archiveName = `${baseArchiveName}_chrome.zip`;
const archivePath = path.join(chromeExtDir, archiveName);

const output = fs.createWriteStream(archivePath);
const archive = archiver("zip", {
zlib: { level: 9 },
});
archive.directory(targetDir, false);
archive.pipe(output);
await archive.finalize();
console.log(`created ${archivePath}`);
};

const buildFirefoxExt = async () => {
const targetDir = prepareSrc(firefoxExtDir);
const archiveName = `${baseArchiveName}_firefox.zip`;
const archivePath = path.join(firefoxExtDir, archiveName);
const manifestPath = path.join(targetDir, "manifest.json");

fs.rmSync(manifestPath);
fs.copySync("misc/manifest.firefox.json", manifestPath);

const output = fs.createWriteStream(archivePath);
const archive = archiver("zip", {
zlib: { level: 9 },
});
archive.directory(targetDir, false);
archive.pipe(output);
await archive.finalize();
console.log(`created ${archivePath}`);
};

const main = async () => {
await buildChromeExt();
await buildFirefoxExt();
};

main();
49 changes: 49 additions & 0 deletions misc/manifest.firefox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"manifest_version": 3,
"name": "Auto hide next up card for Amazon Prime Video",
"version": "2.1.1",
"default_locale": "en",
"description": "__MSG_desc__",
"icons": {
"16": "icons/16.png",
"32": "icons/32.png",
"48": "icons/48.png",
"128": "icons/128.png"
},
"content_scripts": [
{
"matches": [
"https://*.amazon.co.jp/*",
"https://*.amazon.com/*",
"https://*.amazon.ae/*",
"https://*.amazon.co.uk/*",
"https://*.amazon.it/*",
"https://*.amazon.in/*",
"https://*.amazon.eg/*",
"https://*.amazon.com.au/*",
"https://*.amazon.nl/*",
"https://*.amazon.ca/*",
"https://*.amazon.sa/*",
"https://*.amazon.sg/*",
"https://*.amazon.se/*",
"https://*.amazon.es/*",
"https://*.amazon.de/*",
"https://*.amazon.com.tr/*",
"https://*.amazon.com.br/*",
"https://*.amazon.fr/*",
"https://*.amazon.com.be/*",
"https://*.amazon.pl/*",
"https://*.amazon.com.mx/*",
"https://*.amazon.cn/*",
"https://*.primevideo.com/*"
],
"js": ["main.js"]
}
],
"browser_specific_settings": {
"gecko": {
"id": "auto-hide-next-up-card-for-amazon-prime-video@ryo-fujinone.net",
"strict_min_version": "121.0"
}
}
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
"private": true,
"type": "module",
"scripts": {
"build": "run-s build:ext build:userscript",
"build:ext": "node build.js",
"build:userscript": "rollup --config rollup.config.js",
"dev:firefox": "env-cmd -f .env.firefox web-ext run",
"dev:chrome": "env-cmd -x -f .env.chrome web-ext run -t chromium --chromium-binary=$CHROMIUM_BINARY_PATH --chromium-profile=$CHROMIUM_PROFILE_PATH",
"dev:userscript": "env-cmd -f .env.userscript rollup --config rollup.config.js --watch"
},
"devDependencies": {
"archiver": "^7.0.1",
"env-cmd": "^10.1.0",
"fs-extra": "^11.2.0",
"npm-run-all": "^4.1.5",
"rollup": "^4.13.0",
"rollup-plugin-auto-reload": "^1.0.3",
"userscript-metadata-generator": "^0.2.4",
Expand Down
Loading

0 comments on commit 23d190c

Please sign in to comment.