Ask coding questions

← Back to all posts
Import js script from github repo using link
ReallyBasic (14)

I am trying to create a modding system for a game I am making using javascript, so I am allowing users to insert a link to a GitHub repo and upload mods in a json format. There is a readme and a mod.js file in each mod, but I only need to read the mod.js file.

What would be the best way to do this?

Thanks, RBG

Answered by Coder100 (18915) [earned 5 cycles]
View Answer
Coder100 (18915)

all js files are stored in a raw place, you could directly prompt them (or you can generate them) to get that file.

on any file you can click raw

and now all your job to do is to get the URL of that raw file, and use fetch to get the contents!

ReallyBasic (14)

So if they submit a link like this one:
then how would I be able to get the url to that specific file?
To narrow down what I am looking for, is there a specific method I can write or call?

Thanks for the response!

Coder100 (18915)


you could use regexp replace maybe @ReallyBasic

ReallyBasic (14)

I figured out how to do it with the raw file. Thanks for your help! @Coder100