1
0
Fork 0
cookiedb/userscript build.ts

130 Zeilen
3.2 KiB
TypeScript

import * as esbuild from "https://deno.land/x/esbuild@v0.23.0/mod.js";
class userjs {
name: string;
namespace: string;
version: string;
description: string;
author: string[];
source: string;
run_at: string;
grant: string[];
match: string[];
constructor(
name: string,
namespace: string,
version: string,
description: string,
author: string[],
source: string,
run_at:
| "document-start"
| "document-body"
| "document-end"
| "document-idle"
| "context-menu" = "document-end",
grant: string[] = [],
match: string[],
) {
this.name = name;
this.namespace = namespace;
this.version = version;
this.description = description;
this.author = author;
this.source = source;
this.run_at = run_at;
this.grant = grant;
this.match = match;
}
toString(): string {
const b = ["// ==UserScript=="];
b.push(`// @name ${this.name}`);
b.push(`// @version ${this.version}`);
b.push(`// @source ${this.source}`);
b.push(`// @description ${this.description}`);
for (const author of this.author) {
b.push(`// @author ${author}`);
}
b.push(`// @run-at ${this.run_at}`);
if (this.grant.length == 0) {
b.push(`// @grant none`);
}else {
for (const grant of this.grant)
b.push(`// @grant ${grant}`);
}
for (const match of this.match) {
b.push(`// @match ${match}`);
}
b.push("// ==/UserScript==");
return b.join("\n");
}
}
async function userscript_build(prefix: string, metadata: userjs) {
console.log(`Building ${prefix}`);
await esbuild.build({
outfile: `userscripts/${prefix}.user.js`,
bundle: true,
charset: "utf8",
banner: {
"js": metadata.toString(),
},
entryPoints: [`userscripts/${prefix}.ts`],
minify: true,
platform: "browser",
target: "es2022",
});
}
await userscript_build(
"girlgenius",
new userjs(
"Girlgenius https fix",
"https://sebastian-tobie.de/",
"0.2",
"converts http to https urls",
["Sebastian Tobie"],
"https://gitea.sebastian-tobie.de/sebastian/cookiedb/raw/branch/stable/userscripts/girlgenius.user.js",
"document-body",
[],
[],
),
);
await userscript_build(
"kobo_easy_archive",
new userjs(
"Kobo library easy archive",
"https://sebastian-tobie.de/",
"0.1",
"Helps with archiving kobo books",
["Sebastian Tobie"],
"https://gitea.sebastian-tobie.de/sebastian/cookiedb/raw/branch/stable/userscripts/kobo_easy_archive.user.js",
"document-idle",
[],
[
"https://www.kobo.com/de/de/library/books",
"https://www.kobo.com/de/de/library/books?*",
],
),
);
await userscript_build(
"thalia-filter",
new userjs(
"Thalia Filter",
"https://sebastian-tobie.de/",
"0.2",
"Filters out unwanted books",
["Sebastian Tobie"],
"https://gitea.sebastian-tobie.de/sebastian/cookiedb/raw/branch/stable/userscripts/girlgenius.user.js",
"document-end",
["GM_registerMenuCommand"],
[
"https://www.thalia.de/kategorie/*",
"https://www.thalia.de/kategorie/*/",
"https://www.thalia.de/kategorie/*?*",
"https://www.thalia.de/ebook/kategorien/*/neuheiten",
],
),
);
Deno.exit();