keyconfig 20110522

Announce and Discuss the Latest Theme and Extension Releases.
Post Reply
zillamanilla
Posts: 17
Joined: October 5th, 2008, 9:26 pm

Re: keyconfig 20080929

Post by zillamanilla »

Is there a way to have it where in a keybinding after it pastes the text it submits the text (presses enter for me). Lets just say as an example its google, so it pastes something into the google textbox and submits the search for me.

I was reading on earlier pages that you can create commands with a mouse click. I tried (but failed) in making a double click copy command. So I can double click a word and it copies it? How would that be done?

Thanks.

And as a sidenote, I think dorando might just be the coolest person on earth, honestly, I wish there was more people like him! =D>
Last edited by zillamanilla on October 6th, 2008, 7:17 pm, edited 7 times in total.
nettrotter
Posts: 87
Joined: June 26th, 2007, 6:17 pm

Re: keyconfig 20080929

Post by nettrotter »

I am using Foxlingo toolbar for translation.

Can you tell me what is the code to toggle on/off foxlingo toolbar?
nettrotter
Posts: 87
Joined: June 26th, 2007, 6:17 pm

Re: keyconfig 20080929

Post by nettrotter »

I use a custom button " auto context menu on selection". which will pop up context menu immdiately when you highlight some text on webpages.Very handy, but sometimes i want to toggle off this button for momentary halt for this function.

and the code of this custom button as below:

Code: Select all

var prefs=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
try{
    var cb_autoContextmenu = prefs.getBoolPref("cb_autoContextmenu" );
}catch(e){
    prefs.setBoolPref("cb_autoContextmenu",true );
}
prefs.setBoolPref("cb_autoContextmenu", !prefs.getBoolPref("cb_autoContextmenu" ));
this.checked = prefs.getBoolPref("cb_autoContextmenu" );


then can you please tell me what is the code of toggle on/off "auto context menu on selection" function?
Thanks in advance.
dorando
Posts: 1203
Joined: January 9th, 2004, 9:57 am
Contact:

Re: keyconfig 20080929

Post by dorando »

nettrotter wrote:
dorando wrote:

Code: Select all

var toolbar = document.getElementById("PersonalToolbar");
toolbar.collapsed = !toolbar.collapsed;
document.persist(toolbar.id, "collapsed");
. Replace "PersonalToolbar" with "nav-bar" for the Navigation Toolbar, or "toolbar-menubar" for the Menu.


This set of code still works on PersonalToolbar( aka, bookmark toolbar).
But it doesn't work on Menu bar after replacing Id.
Don't know what about navigation bar ,because i don't wanna try .
Seems to work for me

Code: Select all

var toolbar = document.getElementById("toolbar-menubar");
toolbar.collapsed = !toolbar.collapsed;
document.persist(toolbar.id, "collapsed");  


nettrotter wrote:Then what is the code to copy link text when mouse hovers over a link?
and what is the code to copy link text and location together when mouse hovers over a link with the form of "link text" - "link location"?
Since I don't know how to get the link directly, looping through all available until one matches the url is the best I can come up with

Code: Select all

if(XULBrowserWindow.overLink)
 for (var i = 0, links = content.document.links, l = links.length ; i < l; i++)
  if(links[i].href == XULBrowserWindow.overLink) {
   Components.classes["@mozilla.org/widget/clipboardhelper;1"]
   .getService(Components.interfaces.nsIClipboardHelper)
   .copyString(links[i].text + " - " + links[i].href);

   break;
  }  
. Use

Code: Select all

.copyString(links[i].text);  
to only copy the link text.

zillamanilla wrote:But I'm having a problem with setting a keybinding to Paste. I'm trying to use

Code: Select all

goDoCommand('cmd_paste');
as the command and using one letter as the keybinding "V" (instead of control+v). But it doesn't want to work.
Using single letters as shortcut won't work in text boxes/form elements or if Search for text when I start typing is enabled as these are handled before it reaches the <key> added by keyconfig.

zillamanilla wrote:And while I'm at it, is there a way to switch to another Firefox window? Like if I have two open and I want to go to the other one.
Try

Code: Select all

