Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu built-in JavaScript function support #127

Open
INSide-734 opened this issue Jul 28, 2024 · 0 comments
Open

Menu built-in JavaScript function support #127

INSide-734 opened this issue Jul 28, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@INSide-734
Copy link

Is it possible to incorporate an in-built JavaScript function like those in TrMenu

And supports calling functions between menus.

The following is an example from TrMenu.

Functions:
  flash: |-
    function flash() {
      var display = new Date().getSeconds() % 2 == 0
      return display ? args[0] : "  "
    }
    flash()

In this example, we define a function called flash under Functions. This function checks if the current system time (seconds) is even and returns the passed parameter or a space accordingly.

This function can create a blinking animation effect and supports custom parameters as the blinking symbol.

The call format is ${[funcName]_[Arg1]_[Arg2]}, for example ${flash_>}.

The line var args = new Array() is automatically added above the default function, and the arguments are written into it. Thus, the parameters passed to the built-in function can be directly used in the form of the args array.

bStats:
  servers: 'vars("${bStats.query_servers_&a_&7 servers}")'
  players: 'vars("${bStats.query_players_&6_&7 players}")'
  menus: 'vars("${bStats.query_menus_&2_&7 menus}")'
  opens: |-
    function opens() {
      var data = utils.query("https://bstats.org/api/v1/plugins/5742/charts/menu_open_counts/data?maxElements=1")
      if (data.has()){
        return "&b" + data.asJson().getAsJsonArray().get(0).getAsJsonArray().get(1) + "&7"
      }
      return "&8Loading." + vars("${flash_.}") + "&7"
    }
    opens()
  query: |-
    function query() {
      var data = utils.query("https://bstats.org/api/v1/plugins/5742/charts/" + args[0] + "/data?maxElements=1")
      if (data.has()){
        return args[1] + data.asJson().getAsJsonArray().get(0).getAsJsonArray().get(1) + args[2]
      }
      return "&8Loading." + vars("${flash_.}")
    }
    query()
@BlitzOffline BlitzOffline added the enhancement New feature or request label Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants