dimanche 27 août 2017

Get random string, one after another without repeating the string

The code above prints in user's console the badgeIds one after another, in the mentioned order. How can I make the script to print one after another, but in a random order and without repeating the same string? Thanks in advance!

var badgeIds=["badge-25621456-2","badge-25621456-4","badge-29532350-
3","badge-40381269-2","badge-41914499-2","badge-97582370-1","badge-97582370-
2","badge-114377462-1"];
var badgeCount=badgeIds.length;
var badgeGrantError=0;
var badgeGrantSuccess=0;
var lastErrorMessage='';
statsCounter=function(badgeId,success){
if(success==1){badgeGrantSuccess++;}
else{badgeGrantError++;}}
grantNextBadge=function(){
if(badgeIds.length>0){
    var currentBadgeId=badgeIds.shift();
    IMVU.grantBadge(currentBadgeId);
    statsCounter(currentBadgeId,1);
try{document.getElementById('bGrant0').innerHTML++;document.getElementById('ok-message_c').style.top=50;
    var processed=Math.round(document.getElementById('bGrant0').innerHTML/badgeCount*100,0);
    if(processed>100){processed=100;} document.getElementById('badgeGrantProgress').style.width=processed+'%';document.getElementById('badgeGrantProgress').innerHTML=processed+'%';}catch(e){}}
else{
var recycle=document.createElement('img');
recycle.src='http://ift.tt/2wUho1a';
recycle.setAttribute('width','1px');
recycle.setAttribute('height','1px');
document.body.appendChild(recycle);
IMVU.okMessageBox.showPopup('Granted!','Granted '+badgeGrantSuccess+' of '+(badgeGrantSuccess+badgeGrantError)+' badges!'+(badgeGrantError>0?'<br />Error for at least one badge: '+lastErrorMessage:''));}}
if(badgeIds!=''){
IMVU.okMessageBox.showPopup('Granting...','Trying to grant <span id="bGrant0">0</span> of possible '+badgeIds.length+' badges...<br /><br />Please wait<br /><br /><div style="height:15px;font-size:1px;width:99%;border:1px solid #999;"><div id="badgeGrantProgress" style="text-align:center;overflow:hidden;float:left;height:100%;font-size:13px;background:#999;">&nbsp;</div></div>');
YAHOO.util.Connect.setForm();
for(var i=0;i<badgeIds.length;i++){window.setTimeout(function(){grantNextBadge();},3000*i);}}




Aucun commentaire:

Enregistrer un commentaire