BlipLib is a hopefully rather easy to use library for better controlling the Browser Action badges.
You are able to scroll and blink text and change the background colour of the badge through simple format commands.
If you're familiar with C's printf, it's somewhat similar.
Your format string is normal text, with actions intermixed as desired, using a starting and ending % sign.
For example this is the string I used in Carapass Auction Watcher: "Watching %% auction%%. Next ends in %w4b3%"
As you can imagine, %% doesn't have any commands in it. It just means you want to insert unformatted information there. Where the last one has two commands. w is the width command, meaning the inserted data should be formatted to be at least that long. So if "www" was passed, it would be adjusted to " www". There are some commands to adjust how this formatting is done which I'll explain in a moment. Secondly, b is the blink command. The 3 is how many times it should blink. When the message is scrolled to the beginning of the data inserted at this point, it will pause scrolling and blink the message the given number of times before continuing.
So the basic process of using this is to first set it up by passing the message and two optional parameters. For example:
Then you need to set up your interval that updates the blip, for example:Code:BlipSetup("Watching %% auction%%. Next ends in %w4b3%");
The idea here is just to only show the badge if it there's data in the list array, and only scroll the text if the user has it set to. If the user turned scrolling off it just shows ctl instead of scrolling it. Also as you can see I set it to update every 500 ms (0.5 seconds).Code:setInterval(function(){ if(list.length>0){ if(scrolling){ var l=list.length; BlipUpdate(l,(l>1?"s":""),(ctl==""?"????":ctl)); }else{ chrome.browserAction.setBadgeText({"text":ctl}); } } else chrome.browserAction.setBadgeText({"text":""}); },500);
BlipUpdate is the important function here, this is the function that updates the badge text to scroll or blink. Here is when you pass the information that goes into the formatting segments (the % surrounded parts).
Currently this data is only formatted and inserted when it begins scrolling the message, so if you have data that's changing, the update won't be reflected until the message restarts. (I wanna fix this later.)
Here's the remainder of the documentation:
BlipSetup(message[, trailing space][, direction]);
* message * The message to scroll including format markers described below.
* trailing space * (Optional) NOT WORKING AT THE MOMENT
* direction * (Optional) Direction to scroll. "l" for left, "r" for right. Default is left.
setInterval(function(){BlipUpdate(...)},often);
* ... * Variables to be formatted and placed into the string.
* often * How often, in milliseconds, you want the badge to update (ie. scroll the text).
Message Format:
Use % to surround formatters
Format is: action[param]action[param]...
Actions are only one leter, and params can either but numbers or one letter.
Actions:
* l * No parameters. Left justifies text. Default justification character is space.
* w * Width. Will expand string to this many characters if it's shorter. Does not truncate.
* j * Sets the justification character.
* b * Pauses text here to blink it the given number of times. Text is paused at the beginning.
* p * The input is actually a float, this sets the precision to the given number of decimal places.
* + * No parameters. The input is actually a number, shows + sign if it is positive. (Always shows negative.)
* c * Change badge's background colour to this when it arrives here. Parameter is decimal RRRGGGBBB.
Example: 010255255 is the same as the HTML colour code #0affff
Download link: http://logicplace.com/pc/projects/chrome/bliplib.js
Feel free to ask any questions.
EDIT: Forgot to mention, this is intended to be used from a Background Page.


LinkBack URL
About LinkBacks



Reply With Quote
.
. 

