Last night, I decided to make a city name generator because another website I would frequently visit got knocked offline. However, once I add {import:78435dca8c2d1750fe1affd02ef2886f} (78435dca8c2d1750fe1affd02ef2886f is the file name) to the [list] folder of the code it outputs a message in the bottom right corner (see image), and it does nothing else. It lets me tap on the green box but it doesn’t do anything. Just putting all entries in will just give me an error saying the code is too big. The problem may be that all of the name entries take up six megabytes, but I really don’t know at this point. Any help appreciated.

  • VioneT@lemmy.worldM
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    5 days ago

    The problem with that is the generator 78435dca8c2d1750fe1affd02ef2886f doesn’t exist. Meaning, the page https://perchance.org/78435dca8c2d1750fe1affd02ef2886f doesn’t exist. Thus, you need to create that separate page before you can import it. You can’t use the import to open up local files.

    Here are some links on creating an Import/Export of another generator:

    If you need some help with recreating the generator, feel free to ask 😊

    • spottie@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      5 days ago

      I see where you’re going, as what I meant to upload was https://user-uploads.perchance.org/file/78435dca8c2d1750fe1affd02ef2886f.txt. Not that experienced at code, and I have no idea on how to modify the [list] section so that it makes the importer download from the file on the uploads site.

      • VioneT@lemmy.worldM
        link
        fedilink
        English
        arrow-up
        2
        ·
        edit-2
        5 days ago

        You can add this function on the lists editor:

        url = https://user-uploads.perchance.org/file/78435dca8c2d1750fe1affd02ef2886f.txt
        
        list
          [getTxtList(url)]
        
        getTxtList(url) =>
          if (!url.endsWith('.txt')) return;
          let fileName = url.split('/file/')[1].replace('.txt', '');
          if (!root[fileName]) {
            const request = new XMLHttpRequest();
            request.open("GET", url, false);
            request.send(null);
            let list = request.responseText
            list = list.split(/[\n\r]/).filter(a => a)
            root[fileName] = list
          }
          return root[fileName]
        
          • VioneT@lemmy.worldM
            link
            fedilink
            English
            arrow-up
            1
            ·
            4 days ago

            Btw, it seems to load/hang a little bit each time the button to randomize is clicked, so I’ve made an adjustment with the code, so it loads and selects an item faster, so just change the following lines:

            getTxtList(url) =>
              if (!url.endsWith('.txt')) return;
              let fileName = url.split('/file/')[1].replace('.txt', '');
              if (!root[fileName]) {
                const request = new XMLHttpRequest();
                request.open("GET", url, false);
                request.send(null);
                let list = request.responseText
                list = list.split(/[\n\r]/).filter(a => a)
                // changes
                root[fileName] = {}
                let maxPerSubset = 5000
                for(i = 0; i < Math.ceil(list.length / maxPerSubset); i++) {
                  root[fileName][i] = [... list.slice((0 + i) * maxPerSubset, (1 + i) * maxPerSubset)]
                }
              }
              return root[fileName][Object.keys(root[fileName]).selectOne] // change