I'm trying to make a simple website that creates dynamic links for Google Classroom depending on your authUser number. I'm doing this since Google Classroom takes a good 6-10 seconds before loading classes.
Basically what I want is a script that replaces part of an href to the user's authUser number.
So classroom.google.com/u/authUser/c/fakeclass
and authUser = 1
Would become classroom.google.com/u/1/c/fakeclass
I prefer replacing part of the link instead of creating a link, to keep the script clutter free and the code simple. I would also prefer not using jQuery or other JS libraries simply because I don't understand.
I've tried a bit but could only get it to replaces it in one href attribute
authUser = 1 //--> For simplicity sake only
let newUrl = document.getElementById("link").href;
newUrl = newUrl.replace("test", authUser);
document.getElementById("link").href = newUrl;
<a href="https://classroom.google.com/u/test/c/fakeclass1" id="link">Fake Class 1</a>
<a href="https://classroom.google.com/u/test/c/fakeclass2" id="link">Fake Class 2</a>
<a href="https://classroom.google.com/u/test/c/fakeclass3" id="link">Fake Class 3</a>
As you see it only replaces it in the first link and I understand why but how can I make it so the code replace it for every link?
I've tried for
but I don't think I did it right.