How do I access the same JSON file from two different TamperMonkey scripts?

I have two TamperMonkey scripts that each operate on a different page of the same website to perform inventory management tasks (for anyone familiar with Neopets, one script runs on the Safety Deposit page and the other runs on the Quick Stock page). Originally each script had its own list of items, but I figured it would be much better if both of them could access a single JSON list.

Unfortunately, it turned out to be way more difficult than I thought to get that to work. As far as I can tell, TamperMonkey doesn’t allow one script to access the storage of another, and there isn’t a “general storage” area where you can put files for all scripts to access. So my question is, can I make a JSON file accessible to (and editable by) multiple scripts?

Some things I’ve already tried / am aware of as possible solutions but ruled out:

  • I already tried creating a local JSON file and accessing that, but as far as I can tell you need to actually host that file on something like WAMP or else Chrome won’t allow the access (newbie mistake I guess, lol). That won’t work for me though, because I’m planning to distribute these scripts to other players, and the majority of them don’t have the knowhow to run a server on their PC.

  • I know I can create a Pastebin or Gist file and access that, but I won’t be able to edit the values using the TM script, which is semi-important since I’m doing inventory management and I’m trying to avoid doing that manually as much as possible.

  • I don’t want to just combine the two TM scripts into one, because they run on different webpages and perform different tasks. The only thing they have in common is this central database of items I’m trying to set up. If there literally is no other solution then I guess I can combine them and just add an if statement that checks what the current URL is, but I was hoping there would be a better and more maintainable way of doing this.

Leave a Comment