Cobrastyle for karmapolice

Karmad***p


I had to sit here deep in the karma hole. As a beginner, for me it was a very emotional experience, karma wanted to track every second. To do this it is most convenient to use firefox extension called habraholic (by Semenov, thank you very much, good man!). But I'm somehow not very satisfied with the indicators — black faceless, harsh (to me) numbers.

I wanted a holiday, and then came across topic for writing extensions for Firefox. Villages to understand that as a Yes...

/ >

habraholic.xpi


.xpi is .zip. Rename and unpack. The resulting extension in the form of folders and files. Everything you need to edit is in the folder ../chrome/content

Xul label, chrom


For a start, found that the karma rating is displayed in the status bar as a single line. And have to paint in different colors. So it is necessary to break the label three label (karma, rating, position). Open the file panel.the xul that describes our facilities, and add to the already specified label two more, with unique names:

<label id="habraholickarma" value="Habrahabr!" tooltiptext="Click to configure." onclick="habraholicLeftClick(event)"/>
<label id="habraholicrating" value="Habrahabr!" tooltiptext="Click to configure." onclick="habraholicLeftClick(event)"/>
<label id="habraholicposition" value="Habrahabr!" tooltiptext="Click to configure." onclick="habraholicLeftClick(event)"/>


* This source code was highlighted with Source Code Highlighter.


I just copied the line three times, so I have not set the user name in the status bar says "Habrahabr! Habrahabr! Habrahabr!". Completely fits my mood for the last three days.

Harestail


To add settings that will enable/disable Harstel, you need to open the prefs file.the xul that describes the settings window. Added to the checkbox "do Not show the position in the ranking of" another one:

<checkbox id="habraholic-hideRatingPosition" preference="habraholic-hideRatingPosition-pref" label="do Not show in the rankings"/>
<checkbox id="habraholic-habrastyle" preference="habraholic-habrastyle-pref" label="Habra-style indicators,"/>


* This source code was highlighted with Source Code Highlighter.


Summary:


Was shocked on how simple it is.

CSS? CSS!


So, we have three text boxes — labels are shown in black font size of 13 points. That's what we decided to rule. We will apply styles to each label your. Only to apply the style, it is necessary to know which style you want to apply. I in finding this knowledge very useful extension for FF CSS Viewer. After installation, just hover a mouse over page elements and it shows what the element styles applied to them. Go to Habro...

Karma: color #66CC66 size 36px, font-family Verdana,sans-serif
Rating: color #3399FF, size 36px, font-family Verdana,sans-serif
Position: color #777777, size 14px, font-family Verdana,sans-serif

Now I have all the text sadly here is this:

Item: color black, size 13px, font-family Verdana,sans-serif

In order to know — on or off the style in the settings, add a function habraholicIsHabraStyle(), which copies one to one function habraholicIsRatingPositionHidden(), with the exception of the ID of the control whose value it returns.

Then just immediately after displaying the text labels apply styles to these labels:

if(habraholicIsHabraStyle())
document.getElementById("habraholickarma").style.color = "#66CC66";
document.getElementById("habraholickarma").style.fontSize = "36px";
document.getElementById("habraholicposition").style.fontFamily = "Verdana,sans-serif";
} else {
document.getElementById("habraholickarma").style.color = "black";
document.getElementById("habraholickarma").style.fontSize = "13px";
}


* This source code was highlighted with Source Code Highlighter.


How many decimal places?


Everything seems to be fine, but something is not right. Habra api returns the needed values not in the format. For example I had a "-10 -57.6", and in my characetr have all different and beautiful: "-10,00 -57,60". I'm an engineer, and not used with zeros to lose, even if they are right. In General, add a function that gets the values obtained by point, adds a comma instead of a period and one or two zeros. For accuracy.

function addCommas(nStr)
{
nStr += ";
var x = nStr.split('.'); //split the string at the point
var x1 = x[0]; //integer part of the number
if (x.length - 1) if (!(x[1].length - 1)) x[1] += '0'; //if the number was the integer and the decimal part and the fraction consisted of only one digit, attributed to fractional parts rear toe
var x2 = x.length > 1 ? ',' + x[1] : ',00'; //If there is a fractional part - to write two zeros after the decimal point, if there was - write it
return x1 + x2;
}


* This source code was highlighted with Source Code Highlighter.


That's all:


the question


Why in the example did not work method .toFixed, for example x.toFixed?
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Fresh hay from the cow, or 3000 icons submitted!

Knowledge base. Part 2. Freebase: make requests to the Google Knowledge Graph

Group edit the resources (documents) using MIGXDB