browser commands

0 views
Skip to first unread message

Braydon Fuller

unread,
Jan 5, 2009, 3:31:14 AM1/5/09
to ubiquity...@googlegroups.com
Was just searching through the Herd, and default commands
and was really wondering why there are not any "browser"
commands? Such as:

- history
- back / forward / home / refresh / page-down / page-up
- bookmark / print
- preferences
- delete-cache
- turn on / off plugins and themes
- fullscreen
- downloads
- url (goto)
- quit

Thus replacing the need for a menubar at all. Also just the ctrl key
could be the hotkey so that ctrl b (back), ctrl f (forward), u (up), d
(down)
would work.


Christian Sonne

unread,
Jan 5, 2009, 3:36:37 AM1/5/09
to ubiquity...@googlegroups.com
Great ideas - I'll try to implement at least most of them, and add them in the default feeds

Aza

unread,
Jan 5, 2009, 3:37:27 AM1/5/09
to ubiquity...@googlegroups.com
Hi Braydon,

Those would be an excellent set of commands. Want to take a shot at creating them and we'll pull them into Ubiq!

-- aza | ɐzɐ --

Braydon Fuller

unread,
Jan 5, 2009, 3:44:05 AM1/5/09
to ubiquity...@googlegroups.com
Another idea would be to have "history" show up formatted as HTML like about:config does. This could be done with; downloads, bookmarks, add-ons, and preferences. The benefit being, besides doing away with dialog boxes, is that you could share them online (especially cool for bookmarks). Might work better with Weave too.

    Braydon

Braydon Fuller

unread,
Jan 5, 2009, 3:45:18 AM1/5/09
to ubiquity...@googlegroups.com
Aza wrote:
Hi Braydon,

Those would be an excellent set of commands. Want to take a shot at creating them and we'll pull them into Ubiq!
I'll take a look.
Looks like Christian also stepped up. :)

    Braydon

Christian Sonne

unread,
Jan 5, 2009, 4:49:44 AM1/5/09
to ubiquity...@googlegroups.com
On Mon, Jan 5, 2009 at 9:45 AM, Braydon Fuller <cou...@braydon.com> wrote:
Aza wrote:
Hi Braydon,

Those would be an excellent set of commands. Want to take a shot at creating them and we'll pull them into Ubiq!
I'll take a look.
Looks like Christian also stepped up. :)

    Braydon


-- aza | ɐzɐ --


On Mon, Jan 5, 2009 at 12:31 AM, Braydon Fuller <cou...@braydon.com> wrote:

Was just searching through the Herd, and default commands
and was really wondering why there are not any "browser"
commands? Such as:

Before anyone else spends time on it, I'll just check off the ones I've done so far
 

- history
- back / forward / home / refresh / page-down / page-up
back, forward, home, refresh

- bookmark / print
bookmark, print

- preferences
- delete-cache
- turn on / off plugins and themes
- fullscreen
fullscreen

- downloads
- url (goto)
- quit
I've done close, which closes the current window - but not yet quit

Braydon Fuller

unread,
Jan 5, 2009, 5:00:01 AM1/5/09
to ubiquity...@googlegroups.com
Christian Sonne wrote:

(...)


Before anyone else spends time on it, I'll just check off the ones I've done so far

- history
- back / forward / home / refresh / page-down / page-up
back, forward, home, refresh
Cool. I was just messing around with this and ended up with:

CmdUtils.CreateCommand({
  name: "back",
  icon: "gtk-go-back",
  description: "Browser's Back Function",
  takes: {"input": noun_arb_text},
  preview: function( pblock, input ) {
    var template = "Hello ${name}";
    pblock.innerHTML = CmdUtils.renderTemplate(template, {"name": "World!"});
  },
  execute: function(input) {
    CmdUtils.getWindowInsecure().history.go(-1)
  }
});

Ditto for forward.
Obviously lots of problems,;icon, and preview.
I was thinking the preview could be a thumbnail of the window, and it could accept nouns that are of the type of titles of pages in the history, as well as integers.

What did you get so far?

    Braydon


Christian Sonne

unread,
Jan 5, 2009, 5:14:13 AM1/5/09
to ubiquity...@googlegroups.com

