first web extension version
This commit is contained in:
3
web-extension/cl/.gitignore
vendored
Normal file
3
web-extension/cl/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules/*
|
||||
dist/*
|
||||
web-ext-artifacts/*
|
||||
BIN
web-extension/cl/icons/img-48.png
Normal file
BIN
web-extension/cl/icons/img-48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 193 B |
26
web-extension/cl/manifest.json
Normal file
26
web-extension/cl/manifest.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "Champs-Libres Helper",
|
||||
"version": "0.4",
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
"id": "helper@champs-libres-coop",
|
||||
"strict_min_version": "143.0"
|
||||
}
|
||||
},
|
||||
|
||||
"description": "Aide pour les champs-libres",
|
||||
|
||||
"icons": {
|
||||
"48": "icons/img-48.png"
|
||||
},
|
||||
|
||||
"permissions": ["menus", "nativeMessaging", "tabs"],
|
||||
"host_permissions": [
|
||||
"*://*/*"
|
||||
],
|
||||
"background": {
|
||||
"scripts": ["dist/background/background.js"],
|
||||
"type": "module"
|
||||
}
|
||||
}
|
||||
6194
web-extension/cl/package-lock.json
generated
Normal file
6194
web-extension/cl/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
21
web-extension/cl/package.json
Normal file
21
web-extension/cl/package.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "web-extension",
|
||||
"version": "0.4.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"check": "tsc --noEmit",
|
||||
"build": "tsc",
|
||||
"package": "tsc && web-ext build --overwrite-dest"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"type": "commonjs",
|
||||
"devDependencies": {
|
||||
"@types/firefox-webext-browser": "^143.0.0",
|
||||
"typescript": "^5.9.3",
|
||||
"web-ext": "^7.6.0"
|
||||
}
|
||||
}
|
||||
68
web-extension/cl/src/background/background.ts
Normal file
68
web-extension/cl/src/background/background.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import {isOutputMessageError, isOutputMessageSuccess} from "./types.js";
|
||||
|
||||
const projects: { name: string, slug: string }[] = [
|
||||
//{name: "test (dev only)", slug: "test"},
|
||||
{name: "Adminsys", slug: "champs-libres-adminsys"},
|
||||
{name: "Be-Arbres", slug: "be-arbres"},
|
||||
{name: "Chill", slug: "chill"},
|
||||
{name: "Chill > AMLI", slug: "amli"},
|
||||
{name: "Chill > Haute-Vienne", slug: "haute-vienne"},
|
||||
{name: "Chill > Petits Chills", slug: "petits-chill"},
|
||||
{name: "Chill > Samu Social", slug: "samu-social"},
|
||||
{name: "Chill > Vendée", slug: "vendee"},
|
||||
{name: "Osiris", slug: "osiris"},
|
||||
{name: "Raponmap", slug: "raponmap"}
|
||||
]
|
||||
|
||||
for (const project of projects) {
|
||||
browser.menus.create(
|
||||
{
|
||||
id: "cl-issue-2-wp-" + project.slug,
|
||||
title: project.name,
|
||||
contexts: ["link"],
|
||||
type: "radio"
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
browser.menus.onClicked.addListener(async function(info, tab) {
|
||||
console.log("info", info);
|
||||
|
||||
if (typeof info.menuItemId === "string") {
|
||||
console.log("menuItemId", info.menuItemId);
|
||||
if (info.menuItemId.startsWith("cl-issue-2-wp-")) {
|
||||
console.log("start with cl-issue-2-wp-");
|
||||
const slug = info.menuItemId.replace("cl-issue-2-wp-", "");
|
||||
console.log("slug", slug);
|
||||
if (typeof info.linkUrl === "string") {
|
||||
await convertToWorkPackage(slug, info.linkUrl);
|
||||
} else {
|
||||
console.error("linkUrl is not a string");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
async function convertToWorkPackage(slug: string, url: string): Promise<void> {
|
||||
const message = {
|
||||
type: "Issue2Work",
|
||||
url: url,
|
||||
project: slug,
|
||||
};
|
||||
try {
|
||||
const sending: unknown = await browser.runtime.sendNativeMessage("cl_cli", message);
|
||||
if (isOutputMessageError(sending)) {
|
||||
console.error("error while handling message", sending.message);
|
||||
} else if (isOutputMessageSuccess(sending)) {
|
||||
try {
|
||||
await browser.tabs.create({
|
||||
url: sending.data.created,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("error while creating new tab", error);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("error while handling message", error);
|
||||
}
|
||||
}
|
||||
44
web-extension/cl/src/background/types.ts
Normal file
44
web-extension/cl/src/background/types.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
export type OutputMessageError = {
|
||||
result: "Error",
|
||||
message: string,
|
||||
}
|
||||
|
||||
export type OutputIssue2Work = {
|
||||
type: "Issue2Work";
|
||||
created: string;
|
||||
}
|
||||
|
||||
export type OutputMessageSuccess = {
|
||||
result: 'Ok'
|
||||
data: OutputIssue2Work;
|
||||
}
|
||||
|
||||
export type OutputMessage = OutputMessageError | OutputMessageSuccess;
|
||||
|
||||
export function isOutputMessage(value: unknown): value is OutputMessage {
|
||||
return isOutputMessageError(value) || isOutputMessageSuccess(value);
|
||||
}
|
||||
|
||||
export function isOutputMessageError(value: unknown): value is OutputMessageError {
|
||||
return (
|
||||
typeof value === 'object' &&
|
||||
value !== null &&
|
||||
'result' in value &&
|
||||
value.result === 'Error' &&
|
||||
'message' in value &&
|
||||
typeof value.message === 'string'
|
||||
);
|
||||
}
|
||||
|
||||
export function isOutputMessageSuccess(value: unknown): value is OutputMessageSuccess {
|
||||
return (
|
||||
typeof value === 'object' &&
|
||||
value !== null &&
|
||||
'result' in value &&
|
||||
value.result === 'Ok' &&
|
||||
'data' in value &&
|
||||
typeof value.data === 'object' &&
|
||||
value.data !== null
|
||||
);
|
||||
}
|
||||
19
web-extension/cl/tsconfig.json
Normal file
19
web-extension/cl/tsconfig.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES6",
|
||||
"module": "ESNext",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"moduleResolution": "bundler",
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"declaration": false,
|
||||
"types": [
|
||||
"firefox-webext-browser"
|
||||
]
|
||||
},
|
||||
"include": ["./src/**/*.ts"],
|
||||
"exclude": ["./node_modules", "dist"]
|
||||
}
|
||||
Reference in New Issue
Block a user