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