views:

57

answers:

1

Hey guys,

recently I've installed the FireGestures plugin for Firefox, which I find very useful. You can also create your own scripts using JavaScript.

I want to create a script that simply scrolls to the top and then reloads the page. Sound simple, but I couldnt figure it out.

In FireGestures' help page it says "Of course, you can use global objects defined in browser.xul such as gBrowser, Cc and Ci."

I dont have eny experience with those and the Mozilla XUL documentation is one of the worst things that I've ever seen.

I've managed to trigger the reloading part by intuitively typing gBrowser.reload(); which reloads the current tab (exactly what i want).

How can I tell FireGestures to scroll to the top?

+1  A: 

This worked for me.

goDoCommand('cmd_scrollTop');
gBrowser.reload();

This link has some more cmd_* commands with explanations (Just have to find the command among the Keyconfig syntax). http://kb.mozillazine.org/Keyconfig_extension:_Firefox

Also, viewing the source of some of the other Mappings will give you these cmd_* commands as well.

EDIT:

Here is a list of some of the more basic commands I found on the URL above (I haven't tested all of these):

  • Open Location: gBrowser.loadURI('http://www.mozilla.org/');
  • Next Tab: gBrowser.mTabContainer.advanceSelectedTab(1);
  • Previous Tab: gBrowser.mTabContainer.advanceSelectedTab(-1);
  • Reload All Tabs: gBrowser.reloadAllTabs();
  • Close current Tab: var tab = gBrowser.mCurrentTab; gBrowser.removeTab(tab);
  • Scroll Page Down: goDoCommand('cmd_scrollPageDown');
  • Scroll Page Up: goDoCommand('cmd_scrollPageUp');
  • Scroll to the Bottom: goDoCommand('cmd_scrollBottom');
  • Scroll to the Top: goDoCommand('cmd_scrollTop');
  • Scroll Line Down: goDoCommand('cmd_scrollLineDown');
  • Scroll Line Up: goDoCommand('cmd_scrollLineUp');

EDIT:

Here is a more comprehensive list of commands (Also untested):
https://developer.mozilla.org/en/XUL/List_of_commands

Brandon Boone
I'll try it asap! How do i view the sources? That's what I asked myself all along...
f1sh
Firefox Menu ->Tools ->Add-ons->FireGestures->Options->Main->Mappings->View Source->Click on Item you wish to view->Edit->It'll be in the "Command" text box. This will just give you the commands, but won't tell you how to execute them.
Brandon Boone
It seems we have different versions of the add-on... I cannot see the source, only user-defined scripts show the commands in a textbox. For the predefined commands, there are only one-line-commands in the style of "FireGestures:DuplicateTab".
f1sh
Maybe, maybe not. I also see those one-line-commands in some of the scripts. But others like 'New Window' show 'cmd_newNavigator.' Probably better than looking through these, I'd take a look at the link I've posted. There's quite a few examples that use gBrowser and goDoCommand to accomplish various tasks. Ultimately, I haven't figured out how to translate/execute the provided commands (FireGestures:Command) either. If I do, I'll post that in my answer as well
Brandon Boone
Thanks for all the help :) Have your delicious bounty. With cool whip: http://www.youtube.com/watch?v=lich59xsjik
f1sh