Skip to content

Commit

Permalink
Enhance GM_registerMenuCommand(caption, command)
Browse files Browse the repository at this point in the history
1. the parameter caption can be a function
2. the return value of caption determinates whether to hide the eruda
   panel

This API can be improved to allow changing the style of caption.
  • Loading branch information
JingMatrix committed Sep 27, 2023
1 parent bb8c19e commit 8d2fe74
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions app/src/main/assets/eruda.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,9 @@ eruda.Resources = class extends eruda.Resources {
})
.on("click", ".eruda-command", (e) => {
const index = e.curTarget.dataset.index;
this._command[index].listener(e);
eruda.hide();
const hide = this._command[index].listener(e);
if (hide !== false) eruda.hide();
this.refreshCommand();
});
}
refresh() {
Expand All @@ -295,12 +296,13 @@ eruda.Resources = class extends eruda.Resources {
refreshCommand() {
this._command = ChromeXt.commands.filter((m) => m.enabled);
const commands = this._command
.map(
(cmd, index) =>
`<span data-index=${index} class="${c("command")}">${
cmd.title
}</span>`
)
.map(function (cmd, index) {
let title = cmd.title.toString();
if (typeof cmd.title == "function") {
title = cmd.title(index);
}
return `<span data-index=${index} class="${c("command")}">${title}</span>`;
})
.join("");
this._$command.html(
`<h2 class="${c("title")}">UserScript Commands</h2>` +
Expand Down

0 comments on commit 8d2fe74

Please sign in to comment.