Stars on the weapon icons - Better Battlelog Forums #2050

Sitemap
Topicstarter
Hi. I have idea for new feature for battlelog. I would do that myself (and I still want), but I'm not that good at editing existing sites (i can write one, but not so much edit from the outside). Here's my idea:

http://imageshack.us/a/img545/2224/blogstars.png


I showed it only for 3 weapons, but i want it on each in every class. I wrote some script myself, but i need a little help to move on. At first, i want to write number of kills on every weapon icon. I wrote that:

var handler = function(){
var data = BBLog.getCachedJsonRequest("weaponsPopulateStats", "lastFirst", "json");
if(data){
var items = $("#profile-stats-weapons-secondary-column profile-stats-unlock-progression-kit-items:first div.profile-stats-unlock-progression-kit-item a");

for(i in data.data.mainWeaponStats){
var weapon = data.data.mainWeaponStats[i];
var weaponTr = items.filter("[href*='iteminfo/"+weapon.slug+"/']").closest("div").not("[data-shots]");
if(weaponTr.size()){
weaponTr.attr("data-shots", true);
var td = weaponTr.find("div.last").prev();
td.find(".profile-stats-unlock-progression-kit-items").addClass("bblog-stars");
var html = $(
''+weapon.kills+''
);
td.find(".profile-stats-unlock-progression-kit-items").append(html);
}
}
}
}

BBLog.bindDomChange(handler);
handler();


But it won't work. I would need a debugger for JS, "var_dump" or "print_r" from PHP would do that, but JS doesn't have that. :( By adding my .JS file as plugin to BBlog i can't debug my variables with Firebug, so at that moment I'm blind and I need a little help. Could anyone help me?
console.log() is your debug statement, very similar to var_dump in php.
Topicstarter
Thanks for feedback! I knew console.log(), console.debug(), etc., but I thought that it only works in my browser, not inside the script. That helped me a lot!

First thing I need to know is if you'd consider to implement that in official BBlog plugin? If not, I'll public that as separate plugin for BBlog.

I worked few hours and i managed to develop that:

http://imageshack.us/a/img411/7519/bblogstars2.png


As you can see it's working, but it needs several fixes:
1. Weapons as M16A4, M4 and M320's have no stars, because they "share" kills with M16A3, M4A1 and the M320. Do I have to do a special "if's" for these weapons or it's easier to implement?
2. Little stars have bug with z-index (weapon has smaller z-index value than the star, but it's still on the top). I think the DOM tree should be build differently to fix that.
3. CSS styles could be more esthetic, but I'm not an artist and it suits me. :P
4. The code needs (i think) a little optimization, because method "BBLog.getCachedJsonRequest" with "weaponsPopulateStats" argument requests a lot of stats the plugin doesn't need.

Here's the code:
/**
* The plugin is showing your stars at every gun icon.
*
* @author Humanoss
* @version 1.0
* @date 20.09.2012
* @url
http://google.com

*/

var handler = function(){
var data = BBLog.getCachedJsonRequest("weaponsPopulateStats", "lastFirst", "json");
if(data){
var items = $("#profile-stats-weapons-secondary-column div.profile-stats-unlock-progression-kit-item a");
for(i in data.data.mainWeaponStats){
var weapon = data.data.mainWeaponStats[i];
var weaponTr = items.filter("[href*='iteminfo/"+weapon.slug+"/']").closest("div").not("[data-shots]");
if(weaponTr.size()){
weaponTr.attr("data-shots", true);
var html = $(
''+Math.floor(weapon.kills/100)+''
);
weaponTr.children("div.progress").append(html);
}
}
}
}

BBLog.bindDomChange(handler);
handler();

And link:
http://www.sobol6803.yoyo.pl/bbstars.js
Looks pretty neat, i'll think about a integration.
Topicstarter
Thanks! I'm looking forward to it!

It needs a different position in DOM tree, because i found 2 more bugs:
1. When someone doesn't have a weapon unlocked, the star and number are repositioned (the divs the script is making shouldn't be in "#progress" div.
2. When someone has more than 9 stars, the star is covering the number. "Float" in CSS should do the work.

Would you want me to fix all that stuff or you'll take care of it on your own?
No, i already have done some fixes.
Topicstarter
Well, could I get a little peak at what you've done? :P And when we can expect the next update?
Update out now.
Topicstarter
I've found bug with z-index:

http://imageshack.us/a/img842/9458/bblogstars.png


And it could be positioned in right bottom corner, because it's "flying" now.
Already reported.
http://getbblog.com/viewtopic.php?f=3&t=778

About flying, i saw it. It's just a firefox issue. Also on Todo.