var enumerator =
Components.classes["@mozilla.org/appshell/window-mediator;1"]
.
getService(Components.interfaces.nsIWindowMediator)
.
getZOrderDOMWindowEnumerator("navigator:browser",true);

if(
enumerator.hasMoreElements()) enumerator.getNext();
if(
enumerator.hasMoreElements()) enumerator.getNext().focus();  
This should be similar to Alt+F6 on Windows (but restricted to browser windows).

zillamanilla wrote:Is there a way to have it where in a keybinding after it pastes the text it submits the text (presses enter for me). Lets just say as an example its google, so it pastes something into the google textbox and submits the search for me.
Either simulating a keypress:

Code: Select all

if(commandDispatcher.focusedElement) {
 goDoCommand("cmd_paste");
 
 var e 
= commandDispatcher.focusedElement.ownerDocument.createEvent("KeyEvents");
 e.initKeyEvent("keypress", true, true, null, false, false, false, false, KeyEvent.DOM_VK_ENTER, 0);
 commandDispatcher.focusedElement.dispatchEvent(e);
}
 
or submitting the form owning the focusedElement:

Code: Select all

if(commandDispatcher.focusedElement &&
   commandDispatcher.focusedElement.form) {
 goDoCommand("cmd_paste");
 commandDispatcher.focusedElement.form.submit();
}
 
should work.

zillamanilla wrote:I was reading on earlier pages that you can create commands with a mouse click. I tried (but failed) in making a double click copy command. So I can double click a word and it copies it? How would that be done?
That most likely referred to double clicking an non-custom entry in the keyconfig screen to duplicate it (the still misnamed context > Edit this key does the same). AutoCopy seems to be what you want.

nettrotter wrote:I am using Foxlingo toolbar for translation.

Can you tell me what is the code to toggle on/off foxlingo toolbar?
Try (tested against FoxLingo 2.2.5 but the id might change in the future)

Code: Select all

var toolbar = document.getElementById("foxlingo-toolbar-2-2-4");
toolbar.collapsed = !toolbar.collapsed;
document.persist(toolbar.id, "collapsed");  


nettrotter wrote:I use a custom button " auto context menu on selection". which will pop up context menu immdiately when you highlight some text on webpages.Very handy, but sometimes i want to toggle off this button for momentary halt for this function.

and the code of this custom button as below:

Code: Select all

var prefs=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
try{
    var cb_autoContextmenu = prefs.getBoolPref("cb_autoContextmenu" );
}catch(e){
    prefs.setBoolPref("cb_autoContextmenu",true );
}
prefs.setBoolPref("cb_autoContextmenu", !prefs.getBoolPref("cb_autoContextmenu" ));
this.checked = prefs.getBoolPref("cb_autoContextmenu" );


then can you please tell me what is the code of toggle on/off "auto context menu on selection" function?
Thanks in advance.
The code you've posted actually toggles that functionality on/off (the main code is in the "Initialization code" tab), just replace the last line with

Code: Select all

var button = document.getElementsByAttribute("label","Auto context menu on selection")[0];
if(
button) button.checked = prefs.getBoolPref("cb_autoContextmenu" );  
to update the button state (adjust the label if you modified it).

With Custom Buttons (but apparently not with Custom Buttons²) you can assign a Hotkey from the Button settings tab (it won't be "seen" by keyconfig as this seems to be handled by an event listener).
nettrotter
Posts: 87
Joined: June 26th, 2007, 6:17 pm

Re: keyconfig 20080929

Post by nettrotter »

dorando, you are really master in your field...all the scripts you suggest to me is in use. Thanks a lot.
zillamanilla
Posts: 17
Joined: October 5th, 2008, 9:26 pm

Re: keyconfig 20080929

Post by zillamanilla »

dorando, awesome, just awesome.

One more question, could this keyconfig execute more complicated scripts. Like for instance could I target a specific place on a webpage where text is located and have it execute a program like this:
1) Finds text by location and saves it as a variable (assuming I'm already on the webpage... could this text string be located by dominspector?)
2) Refreshes webpage
3) Finds same text string again and saves it as another variable
4) Compares both text strings to see if there is a change
4a) If no change exists then end script
4b) If change exists continue script
5) Change window
6) Paste changed textstring

