@@ -18051,6 +18051,141 @@ if (typeof self !== 'undefined') {
1805118051 self.GMAudioHandler = GMAudioHandler;
1805218052}
1805318053
18054+ // ============================================================================
18055+ // Generated from src/background/gm-menu-handler.ts; do not edit by hand.
18056+ // Run `node scripts/generate-ts-runtime-modules.mjs` or `npm run build:bg`.
18057+ // ============================================================================
18058+
18059+ const GMMenuHandler = (() => {
18060+ const module = { exports: {} };
18061+ const exports = module.exports;
18062+ "use strict";
18063+ var __defProp = Object.defineProperty;
18064+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
18065+ var __getOwnPropNames = Object.getOwnPropertyNames;
18066+ var __hasOwnProp = Object.prototype.hasOwnProperty;
18067+ var __export = (target, all) => {
18068+ for (var name in all)
18069+ __defProp(target, name, { get: all[name], enumerable: true });
18070+ };
18071+ var __copyProps = (to, from, except, desc) => {
18072+ if (from && typeof from === "object" || typeof from === "function") {
18073+ for (let key of __getOwnPropNames(from))
18074+ if (!__hasOwnProp.call(to, key) && key !== except)
18075+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18076+ }
18077+ return to;
18078+ };
18079+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18080+
18081+ // src/background/gm-menu-handler.ts
18082+ var gm_menu_handler_exports = {};
18083+ __export(gm_menu_handler_exports, {
18084+ GMMenuHandler: () => GMMenuHandler,
18085+ GM_MENU_ACTIONS: () => GM_MENU_ACTIONS,
18086+ default: () => gm_menu_handler_default,
18087+ handleGMMenuMessage: () => handleGMMenuMessage,
18088+ isGMMenuAction: () => isGMMenuAction
18089+ });
18090+ module.exports = __toCommonJS(gm_menu_handler_exports);
18091+ var GM_MENU_ACTIONS = [
18092+ "executeMenuCommand",
18093+ "getMenuCommands",
18094+ "GM_registerMenuCommand",
18095+ "GM_unregisterMenuCommand",
18096+ "registerMenuCommand",
18097+ "unregisterMenuCommand"
18098+ ];
18099+ var GM_MENU_ACTION_SET = new Set(GM_MENU_ACTIONS);
18100+ function isGMMenuAction(action) {
18101+ return typeof action === "string" && GM_MENU_ACTION_SET.has(action);
18102+ }
18103+ async function handleGMMenuMessage(action, data = {}, sender = {}) {
18104+ switch (action) {
18105+ case "registerMenuCommand":
18106+ case "GM_registerMenuCommand": {
18107+ const scriptId = data.scriptId;
18108+ const commands = await chrome.storage.session.get("menuCommands") || {};
18109+ if (!commands.menuCommands) commands.menuCommands = {};
18110+ if (!commands.menuCommands[scriptId]) commands.menuCommands[scriptId] = [];
18111+ const existing = commands.menuCommands[scriptId].findIndex(
18112+ (command) => command.id === data.commandId
18113+ );
18114+ const cmdEntry = {
18115+ id: data.commandId,
18116+ caption: data.caption,
18117+ accessKey: data.accessKey || "",
18118+ autoClose: data.autoClose !== false,
18119+ title: data.title || ""
18120+ };
18121+ if (existing >= 0) {
18122+ commands.menuCommands[scriptId][existing] = cmdEntry;
18123+ } else {
18124+ commands.menuCommands[scriptId].push(cmdEntry);
18125+ }
18126+ await chrome.storage.session.set(commands);
18127+ return { success: true };
18128+ }
18129+ case "unregisterMenuCommand":
18130+ case "GM_unregisterMenuCommand": {
18131+ const scriptId = data.scriptId;
18132+ const commands = await chrome.storage.session.get("menuCommands") || {};
18133+ if (commands.menuCommands?.[scriptId]) {
18134+ commands.menuCommands[scriptId] = commands.menuCommands[scriptId].filter(
18135+ (command) => command.id !== data.commandId
18136+ );
18137+ if (commands.menuCommands[scriptId].length === 0) {
18138+ delete commands.menuCommands[scriptId];
18139+ }
18140+ await chrome.storage.session.set(commands);
18141+ }
18142+ return { success: true };
18143+ }
18144+ case "getMenuCommands": {
18145+ const result = await chrome.storage.session.get("menuCommands");
18146+ const allCommands = result?.menuCommands || {};
18147+ const commands = [];
18148+ const scripts = await ScriptStorage.getAll();
18149+ for (const [scriptId, menuCommands] of Object.entries(allCommands)) {
18150+ const script = scripts.find((candidate) => candidate.id === scriptId);
18151+ if (script && menuCommands) {
18152+ menuCommands.forEach((command) => {
18153+ commands.push({
18154+ ...command,
18155+ scriptId,
18156+ scriptName: script.meta?.name || "Unknown Script"
18157+ });
18158+ });
18159+ }
18160+ }
18161+ return { commands };
18162+ }
18163+ case "executeMenuCommand": {
18164+ if (sender.tab?.id) {
18165+ await chrome.tabs.sendMessage(sender.tab.id, {
18166+ action: "executeMenuCommand",
18167+ data: { scriptId: data.scriptId, commandId: data.commandId }
18168+ });
18169+ }
18170+ return { success: true };
18171+ }
18172+ default:
18173+ return { error: `Unsupported menu command action: ${action}` };
18174+ }
18175+ }
18176+ var GMMenuHandler = Object.freeze({
18177+ GM_MENU_ACTIONS,
18178+ handleGMMenuMessage,
18179+ isGMMenuAction
18180+ });
18181+ var gm_menu_handler_default = GMMenuHandler;
18182+ return module.exports.default || module.exports.GMMenuHandler || module.exports;
18183+ })();
18184+
18185+ if (typeof self !== 'undefined') {
18186+ self.GMMenuHandler = GMMenuHandler;
18187+ }
18188+
1805418189// ============================================================================
1805518190// Generated from src/background/connect-policy.ts; do not edit by hand.
1805618191// Run `node scripts/generate-ts-runtime-modules.mjs` or `npm run build:bg`.
@@ -37738,82 +37873,15 @@ async function handleMessage(message, sender) {
3773837873 scriptMetaStr: null
3773937874 };
3774037875
37741- // Register menu command (with extended options: id, accessKey, autoClose, title)
37876+ // GM menu commands and dashboard menu-command execution
3774237877 case 'registerMenuCommand':
37743- case 'GM_registerMenuCommand': {
37744- const commands = await chrome.storage.session.get('menuCommands') || {};
37745- if (!commands.menuCommands) commands.menuCommands = {};
37746- if (!commands.menuCommands[data.scriptId]) commands.menuCommands[data.scriptId] = [];
37747-
37748- // If command with same id exists, update it instead of adding duplicate
37749- const existing = commands.menuCommands[data.scriptId].findIndex(c => c.id === data.commandId);
37750- const cmdEntry = {
37751- id: data.commandId,
37752- caption: data.caption,
37753- accessKey: data.accessKey || '',
37754- autoClose: data.autoClose !== false,
37755- title: data.title || ''
37756- };
37757- if (existing >= 0) {
37758- commands.menuCommands[data.scriptId][existing] = cmdEntry;
37759- } else {
37760- commands.menuCommands[data.scriptId].push(cmdEntry);
37761- }
37762-
37763- await chrome.storage.session.set(commands);
37764- return { success: true };
37765- }
37766-
37878+ case 'GM_registerMenuCommand':
3776737879 case 'unregisterMenuCommand':
37768- case 'GM_unregisterMenuCommand': {
37769- const commands = await chrome.storage.session.get('menuCommands') || {};
37770- if (commands.menuCommands?.[data.scriptId]) {
37771- commands.menuCommands[data.scriptId] = commands.menuCommands[data.scriptId].filter(
37772- c => c.id !== data.commandId
37773- );
37774- if (commands.menuCommands[data.scriptId].length === 0) {
37775- delete commands.menuCommands[data.scriptId];
37776- }
37777- await chrome.storage.session.set(commands);
37778- }
37779- return { success: true };
37780- }
37781-
37782- // Get menu commands
37783- case 'getMenuCommands': {
37784- const result = await chrome.storage.session.get('menuCommands');
37785- const allCommands = result?.menuCommands || {};
37786- const commands = [];
37787-
37788- // Flatten commands and add script info
37789- const scripts = await ScriptStorage.getAll();
37790- for (const [scriptId, cmds] of Object.entries(allCommands)) {
37791- const script = scripts.find(s => s.id === scriptId);
37792- if (script && cmds) {
37793- cmds.forEach(cmd => {
37794- commands.push({
37795- ...cmd,
37796- scriptId,
37797- scriptName: script.meta?.name || 'Unknown Script'
37798- });
37799- });
37800- }
37801- }
37802-
37803- return { commands };
37804- }
37805-
37806- // Execute menu command
37807- case 'executeMenuCommand': {
37808- // Send to content script
37809- if (sender.tab?.id) {
37810- await chrome.tabs.sendMessage(sender.tab.id, {
37811- action: 'executeMenuCommand',
37812- data: { scriptId: data.scriptId, commandId: data.commandId }
37813- });
37814- }
37815- return { success: true };
37816- }
37880+ case 'GM_unregisterMenuCommand':
37881+ case 'getMenuCommands':
37882+ case 'executeMenuCommand':
37883+ if (typeof GMMenuHandler === 'undefined') return { error: 'GMMenuHandler not available' };
37884+ return await GMMenuHandler.handleGMMenuMessage(action, data, sender);
3781737885
3781837886 // GM_cookie API
3781937887 // chrome.cookies.* only accepts http(s) URLs. Front-validate so blob:/
0 commit comments