Results 1 to 5 of 5

This is a discussion on [NewLib] bliplib within the Plugins Development section, part of the Chrome Plugins category: BlipLib is a hopefully rather easy to use library for better controlling the Browser Action badges. You are able to ...


  1. #1
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default [NewLib] bliplib

    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:
    Code:
    BlipSetup("Watching %% auction%%. Next ends in %w4b3%");
    Then you need to set up your interval that updates the blip, for example:
    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);
    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).

    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.
    Last edited by Waha; 02-13-2010 at 08:47 AM.
    ~ Projects ~
    Specialized: Carapass Auction Watcher, Kongregate Chat
    Libraries: bliplib
    Tools: manifest syntax highlighting & snippits
    ~ Happy to make extensions for pay too ;D ~
    Portfolio: Search and Share

  2. #2
    PAEz's Avatar
    PAEz is offline Moderator
    Join Date
    Aug 2009
    Location
    Australia
    Posts
    656

    Default

    Thanks heaps for sharing your code like this and giving lots of details on how to use it. Wish this sort of thing happened more, especially being a copy and paste coder.
    But if I could be critical (which I dont deserve as your obviously a better coder than me) it would be awesome if you could make this into an object (or woteva its called).
    Id love it work something like this....
    var blipblip = new BlipLib();
    blipblip.msg="Watching %% auction%%. Next ends in %w4b3%";
    blipblip.interval = 500; //animation speed
    blipblip.repeat = true;
    blipblip.updateCallback=update();
    blipblip.play();
    ....whenever the message is about to be played from the beginning it calls the callback passing how many variables it expects and the callback returns an array that the blip uses to fill the spots.
    I know Im asking alot, I dont expect you to do it. Im just thinking out loud, blame Tim Ker (author of SeachCenter)...gave me a great lecture on not using global variables and now I want everything like this .

  3. #3
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    I suppose. I come from a C background so I'm more of a global variables, no objects kind of person.
    The only apprehension I have toward it is that it implies you could have multiple running and that really wouldn't work, since there's only one browser action per extension.

    Also, just fyi, but it'd have to be:
    blipblip.updateCallback=update;
    Using () executes the function and would set the updateCallback to the returned value instead of the function itself.

    Hope you can outgrow copypasta coding lol. It's fine to use libs and read people's code, but like they say in English class when you write a report, "it's best to rewrite it in your own words."
    ~ Projects ~
    Specialized: Carapass Auction Watcher, Kongregate Chat
    Libraries: bliplib
    Tools: manifest syntax highlighting & snippits
    ~ Happy to make extensions for pay too ;D ~
    Portfolio: Search and Share

  4. #4
    PAEz's Avatar
    PAEz is offline Moderator
    Join Date
    Aug 2009
    Location
    Australia
    Posts
    656

    Default

    I suppose. I come from a C background so I'm more of a global variables, no objects kind of person.
    I come from assembly on c64, Amos on amiga, pascal on PC's and now I efn love JS....keep in mind theres years of no computer between each of those languages and I have a shocking memory...basically relearn each time...so I dont know what I am

    Also, just fyi, but it'd have to be:
    blipblip.updateCallback=update;
    Using () executes the function and would set the updateCallback to the returned value instead of the function itself.
    As I just said, I have a shocking memory and details like that allways evade me and Im constantly looking in refrence manuals. So I really appreciate people pointing out things like that or criticize my code as it really helps me get it past my thick skull.

    Hope you can outgrow copypasta coding lol. It's fine to use libs and read people's code, but like they say in English class when you write a report, "it's best to rewrite it in your own words."
    Doubt it with my bad memory and all, but Id like to point out that I only use what I understand (or how the hell ya gonna deal with probs in the future) and have a strong tendency of changing it (I love playing with others code).

    Code:
    The only apprehension I have toward it is that it implies you could have multiple running and that really wouldn't work, since there's only one browser action per extension.
    I dont have a prob with that and I wonder if theres a way of dealing with that?
    Id put the object on the background page and allways access it from there anyways (Like Tim did with the imagecache in search center).
    I might have a go at turning this into an object, been looking for an exercise like that.

  5. #5
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    Yeah sure, it'd be pretty easy to make a wrapper.
    ~ Projects ~
    Specialized: Carapass Auction Watcher, Kongregate Chat
    Libraries: bliplib
    Tools: manifest syntax highlighting & snippits
    ~ Happy to make extensions for pay too ;D ~
    Portfolio: Search and Share

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •