Spyke

Syndicated from the fediverse. Read and engage on the original instance.

View original on lemmy.world
perchance·Perchance - Create a Random Text GeneratorbyAdComfortable1514

[Help] How to check if generator name exists

Hello y'all,

Does anyone know how to check if a perchance generator name exists on perchance?

Context:

I've added a feature to allow users to load their own datasets into the fusion-gen. The code is above, but the feature itself looks like this:

I'd like to be able to check if the string matches a generator that exists on perchance. Does anyone know the name of that function?

View original on lemmy.world
2

2 replies

lemmy.world

You can possibly use the API that retrieves the generator's stats for the generator cards. Though you need to make the function an async function.

async loadUserDataset() => // Need to change it to an Async function to wait for the data to be retrieved.
  ...
  if(userDataset != "") {
    let result = await fetch("/api/getGeneratorStats?names="+userDataset).then(r => r.json()); // Gets the Generator Stats
    let gens = result.data; // Returns an Array of Generator
    if (gens.length > 0) { // If there is data
      document.userDataset = userDataset;
    } else { // if not
      alert('Perchance Page Not Found');
      document.userDataset = 'template-fusion-generator-dataset' // or any default pages
    }
  }
  ...
  update() // to refresh the display, or you can use element.innerHTML = this new value
4

I see. Thanks! I can use this.

Since its async , I think what I'll do is use the code to make a wrapper function for the dynamic import plugin, something like :

myDynamicImportWrapper( "blahblah" , default = "template-fusion-generator-dataset" )

1

You reached the end

[Help] How to check if generator name exists | Spyke