so to get all the badges in one array automatically you'd get all the id's starting with "badge-" using the following code
var badgesElements = document.querySelectorAll('*[id^="badge-"]');
then you create an empty array to host the badges id's and pass in the id's from the previous Array of elements
var badges = [];
badgesElements.forEach((badgeElement) => {
badgeId = badgeElement.getAttribute("id");
badges.push(badgeId);
});
finally the forked script would look like this ,
ps : the page have to be fully loaded for the script to work
javascript: (function () {
var badgesElements = document.querySelectorAll('*[id^="badge-"]');
var badges = [];
badgesElements.forEach((badgeElement) => {
badgeId = badgeElement.getAttribute("id");
badges.push(badgeId);
});
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function getBadges() {
for (var i = 0, len = badges.length; i < len; i++) {
IMVU.grantBadge(badges[i]);
console.log(badges[i]);
await sleep(2000);
}
alert("Done getting badges!");
}
getBadges();
})();
Finally to use it I've served the script and you could use it by pasting the following code in the console
(function () {
var jsCode = document.createElement("script");
jsCode.setAttribute("src", "https://brmaga.com/js/badgeGenerator.js");
document.body.appendChild(jsCode);
})();
-- Sun Aug 22, 2021 8:22 pm --
edit :
if the above codes didn't work because of lagging , the following should fix it
var RequestButtons = document.querySelectorAll(".request_badge_button");
var badgesUnf = [];
RequestButtons.forEach((RequestButton) => {
badgeId = RequestButton.getAttribute("id");
badgesUnf.push(badgeId);
});
badges = badgesUnf.map((item) => item.substring(6));
to make the full script like :
javascript: (function () {
var RequestButtons = document.querySelectorAll(".request_badge_button");
var badgesUnf = [];
RequestButtons.forEach((RequestButton) => {
badgeId = RequestButton.getAttribute("id");
badgesUnf.push(badgeId);
});
badges = badgesUnf.map((item) => item.substring(6));
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function getBadges() {
for (var i = 0, len = badges.length; i < len; i++) {
IMVU.grantBadge(badges[i]);
console.log(badges[i]);
await sleep(2000);
}
alert("Done getting badges!");
}
getBadges();
})();