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?

  • VioneTM
    link
    English
    44 months ago

    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
    
    • @AdComfortable1514OP
      link
      English
      14 months ago

      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” )