I have not yet troubled myself with icons and the likes (I think a lot of the current icons have been produced by the same guy, but I can't remember who :-S) but here is my current implementations:
CmdUtils.CreateCommand({
  name: "fullscreen",
  description: "Toggles fullscreen mode",
  preview: function( pblock ) {pblock.innerHTML=this.description},
  execute: function() {
    var win = CmdUtils.getWindow();
    win.fullScreen = win.fullScreen ? false : true;
  }
});

CmdUtils.CreateCommand({
  name: "back",
  description: "Go one step back in history",
  preview: function( pblock ) {pblock.innerHTML=this.description},
  execute: function() {
    var win = CmdUtils.getWindow();
    win.history.go(-1);
  }
});

CmdUtils.CreateCommand({
  name: "forward",
  description: "Go one step forward in history",
  preview: function( pblock ) {pblock.innerHTML=this.description},
  execute: function() {
    var win = CmdUtils.getWindow();
    win.history.go(1);
  }
});

CmdUtils.CreateCommand({
  name: "home",
  description: "Go to home page",
  preview: function( pblock ) {pblock.innerHTML=this.description},
  execute: function() {
    var win = CmdUtils.getWindow();
    win.home();
  }
});

CmdUtils.CreateCommand({
  name: "close",
  description: "Close firefox",
  preview: function( pblock ) {pblock.innerHTML=this.description},
  execute: function() {
    var win = CmdUtils.getWindow();
    win.close();
  }
});

CmdUtils.CreateCommand({
  name: "refresh",
  description: "Refresh current document",
  preview: function( pblock ) {pblock.innerHTML=this.description},
  execute: function() {
    var win = CmdUtils.getWindow();
    win.location.reload( true );
  }
});

CmdUtils.CreateCommand({
  name: "bookmark",
  description: "Add current document to bookmarks",
  preview: function( pblock ) {pblock.innerHTML=this.description},
  execute: function() {
    var win = CmdUtils.getWindowInsecure();
    var doc = CmdUtils.getDocument();
    try {
      if(!win.sidebar.addPanel(doc.title, win.location.href,"")) throw("Internal error");
    } catch ( e ) { displayMessage("Page could not be bookmarked!" + ((e)?" - "+e:"")); }
  }
});

CmdUtils.CreateCommand({
  name: "print",
  description: "Print current page",
  preview: function( pblock ) {pblock.innerHTML=this.description},
  execute: function() {
    var win = CmdUtils.getWindow();
    win.print();
  }
});

-- cers / Christian Sonne
 

Braydon Fuller

unread,
Jan 5, 2009, 5:38:13 AM1/5/09
to ubiquity...@googlegroups.com
Do you know where error messages go? Errors seem to pass silently.

    Braydon

Christian Sonne

unread,
Jan 5, 2009, 5:53:49 AM1/5/09
to ubiquity...@googlegroups.com
On Mon, Jan 5, 2009 at 11:38 AM, Braydon Fuller <cou...@braydon.com> wrote:
Do you know where error messages go? Errors seem to pass silently.

That depends on a few things... if the error is an exception, ubiquity catches it and depending on the value of extensions.ubiquity.displayAlertOnError in about:config it will display the exception as a notification - regardless of it's value, it will be logged in the console. (At least, that's how I've understood it.)

If the error is not an exception, or something before ubiquity catches it, you are hard pressed to figure out what has happened - you'll notice that my code for bookmark is a bit strange on that account - if you try to bookmark a chrome page, somethings errors out, but it doesn't throw an exception, or at least not one that reaches me

While writing this email, I've just figured out that I cannot test the function as I do, as it seems to return false in any case, so that command will have to be altered:

CmdUtils.CreateCommand({
  name: "bookmark",
  description: "Add current document to bookmarks",
  preview: function( pblock ) {pblock.innerHTML=this.description},
  execute: function() {
    var win = CmdUtils.getWindowInsecure();
    var doc = CmdUtils.getDocument();
    try {
     win.sidebar.addPanel(doc.title, win.location.href,"");

    } catch ( e ) { displayMessage("Page could not be bookmarked!" + ((e)?" - "+e:"")); }
  }
});
 
is probably better for now...


-- cers / Christian Sonne


    Braydon

Braydon Fuller

unread,
Jan 5, 2009, 6:04:26 AM1/5/09
to ubiquity...@googlegroups.com
I tried turning on AlertOnError, and nothing seems to appear in Firebug, or elsewhere.
Here is what I trying to run:

CmdUtils.getURLSnapshot = function getURLSnapshot(url, options){
  var win = CmdUtils.getHiddenWindow();
  win.document.location.href = url;
  win.document.addEventListener("load", function(){
    return CmdUtils.getWindowSnapshot(win, options);
  }, true);
}

CmdUtils.CreateCommand({
  name: "back",

  description: "Browser's Back Function",
  takes: {"input": noun_arb_text},
  preview: function( pblock, input ) {
    var imgData = CmdUtils.getURLSnapshot( "http://mozilla.org", {width:500} );     
    pblock.innerHTML = "Changes to <b style=\"color:yellow\">%s</b> document.".replace(/%s/, "url");
    pblock.innerHTML += "<br/><img src='%s'>".replace(/%s/, imgData );
  },
  execute: function(input) {
    CmdUtils.getWindow().history.go(-1)
  }
});

Everything works except that upper part, and have really no idea where the problem is.

    Braydon

Braydon Fuller

unread,
Jan 5, 2009, 6:47:04 AM1/5/09
to ubiquity...@googlegroups.com
I ended up using CmdUtils.log() to see what's going on. I also used this for some introspection:

function dir(ob){
  var a=[],attr
  for(attr in ob){a.push(attr)}
  return a.sort().join('\n')
}

Very similar to the Pythonic dir().

Here is a slightly more functional version of the previous, the scale of the thumbnail is way off though...

CmdUtils.getURLSnapshot = function getURLSnapshot(url, options){
  var hiddenWindow = CmdUtils.getHiddenWindow();
  hiddenWindow.document.location.href = url
  return CmdUtils.getWindowSnapshot(hiddenWindow.document.defaultView, options);
}

CmdUtils.CreateCommand({
  name: "back",
  description: "Go one step back in history",

  takes: {"input": noun_arb_text},
  preview: function( pblock, input ) {
    var imgData = CmdUtils.getURLSnapshot( "http://mozilla.org", {width:500} );      
    pblock.innerHTML = "Changes to <b style=\"color:yellow\">%s</b> document.".replace(/%s/, "url");
    pblock.innerHTML += "<br/><img src='%s'>".replace(/%s/, imgData );
  },
  execute: function(input) {
    CmdUtils.getWindow().history.go(-1)
  }
})
;




    Braydon Fuller








Braydon Fuller

unread,
Jan 5, 2009, 8:55:42 AM1/5/09
to ubiquity...@googlegroups.com
Another version of back (still a bit goofy):

CmdUtils.getURLSnapshot = function(url, options){
if(!options) options = {};
var hw = CmdUtils.getHiddenWindow();
hw.document.location.href = url;
cw = CmdUtils.getWindow()
hw.innerWidth = cw.innerWidth
hw.innerHeight = cw.innerHeight
var th_hw = CmdUtils.getHiddenWindow();
var th =
th_hw.document.createElementNS("http://www.w3.org/1999/xhtml", "canvas" );
width = options.width || 200;
var scale = width / hw.innerWidth;
var ratio = hw.innerHeight / hw.innerWidth;
th.mozOpaque = true;
th.width = width;
th.height = th.width * ratio;
var ctx = th.getContext("2d");
ctx.scale(scale, scale);
ctx.drawWindow(hw, hw.scrollX, hw.scrollY,
hw.innerWidth, hw.innerWidth, "rgb(255,255,255)");
return th.toDataURL("image/jpeg", "quality=90");
}

var noun_type_history = {
_name: "history urls",
suggest: function( text, html ) {
var suggestions = [];
var history = CmdUtils.getWindow().history;
for ( var i = 0; i < history.length; i++ ) {
url = history[i];
if (url.match(text, "i"))
suggestions.push(CmdUtils.makeSugg(url));
}
return suggestions.splice(0, 5);
}
};


CmdUtils.CreateCommand({
name: "back",
description: "Go one step back in history",

takes: {"input": noun_type_history},


preview: function( pblock, input ) {

if (input.text) {var url = input.text;
} else { var url = CmdUtils.getWindow().history.previous;}
var imgData = CmdUtils.getURLSnapshot(url, {width:500} );


pblock.innerHTML = "Changes to <b style=\"color:yellow\">%s</b>
document.".replace(/%s/, url);
pblock.innerHTML += "<br/><img src='%s'>".replace(/%s/, imgData );
},
execute: function(input) {

if (input.text){
CmdUtils.getWindow().location.href = input.text;
} else {
CmdUtils.getWindow().history.go(-1);
}
}
});

Reply all
Reply to author
Forward
0 new messages