[-o<
nettrotter
Posts: 87
Joined: June 26th, 2007, 6:17 pm

Re: keyconfig 20080929

Post by nettrotter »

QuickJava Allows quick enable and disable of Java and Javascript from toolbar. If I don't want to install extra addon, what code is in need to toggle on/off Java and javascript as firefow browser does.
dorando
Posts: 1203
Joined: January 9th, 2004, 9:57 am
Contact:

Re: keyconfig 20080929

Post by dorando »

zillamanilla wrote: [-o<
Something in the form

Code: Select all

var a = content.document.getElementById("DetailsTimeLeft").textContent;

BrowserReload();

function tempFunction(){
 gBrowser.removeEventListener("DOMContentLoaded",tempFunction,false);
 var b = content.document.getElementById("DetailsTimeLeft").textContent;
 if(!= b) {
  var enumerator =
  Components.classes["@mozilla.org/appshell/window-mediator;1"]
  .getService(Components.interfaces.nsIWindowMediator)
  .getZOrderDOMWindowEnumerator("navigator:browser",true);

  var newWindow;
  if(enumerator.hasMoreElements()) enumerator.getNext();
  if(enumerator.hasMoreElements()) newWindow = enumerator.getNext();
  var focusedElement = newWindow.document.commandDispatcher.focusedElement;

  if(!focusedElement) return;
  newWindow.focus(); focusedElement.focus();

  var editor = (focusedElement instanceof Components.interfaces.nsIDOMNSEditableElement) ? focusedElement.editor : null;
  if(editor) {
   editor instanceof Components.interfaces.nsIPlaintextEditor;
   editor.insertText(b);
   if(focusedElement.form) focusedElement.form.submit();
  }
 }
}

gBrowser.addEventListener("DOMContentLoaded",tempFunction,false); 
could work, but since this is looking for something very specific (the "End time" on an ebay.com item) you need to adjust it for your use case (also note that it will only switch the window if the target window has a focusedElement).

zillamanilla wrote:assuming I'm already on the webpage... could this text string be located by dominspector?
Unless the text appears in a Plugin you should be able to find it with DOM Inspector.

nettrotter wrote:QuickJava Allows quick enable and disable of Java and Javascript from toolbar. If I don't want to install extra addon, what code is in need to toggle on/off Java and javascript as firefow browser does.

Code: Select all

gPrefService.setBoolPref("javascript.enabled", !gPrefService.getBoolPref("javascript.enabled"));

gPrefService.setBoolPref("security.enable_java", !gPrefService.getBoolPref("security.enable_java"));  
You could also use

Code: Select all

gBrowser.docShell.allowJavascript = !gBrowser.docShell.allowJavascript;

gBrowser.docShell.allowPlugins = !gBrowser.docShell.allowPlugins;  
which disables JavaScript and Plugins per tab.
zillamanilla
Posts: 17
Joined: October 5th, 2008, 9:26 pm

Re: keyconfig 20080929

Post by zillamanilla »

var a = content.document.getElementById("DetailsTimeLeft").textContent;

could work, but since this is looking for something very specific (the "End time" on an ebay.com item) you need to adjust it for your use case (also note that it will only switch the window if the target window has a focusedElement).
Absolutely outstanding!!!! I just have one question I've been trying to modify it a little bit to work for my specific instance. The problem I'm having is retrieving text within an HTML <code></code> tag. I tried using:
"var a = content.document.getElementByTagName("code").textContent;"

But it doesn't seem to work. I think I'm missing something, I've been trying to figure it out, but for the life of me it just won't click right. I think it has to do with "innerHTML" #-o
dorando
Posts: 1203
Joined: January 9th, 2004, 9:57 am
Contact:

Re: keyconfig 20080929

Post by dorando »

zillamanilla wrote:The problem I'm having is retrieving text within an HTML <code></code> tag. I tried using:
"var a = content.document.getElementByTagName("code").textContent;"

But it doesn't seem to work. I think I'm missing something, I've been trying to figure it out, but for the life of me it just won't click right. I think it has to do with "innerHTML" #-o

document.getElementsByTagName (common typo) returns a NodeList, content.document.getElementsByTagName("code")[0] should return the first one.
In this case textContent is likely not suitable, but for innerHTML you might want to strip/convert some content before pasting it, something like

Code: Select all

b = b.replace(/<br>/g,"\n").replace(/<.*?>/g,"").replace(/&nbsp;/g," ").replace(/&lt;/g,"<");
zillamanilla
Posts: 17
Joined: October 5th, 2008, 9:26 pm

Re: keyconfig 20080929

Post by zillamanilla »

document.getElementsByTagName (common typo) returns a NodeList, content.document.getElementsByTagName("code")[0] should return the first one.
Oh man, I was sooo close! :lol: Thanks a ton!

You know what, I'm that I'm thinking about it. Remember the code above I asked about if you could switch firefox windows then paste. I'm starting to wonder if changing tabs would be more efficient and faster. Could you change the code below so that it does the same exact thing but instead of going to another window it goes to another tab? I've been using BrowserNumberTabSelection(event, 1); to go to another tab. Would it work in this instance? I tried inputting it in for "var enumerator" but it didn't work. I was never good at programming. I need the code optimized for the fastest speed possible. :-k

Code: Select all

var a = content.document.getElementById("DetailsTimeLeft").textContent;

    BrowserReload();

    function tempFunction(){
     gBrowser.removeEventListener("DOMContentLoaded",tempFunction,false);
     var b = content.document.getElementById("DetailsTimeLeft").textContent;
     if(a != b) {
      var enumerator =
      Components.classes["@mozilla.org/appshell/window-mediator;1"]
      .getService(Components.interfaces.nsIWindowMediator)
      .getZOrderDOMWindowEnumerator("navigator:browser",true);

      var newWindow;
      if(enumerator.hasMoreElements()) enumerator.getNext();
      if(enumerator.hasMoreElements()) newWindow = enumerator.getNext();
      var focusedElement = newWindow.document.commandDispatcher.focusedElement;

      if(!focusedElement) return;
      newWindow.focus(); focusedElement.focus();

      var editor = (focusedElement instanceof Components.interfaces.nsIDOMNSEditableElement) ? focusedElement.editor : null;
      if(editor) {
       editor instanceof Components.interfaces.nsIPlaintextEditor;
       editor.insertText(b);
       if(focusedElement.form) focusedElement.form.submit();
      }
     }
    }

    gBrowser.addEventListener("DOMContentLoaded",tempFunction,false); 
ffuser17
Posts: 115
Joined: January 25th, 2005, 12:58 am

Re: keyconfig 20080929

Post by ffuser17 »

I use the extension firesomething which changes the name in the titlebar (from mozilla firefox to whatever I like). However, this seems to disable keyconfig's functionality. Any shortcuts I make don't stay once I restart. I also use the extension titlebar tweaks, which also changes the titlebar. Anybody else have a similar issue?
zillamanilla
Posts: 17
Joined: October 5th, 2008, 9:26 pm

Re: keyconfig 20080929

Post by zillamanilla »

ffuser17 wrote:I use the extension firesomething which changes the name in the titlebar (from mozilla firefox to whatever I like). However, this seems to disable keyconfig's functionality. Any shortcuts I make don't stay once I restart. I also use the extension titlebar tweaks, which also changes the titlebar. Anybody else have a similar issue?
While in firefox press crtl+shift+F12. That will load up keyconfig. Double click any of the keyconfig items you want to use. When the new pop up appears (called keyconfig - Key Editor) look in the top right of this window for the check box that says "global", make sure you put a check mark in the box. Then press OK. Exit out of all your browsers, boot up firefox again and test out that keyconfig item you put that checkbox on. It should work now. It makes that item global to any and every firefox window you open up. That might solve your problem.
ffuser17
Posts: 115
Joined: January 25th, 2005, 12:58 am

Re: keyconfig 20080929

Post by ffuser17 »

Hmm... I thought I had it that way before and it didn't work. But now, it works perfectly... Thanks
zillamanilla
Posts: 17
Joined: October 5th, 2008, 9:26 pm

Re: keyconfig 20080929

Post by zillamanilla »

No Problem. You know what probably happened, you set everything but you didn't exit out of your browser and start up a new firefox window. I often do it too.
Post Reply