This command enables you to do a site based google search based on the
subdomain of the active tab, loadit also takes a parameter to further
narrow your search.

The loadit command will put the first 10 results in a stack.
The getit command will pop one result into the current tab each time
you run it.

This is a good example of using persistent storage.

i.e.
1. You are on youtube.com
2. You type loadit mouse
3. Then you type getit and an obnoxious video about the wiimote as a
mouse comes up
4. Type getit again and you get an adorable video of a cat chasing a
remote control mouse

CmdUtils.CreateCommand({
  names: ["loadit"],
  arguments: [{role: 'object', nountype: noun_arb_text}],
  preview: function preview(pblock, args) {

    },
    execute: function execute(args) {
       Bin.myurls(null);

       //displayMessage(args.object.text);

       var sourceURL = Application.activeWindow.activeTab.uri.spec;
       sourceURL = sourceURL.split('/');
       var subDomain = sourceURL[2];

       jQuery.get( 'http://www.google.com/search?q=site:' + subDomain
+ ' ' + args.object.text, null, function( page ) {

       var searchSTR = 'href=\"http://' + subDomain;
       var beginPos = page.indexOf("Search Results",0);
       var endPos = 0;

       beginPos = page.indexOf(searchSTR,beginPos) + 6;
       z = [];

       //displayMessage(searchSTR);


       // 5 is -1 + 6
       while( beginPos > 5 )
       {

          //stringObject.indexOf(searchvalue,fromindex)
          endPos = page.indexOf( "\"", beginPos );

          //stringObject.substring(start,stop)
          //displayMessage(beginPos + ' ' + endPos);
          z.push( page.substring(beginPos,endPos) );

          beginPos = page.indexOf( searchSTR, endPos ) + 6;

       }

       Bin.myurls(z);
       displayMessage("Success" );

       });

    },
})


CmdUtils.CreateCommand({
  name: "getit",
  execute: function list_memos_execute() {
    x = Bin.myurls().pop();
    if( x != null )
    {
        Application.activeWindow.activeTab.document.location.href= x;
        //Utils.openUrlInBrowser(x);
    }
  },
});

-- 
You received this message because you are subscribed to the Google Groups 
"ubiquity-firefox" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/ubiquity-firefox?hl=en.

Reply via email to