Created
November 16, 2012 16:10
-
-
Save kkotaro0111/4088576 to your computer and use it in GitHub Desktop.
Runnig this function, Cheering other produser.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//First: > mobamas.startById( < my id > ); | |
//ajax called twice. When finished it... | |
// | |
//Second: > mobamas.scanUserList(); | |
//ajax called many times. When finished it... | |
// | |
//Third: > mobamas.cheeringForAll(); | |
//Cheer! Cheer! | |
var Charactor = function(uid){ | |
this.uid = uid; | |
this.profile = "http://sp.pf.mbga.jp/12008305/?guid=ON&url=http%3A%2F%2F125.6.169.35%2Fidolmaster%2Fprofile%2Fshow%2F" + uid + "%3Frnd%3D"+mobamas.makeRand(); | |
this.cheerlist1 = "http://sp.pf.mbga.jp/12008305/?guid=ON&url=http%3A%2F%2F125.6.169.35%2Fidolmaster%2Fcheer%2Fcheers_list%2F1%2F"+uid+"%3Frnd%3D"+mobamas.makeRand(); | |
this.cheerlist2 = "http://sp.pf.mbga.jp/12008305/?guid=ON&url=http%3A%2F%2F125.6.169.35%2Fidolmaster%2Fcheer%2Fcheers_list%2F1%2F"+uid+"%2F10%3Frnd%3D"+mobamas.makeRand(); | |
this.cheeringUrl = "http://sp.pf.mbga.jp/12008305/?guid=ON&url=http%3A%2F%2F125.6.169.35%2Fidolmaster%2Fcheer%2Findex%2F"+uid+"%2F1%3Frnd%3D"+mobamas.makeRand(); | |
}; | |
Charactor.prototype = { | |
constructor: "Charactor", | |
cheerscheck: function(){ | |
console.info("check cheer list by " + this.uid); | |
mobamas.getUserIdsFromCheerList(this.cheerlist1); | |
mobamas.getUserIdsFromCheerList(this.cheerlist2); | |
this.checked = true; | |
}, | |
cheering: function(){ | |
var t = this; | |
$.ajax({ | |
url: t.cheeringUrl, | |
type: "GET", | |
success: function(data, status, xhr){ | |
console.log("Success Cheering for " + t.uid + " !"); | |
} | |
}); | |
} | |
}; | |
var mobamas = { | |
cheeringForAll: function(){ | |
var l = this.livingIds; | |
var targetOfCheerID = []; | |
var counter = 500; | |
for( chrid in l){ | |
if(!l[chrid].cheered){ | |
targetOfCheerID.push(chrid); | |
} | |
} | |
function cheercheer(){ | |
var user = targetOfCheerID.shift(); | |
if(typeof user === "undefined"){ | |
clearInterval(tid); | |
return 0; | |
} | |
console.debug("Cheer kouho : " + user); | |
l[user].cheering(); | |
l[user].cheered = true; | |
counter--; | |
if(counter <= 0){ | |
clearInterval(tid); | |
} | |
} | |
function randCaller(){ | |
setTimeout(cheercheer, (Math.random() * 4000)); | |
} | |
var tid = setInterval(randCaller, 2000); | |
}, | |
startById: function(uid){ | |
this.livingIds[uid] = new Charactor(uid); | |
this.scanUserList(); | |
}, | |
scanUserList: function(){ | |
var l = this.livingIds; | |
for( chrid in l){ | |
if(!l[chrid].checked){ | |
l[chrid].cheerscheck(); | |
} | |
}; | |
}, | |
makeRand: function(){ | |
return (Math.random() * 1000000000)<<0 | |
}, | |
getUserIdsFromCheerList: function(cheerlisturl){ | |
var t = this; | |
if( cheerlisturl.match(/cheers_list%2F/)){ | |
$.ajax({ | |
url: cheerlisturl, | |
type: "GET", | |
success: function(data, status, xhr){ | |
var anchors = $(data).find("#top").find("a[href*='profile']"); | |
console.log(anchors); | |
if(anchors.length > 0){ | |
var ids = {}; | |
anchors.each(function(){ | |
var id = t.getIdFromProfileUrl(this); | |
ids[id] = false; | |
}); | |
console.log(ids); | |
t.mergeIds(ids); | |
} | |
} | |
}); | |
} | |
}, | |
getIdFromProfileUrl: function(url){ | |
//prifile url is | |
//http://sp.pf.mbga.jp/12008305/?guid=ON&url=http%3A%2F%2F125.6.169.35%2Fidolmaster%2Fprofile%2Fshow%2F" + uid + "%3Frnd%3D000000000"; | |
var reg = new RegExp("show%2F([0-9]+)"); | |
var id = reg.exec(url); | |
if(!id){ | |
return undefined; | |
} | |
console.log("dripped id : " + id[1]); | |
return id[1]; | |
}, | |
mergeIds: function(ids){ | |
for(var key in ids){ | |
console.info("Merging id : " + key); | |
if(key in this.livingIds){ | |
var chr = this.livingIds[key]; | |
chr.checked = chr.checked || ids[key] || false; | |
}else{ | |
var chr = new Charactor(key); | |
chr.checked = false; | |
this.livingIds[key] = chr; | |
} | |
} | |
}, | |
counter: function(){ | |
var c = 0; | |
for( var i in this.livingIds){ | |
c++; | |
} | |
console.log(c); | |
}, | |
livingIds: {} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment