keyconfig 20110522
-
- Posts: 117
- Joined: June 9th, 2005, 8:30 am
- Location: France
Re: keyconfig 20110522
To Dorando
Now I have for the short-cut alt+Ctrl+G
code
if(readFromClipboard().match(/^identifierW(.*)/))
Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper).copyString(new Function(RegExp.$1)());
where if(.....)/)) is on one line and Compo....()); on an other line.
clipboard contains before shortcut
identifier alert(1); return 7;
and after it I have seen nothing and clipboard has not changed...
What should I have seen ? What should I have in the clipboard after short-cut ? What is the use of alert(1) ?
Now I have for the short-cut alt+Ctrl+G
code
if(readFromClipboard().match(/^identifierW(.*)/))
Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper).copyString(new Function(RegExp.$1)());
where if(.....)/)) is on one line and Compo....()); on an other line.
clipboard contains before shortcut
identifier alert(1); return 7;
and after it I have seen nothing and clipboard has not changed...
What should I have seen ? What should I have in the clipboard after short-cut ? What is the use of alert(1) ?
-
- Posts: 117
- Joined: June 9th, 2005, 8:30 am
- Location: France
Re: keyconfig 20110522
To Dorando
True : I have been trapped by a blank line after the end of what I have selected for copy !
But clicking on "SELECT ALL" is not a good solution because it adds spurious spaces at the beginning of lines...
This time I copied all your code and my import succeeded !
Keyconfig does not like that you define twice the same key + modifiers : this is a good thing !
Your "xxx_key1_AHK Import" shortcut only contains part of the code I posted.
True : I have been trapped by a blank line after the end of what I have selected for copy !
But clicking on "SELECT ALL" is not a good solution because it adds spurious spaces at the beginning of lines...
This time I copied all your code and my import succeeded !
Keyconfig does not like that you define twice the same key + modifiers : this is a good thing !
-
- Posts: 314
- Joined: August 8th, 2006, 4:08 pm
Re: keyconfig 20110522
To: dorando,
-----------------------------------------------------------------------
If any <button> has the focus it will handle it, but due to Bug 335089 - [OS X] Default button in sheets should not be focused (current code in CommonDialog.jsm and dialog.xml). You could add new keys to the dialog containing
document.documentElement.acceptDialog();
and
document.documentElement.cancelDialog();
and assign Y and N to them.
-----------------------------------------------------------------------
==> Unfortunately, I'm not familiar with the Keyconfig code to understand how/where I would assign Y/N using the above code to my existing Key that I'm using?. Below is my existing code that I'm currently using for the Send Now function using Y/N:
var nsIPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var flags =
nsIPromptService.BUTTON_POS_0 * nsIPromptService.BUTTON_TITLE_IS_STRING +
nsIPromptService.BUTTON_POS_1 * nsIPromptService.BUTTON_TITLE_IS_STRING;
if(nsIPromptService.confirmEx(null, "Send Now", "Do you want to send (Y/N)?", flags, "&Yes", "&No", null, null, {}) == 0)
goDoCommand("cmd_sendNow");
Can you please tell me where/how do I add "document.documentElement.acceptDialog();" and "document.documentElement.cancelDialog();" to the above code and assign Y/N as you have suggested?. Or better if you can provide me with the updated code that I can just use directly, it would be much better. Thanks again.
-----------------------------------------------------------------------
If any <button> has the focus it will handle it, but due to Bug 335089 - [OS X] Default button in sheets should not be focused (current code in CommonDialog.jsm and dialog.xml). You could add new keys to the dialog containing
document.documentElement.acceptDialog();
and
document.documentElement.cancelDialog();
and assign Y and N to them.
-----------------------------------------------------------------------
==> Unfortunately, I'm not familiar with the Keyconfig code to understand how/where I would assign Y/N using the above code to my existing Key that I'm using?. Below is my existing code that I'm currently using for the Send Now function using Y/N:
var nsIPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var flags =
nsIPromptService.BUTTON_POS_0 * nsIPromptService.BUTTON_TITLE_IS_STRING +
nsIPromptService.BUTTON_POS_1 * nsIPromptService.BUTTON_TITLE_IS_STRING;
if(nsIPromptService.confirmEx(null, "Send Now", "Do you want to send (Y/N)?", flags, "&Yes", "&No", null, null, {}) == 0)
goDoCommand("cmd_sendNow");
Can you please tell me where/how do I add "document.documentElement.acceptDialog();" and "document.documentElement.cancelDialog();" to the above code and assign Y/N as you have suggested?. Or better if you can provide me with the updated code that I can just use directly, it would be much better. Thanks again.
-
- Posts: 165
- Joined: March 19th, 2007, 6:24 am
Re: keyconfig 20110522
hi dorando,
I've noticed a while back (there might have been a change somewhere along the way)
that the command for opening the current tab's tab context menu has changed since you last helped me in this matter:
http://forums.mozillazine.org/viewtopic.php?f=48&t=72994&start=1875
I'm using tabmixplus (tmp) and have trimmed down the tab context menu with tmp to just a few entries.
With the above code it happens quite often (though I'm not sure when it happens and what exactly triggers it to happen)
that it gives me a very long menu with many many entries (the complete list, as it were),
when I use your code from above. - If, instead, I right click on the tab it reliably returns the (tmp-) trimmed-down version of the tab context menu.
Any ideas how to refine the code above?
thx!
chirpy
- EDIT -
The error console yields this:
which is
in the context of
in case this is helpful?
I've noticed a while back (there might have been a change somewhere along the way)
that the command for opening the current tab's tab context menu has changed since you last helped me in this matter:
http://forums.mozillazine.org/viewtopic.php?f=48&t=72994&start=1875
Code: Select all
var tabMenu = gBrowser.tabContextMenu || document.getAnonymousElementByAttribute(gBrowser,"anonid","tabContextMenu");
document.popupNode = gBrowser.mCurrentTab;
tabMenu.openPopup(gBrowser.mCurrentTab, "after_start", 0, 0, true);
I'm using tabmixplus (tmp) and have trimmed down the tab context menu with tmp to just a few entries.
With the above code it happens quite often (though I'm not sure when it happens and what exactly triggers it to happen)
that it gives me a very long menu with many many entries (the complete list, as it were),
when I use your code from above. - If, instead, I right click on the tab it reliably returns the (tmp-) trimmed-down version of the tab context menu.
Any ideas how to refine the code above?
thx!
chirpy
- EDIT -
The error console yields this:
Timestamp: 01/05/12 10:21:25
Error: aPopupMenu.triggerNode is null
Source File: chrome://browser/content/browser.js
Line: 12125
which is
Code: Select all
this.contextTab = aPopupMenu.triggerNode.localName == "tab" ?
in the context of
Code: Select all
var TabContextMenu = {
contextTab: null,
updateContextMenu: function updateContextMenu(aPopupMenu) {
this.contextTab = aPopupMenu.triggerNode.localName == "tab" ?
aPopupMenu.triggerNode : gBrowser.selectedTab;
let disabled = gBrowser.tabs.length == 1;
// Enable the "Close Tab" menuitem when the window doesn't close with the last tab.
document.getElementById("context_closeTab").disabled =
disabled && gBrowser.tabContainer._closeWindowWithLastTab;
var menuItems = aPopupMenu.getElementsByAttribute("tbattr", "tabbrowser-multiple");
for (var i = 0; i < menuItems.length; i++)
menuItems[i].disabled = disabled;
disabled = gBrowser.visibleTabs.length == 1;
menuItems = aPopupMenu.getElementsByAttribute("tbattr", "tabbrowser-multiple-visible");
for (var i = 0; i < menuItems.length; i++)
menuItems[i].disabled = disabled;
// Session store
document.getElementById("context_undoCloseTab").disabled =
Cc["@mozilla.org/browser/sessionstore;1"].
getService(Ci.nsISessionStore).
getClosedTabCount(window) == 0;
// Only one of pin/unpin should be visible
document.getElementById("context_pinTab").hidden = this.contextTab.pinned;
document.getElementById("context_unpinTab").hidden = !this.contextTab.pinned;
// Disable "Close other Tabs" if there is only one unpinned tab and
// hide it when the user rightclicked on a pinned tab.
let unpinnedTabs = gBrowser.visibleTabs.length - gBrowser._numPinnedTabs;
document.getElementById("context_closeOtherTabs").disabled = unpinnedTabs <= 1;
document.getElementById("context_closeOtherTabs").hidden = this.contextTab.pinned;
// Hide "Bookmark All Tabs" for a pinned tab. Update its state if visible.
let bookmarkAllTabs = document.getElementById("context_bookmarkAllTabs");
bookmarkAllTabs.hidden = this.contextTab.pinned;
if (!bookmarkAllTabs.hidden)
PlacesCommandHook.updateBookmarkAllTabsCommand();
// Hide "Move to Group" if it's a pinned tab.
document.getElementById("context_tabViewMenu").hidden =
(this.contextTab.pinned || !TabView.firstUseExperienced);
}
};
in case this is helpful?
Last edited by chirpy_7 on May 1st, 2012, 3:18 am, edited 2 times in total.
-
- Posts: 174
- Joined: February 6th, 2008, 3:02 pm
Re: keyconfig 20110522
Slickone wrote:If Ctrl-Q is a default shortcut, why doesn't it show up in keyconfig's list?
Could someone give me the code to add for Ctrl-Q?
Can no one answer this?
- tonymec
- Posts: 734
- Joined: October 15th, 2004, 2:58 am
- Location: Ixelles (Brussels Capital Region, Belgium)
- Contact:
Re: keyconfig 20110522
Slickone wrote:Slickone wrote:If Ctrl-Q is a default shortcut, why doesn't it show up in keyconfig's list?
Could someone give me the code to add for Ctrl-Q?
Can no one answer this?
Some built-in key bindings are handled before keyconfig can see them. On many OSes (but, I think, not on Windows) Ctrl-Q means Quit (on Windows it might be Ctrl-X, I'm not sure).
I see it listed in the keyconfig list, as "Quit — accel+Q — key_quit"
(IIUC "accel" means Cmd on Mac and Ctrl elsewhere).
Best regards,
Tony
Tony
-
- Posts: 174
- Joined: February 6th, 2008, 3:02 pm
Re: keyconfig 20110522
tonymec wrote:Slickone wrote:Slickone wrote:If Ctrl-Q is a default shortcut, why doesn't it show up in keyconfig's list?
Could someone give me the code to add for Ctrl-Q?
Can no one answer this?
Some built-in key bindings are handled before keyconfig can see them. On many OSes (but, I think, not on Windows) Ctrl-Q means Quit (on Windows it might be Ctrl-X, I'm not sure).
I see it listed in the keyconfig list, as "Quit — accel+Q — key_quit"
(IIUC "accel" means Cmd on Mac and Ctrl elsewhere).
It's not in my list (Windows). I had read on a website that keyconfig could disable Ctrl-Q, so I don't keep shutting down Firefox by mistake.
- tonymec
- Posts: 734
- Joined: October 15th, 2004, 2:58 am
- Location: Ixelles (Brussels Capital Region, Belgium)
- Contact:
Re: keyconfig 20110522
Slickone wrote:It's not in my list (Windows). I had read on a website that keyconfig could disable Ctrl-Q, so I don't keep shutting down Firefox by mistake.
Do you have a line titled "Exit" in the keyconfig popup?
Best regards,
Tony
Tony
-
- Posts: 117
- Joined: June 9th, 2005, 8:30 am
- Location: France
Re: keyconfig 20110522
On my French version of Keyconfig pop-up I have in the right lower corner "Fermer" that I would have translated to "Close" but that may be your "Exit"...
Ctrl+Q was not in the pop-up list, I have given it to one of my personal short-cuts without problem.
Ctrl+Q was not in the pop-up list, I have given it to one of my personal short-cuts without problem.
-
- Posts: 117
- Joined: June 9th, 2005, 8:30 am
- Location: France
Re: keyconfig 20110522
To Slickone
I have not found Ctrl+Q in the standard short-cuts page :
http://support.mozilla.org/en-US/kb/Key ... 0shortcuts
If you wish to close Firefox and its screens, 2 codes have been given to me :
-page 151 by Zoolcar9
goQuitApplication()
-page 152 by Dorando
var ss = Components.classes["@mozilla.org/browser/sessionstore;1"].getService(Components.interfaces.nsISessionStore);
ss.setBrowserState('{"windows":[{"tabs":[{}]}]}');
ss.setBrowserState('{"windows":[{}]}');
I have not found Ctrl+Q in the standard short-cuts page :
http://support.mozilla.org/en-US/kb/Key ... 0shortcuts
If you wish to close Firefox and its screens, 2 codes have been given to me :
-page 151 by Zoolcar9
goQuitApplication()
-page 152 by Dorando
var ss = Components.classes["@mozilla.org/browser/sessionstore;1"].getService(Components.interfaces.nsISessionStore);
ss.setBrowserState('{"windows":[{"tabs":[{}]}]}');
ss.setBrowserState('{"windows":[{}]}');
-
- Posts: 155
- Joined: June 7th, 2009, 9:08 am
dorando wrote:You could try to use something likeMorgan B wrote:Maybe something like this could be implemented?:Code: Select all
//@run [url]
Code: Select all
var url = "file:///C:/externalscript1.js";
var request = new XMLHttpRequest();
request.open("GET", "view-source:"+url, false);
request.send(null);
eval(request.responseText);
I just wanted to share an improved version of that:
Code: Select all
(function(f){var r=new XMLHttpRequest();r.open('GET','view-source:file:///C:/Scripts/'+f+'.js',false);r.send(null);return eval('(function(){'+r.responseText+'})();');})
('externalscript1');
Note:
- It doesn't take up as much space as the original.
- It doesn't introduce any new variables.
- It allows for using return in your external scripts without wrapping them into functions.
- It assumes that all your scripts are placed in a folder called "Scripts" directly on the C drive (change if needed).
- Change "externalscript1" into the name of the script you want to run.
- External scripts can access any global variables. Only global variables introduced in external scripts will be accessible from the outside. To avoid using global variables, return any values needed, like this:myScript.js:
Code: Select all
var num = 5, a, b;
[a, b] = (function(f){var r=new XMLHttpRequest();r.open('GET','view-source:file:///C:/Scripts/'+f+'.js',false);r.send(null);return eval('(function(){'+r.responseText+'})();');})
('myScript');
alert(a + b);That should alert 3.5.Code: Select all
return [num / 2, 1];
-
- Posts: 155
- Joined: June 7th, 2009, 9:08 am
Re: keyconfig 20110522
Currently I use this code (which I've copied from this forum, btw) to open Google Translate in the sidebar (I also have a style for it, making it usable in the sidebar):
That works very well.
However, I have an idea:
If there is no selection in the current web page, it should work as it does now.
If there is a selection in the current web page, the selected text should replace the contents of the translate textbox.
Any ideas? Thanks in advance!
Code: Select all
var sidebar = document.getElementById("sidebar");
var sidebarBox = document.getElementById("sidebar-box");
var sidebarSplitter = document.getElementById("sidebar-splitter");
if(sidebar.contentDocument.location != "about:blank" &&
document.getElementById("sidebar-title").value == "Google Translate") {
if(sidebarBox.hidden) {
sidebarBox.setAttribute("sidebarcommand", "viewWebPanelsSidebar");
sidebarBox.hidden = sidebarSplitter.hidden = false;
} else {
sidebarBox.removeAttribute("sidebarcommand");
sidebarBox.hidden = sidebarSplitter.hidden = true;
content.focus();
}
} else {
openWebPanel("Google Translate","http://translate.google.se/?inSidebar#");
sidebarBox.width = 250;
}
That works very well.
However, I have an idea:
If there is no selection in the current web page, it should work as it does now.
If there is a selection in the current web page, the selected text should replace the contents of the translate textbox.
Any ideas? Thanks in advance!
-
- Posts: 6437
- Joined: February 3rd, 2009, 6:29 pm
Re: keyconfig 20110522
@Morgan B
Here is how to set the textarea value with the selection and click the submit button.
I use a listener to do something similar.
Here is how to set the textarea value with the selection and click the submit button.
Code: Select all
var focusedWindow = document.commandDispatcher.focusedWindow;
var selection = focusedWindow.getSelection();
if (!selection.isCollapsed) {
document.getElementById("sidebar").contentDocument.
getElementById("web-panels-browser").contentDocument.
getElementById("source").value = selection.toString();
document.getElementById("sidebar").contentDocument.
getElementById("web-panels-browser").contentDocument.
getElementById("gt-submit").click();
}
I use a listener to do something similar.
Code: Select all
function listener(aEvent) {
aEvent.currentTarget.removeEventListener(aEvent.type, listener, true);
aEvent.originalTarget.getElementById("source").value = text;
aEvent.originalTarget.getElementById("gt-submit").click();
}
var url = "http://translate.google.com/?hl=en&eotf=0&sl=en&tl=ru";
var focusedWindow = document.commandDispatcher.focusedWindow;
var selection = focusedWindow.getSelection();
if (!selection.isCollapsed) {
var text = selection.toString();
var browser = gBrowser.getBrowserForTab(gBrowser.addTab(url));
browser.addEventListener("load", listener, true);
}
-
- Posts: 155
- Joined: June 7th, 2009, 9:08 am
Re: keyconfig 20110522
Thanks morat!
I came up with this:
However, the alert("Wait for page load ..."); hack isn't optimal. I tried to use something like listener version, but I failed - any help?
Moreover, how do I clear the selection?
Thanks again.
I came up with this:
Code: Select all
function transferSelection() {
var selection = document.commandDispatcher.focusedWindow.getSelection();
if (!selection.isCollapsed) {
document.getElementById("sidebar").contentDocument.getElementById("web-panels-browser").contentDocument.getElementById("source").value = selection.toString();
return true;
}
return false;
}
var sidebar = document.getElementById("sidebar"),
sidebarBox = document.getElementById("sidebar-box"),
sidebarSplitter = document.getElementById("sidebar-splitter");
if (sidebar.contentDocument.location !== "about:blank" && document.getElementById("sidebar-title").value === "Google Translate") {
if (sidebarBox.hidden) {
sidebarBox.setAttribute("sidebarcommand", "viewWebPanelsSidebar");
sidebarBox.hidden = sidebarSplitter.hidden = false;
transferSelection();
} else {
if (!transferSelection()) {
sidebarBox.removeAttribute("sidebarcommand");
sidebarBox.hidden = sidebarSplitter.hidden = true;
content.focus();
}
}
} else {
openWebPanel("Google Translate", "http://translate.google.se/?inSidebar#");
sidebarBox.width = 250;
alert("Wait for page load ...");
transferSelection();
}
However, the alert("Wait for page load ..."); hack isn't optimal. I tried to use something like listener version, but I failed - any help?
Moreover, how do I clear the selection?
Thanks again.