Thank you, @morat, but tbkeys still does not save it. There must be a formal fault.morat wrote:@bege
MailUtils.getFolderForUri was renamed to MailUtils.getExistingFolder.
Reference
http://developer.thunderbird.net/?q=getFolderForURI
keyconfig 20110522
-
- Posts: 153
- Joined: January 23rd, 2009, 9:14 pm
- Location: Germany
Re: keyconfig 20110522
-
- Posts: 6437
- Joined: February 3rd, 2009, 6:29 pm
Re: keyconfig 20110522
@bege
The MailUtils.getExistingFolder method works here in the error console.
Troubleshooting for tbkeys: http://forums.mozillazine.org/viewtopic ... #p14872763
Remember to include the window object in custom commands.
Common key bindings (notice the window object)
http://github.com/wshanks/tbkeys#common-key-bindings
The MailUtils.getExistingFolder method works here in the error console.
Code: Select all
(function () {
var targetUri = gFolderDisplay.displayedFolder.URI;
var targetFolder = MailUtils.getExistingFolder(targetUri);
alert(targetUri + "\n" + targetFolder.URI);
})();
Remember to include the window object in custom commands.
Common key bindings (notice the window object)
http://github.com/wshanks/tbkeys#common-key-bindings
-
- Posts: 153
- Joined: January 23rd, 2009, 9:14 pm
- Location: Germany
Re: keyconfig 20110522
The code you posted here and the one earliermorat wrote:@bege
The MailUtils.getExistingFolder method works here in the error console.
Troubleshooting for tbkeys: http://forums.mozillazine.org/viewtopic ... #p14872763Code: Select all
(function () { var targetUri = gFolderDisplay.displayedFolder.URI; var targetFolder = MailUtils.getExistingFolder(targetUri); alert(targetUri + "\n" + targetFolder.URI); })();
Remember to include the window object in custom commands.
Common key bindings (notice the window object)
http://github.com/wshanks/tbkeys#common-key-bindings
Code: Select all
alert(GetFirstSelectedMsgFolder().URI);
In the JSON validator the line looks like this after I pasted it
Code: Select all
"m": "(function () { var targetUri = "mailbox://me%40gmx.de@mail.gmx.net/Trash"; var targetFolder = MailUtils.getExistingFolder(targetUri); MsgMoveMessage(targetFolder); })();",
Code: Select all
"m": "(function () { var targetUri = "
mailbox: //me%40gmx.de@mail.gmx.net/Trash"; var targetFolder = MailUtils.getExistingFolder(targetUri); MsgMoveMessage(targetFolder); })();",
and throws this error
Code: Select all
Error: Parse error on line 14:
... var targetUri = " mailbox: //me%40gmx.
----------------------^
Expecting 'EOF', '}', ':', ',', ']', got 'undefined'
-
- Posts: 6437
- Joined: February 3rd, 2009, 6:29 pm
Re: keyconfig 20110522
Try the following main key bindings in settings using the tbkey addon.
Notice the single quote characters within the double quote characters.
Notice the window objects. Without the window object, alert fails with a reference error.
Notice the lack of a trailing comma after the last key so the input is a valid JSON string.
JSON Validator
http://jsonlint.com/
Code: Select all
{
"1": "window.alert('foo');",
"2": "(function () { var text = 'bar'; window.alert(text); })();"
}
Notice the window objects. Without the window object, alert fails with a reference error.
Notice the lack of a trailing comma after the last key so the input is a valid JSON string.
JSON Validator
http://jsonlint.com/
-
- Posts: 153
- Joined: January 23rd, 2009, 9:14 pm
- Location: Germany
Re: keyconfig 20110522
@morat
Eventually I got it!
The mailbox URI must be enclosed in single quotes, not in double quotes, and the functions need the "window." as you already wrote.
In case someone can use this code for a similar task: This code moves the selected files to the specified folder.
Edit: What would it look like if I don't want to move the selected files but clear the whole folder?
Eventually I got it!
The mailbox URI must be enclosed in single quotes, not in double quotes, and the functions need the "window." as you already wrote.
In case someone can use this code for a similar task: This code moves the selected files to the specified folder.
Code: Select all
"b": "(function () { var targetUri = 'mailbox://me%40gmx.de@mail.gmx.net/Trash'; var targetFolder = window.MailUtils.getExistingFolder(targetUri); window.MsgMoveMessage(targetFolder); })();"
-
- Posts: 6437
- Joined: February 3rd, 2009, 6:29 pm
Re: keyconfig 20110522
I don't know what you mean by clear the whole folder.bege wrote:clear the whole folder
Here is how to select all the messages in the folder.
Code: Select all
window.goDoCommand('cmd_selectAll');
Code: Select all
window.goDoCommand('cmd_delete');
-
- Posts: 153
- Joined: January 23rd, 2009, 9:14 pm
- Location: Germany
Re: keyconfig 20110522
@morat
Thank you very much, that is exactly what I meant: Only click on the folder in the folder tree and tap "b": then all files in that folder are being moved to the specified folder. It works like a charm.
Thank you very much, that is exactly what I meant: Only click on the folder in the folder tree and tap "b": then all files in that folder are being moved to the specified folder. It works like a charm.
Code: Select all
"b": "(function () { var targetUri = 'mailbox://me%40gmx.de@mail.gmx.net/Trash'; var targetFolder = window.MailUtils.getExistingFolder(targetUri); window.goDoCommand('cmd_selectAll'); window.MsgMoveMessage(targetFolder); })();"
-
- Posts: 203
- Joined: July 10th, 2004, 7:46 pm
- Location: UK
Re: keyconfig 20110522
I used to use the code below in KeyConfig in conjunction with 'Biscuit' (an extension for managing cookies) to open a window showing only the cookies for the current domain. However, the code only works when e10s multi-process is disabled.
All of the rest of the extension's functions work perfectly with e10s enabled, so it's still a very usable extension apart from that one important missing feature.
Seeing as it's only the opening of a window, I'm hoping that it may be possible to amend the code below so that it can work with e10s enabled (instead of requiring an extension rewrite). Is this do-able?
All of the rest of the extension's functions work perfectly with e10s enabled, so it's still a very usable extension apart from that one important missing feature.
Seeing as it's only the opening of a window, I'm hoping that it may be possible to amend the code below so that it can work with e10s enabled (instead of requiring an extension rewrite). Is this do-able?
Code: Select all
// show cookies for current domain
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Browser:Cookies");
var eTLDService = Components.classes["@mozilla.org/network/effective-tld-service;1"].
getService(Components.interfaces.nsIEffectiveTLDService);
var eTLD;
var uri = content.document.documentURIObject;
try {
eTLD = eTLDService.getBaseDomain(uri);
} catch (e) {
eTLD = uri.asciiHost;
}
if (win) {
win.gCookiesWindow.setFilter(eTLD);
win.focus();
} else {
var url = "chrome://browser/content/preferences/cookies.xul";
window.openDialog(url, "Browser:Cookies", "", {filterString : eTLD});
}
-
- Posts: 6437
- Joined: February 3rd, 2009, 6:29 pm
Re: keyconfig 20110522
@Oomingmak
Try something like:
Try something like:
Code: Select all
(function () {
var script = "data:text/plain," + encodeURIComponent(`
var data = {};
data.href = content.location.href;
sendAsyncMessage("foobar", data);
`);
gBrowser.selectedBrowser.messageManager.addMessageListener("foobar", function removeMe(message) {
gBrowser.selectedBrowser.messageManager.removeMessageListener("foobar", removeMe);
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Browser:Cookies");
var eTLDService = Components.classes["@mozilla.org/network/effective-tld-service;1"].
getService(Components.interfaces.nsIEffectiveTLDService);
var eTLD;
var ios = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var uri = ios.newURI(message.data.href, null, null);
try {
eTLD = eTLDService.getBaseDomain(uri);
} catch (e) {
eTLD = uri.asciiHost;
}
if (win) {
win.gCookiesWindow.setFilter(eTLD);
win.focus();
} else {
var url = "chrome://browser/content/preferences/cookies.xul";
var features = "resizable,dialog=no,centerscreen";
window.openDialog(url, "Browser:Cookies", features, {filterString : eTLD});
}
});
gBrowser.selectedBrowser.messageManager.loadFrameScript(script, false);
})();
-
- Posts: 203
- Joined: July 10th, 2004, 7:46 pm
- Location: UK
Re: keyconfig 20110522
@morat
Wow, you never cease to amaze me! I was reluctant to ask this question at first (because I thought that it was such a long-shot) but your solution works perfectly. Thank you so much!
While I am here, just one more question if I may:
I have another extension (Display Anchors) that adds a toolbar button to allow web-page anchor identifiers to be turned on or off. The extension also has a hotkey to do the same thing, but the hotkey only works after the toolbar button has been pressed at least once, which is annoying.
In order to be able to use the hotkey without having to press the toolbar button first, I thought that I could use Keyconfig to simulate pressing the extension's toolbar button each time that the hotkey is pressed.
Is this possible? and if so, would you need any specific info about the extension, or can simulated toolbar-button clicking be achieved using a generic template into which I could just drop the name / id of the relevant button?
Wow, you never cease to amaze me! I was reluctant to ask this question at first (because I thought that it was such a long-shot) but your solution works perfectly. Thank you so much!
While I am here, just one more question if I may:
I have another extension (Display Anchors) that adds a toolbar button to allow web-page anchor identifiers to be turned on or off. The extension also has a hotkey to do the same thing, but the hotkey only works after the toolbar button has been pressed at least once, which is annoying.
In order to be able to use the hotkey without having to press the toolbar button first, I thought that I could use Keyconfig to simulate pressing the extension's toolbar button each time that the hotkey is pressed.
Is this possible? and if so, would you need any specific info about the extension, or can simulated toolbar-button clicking be achieved using a generic template into which I could just drop the name / id of the relevant button?
-
- Posts: 6437
- Joined: February 3rd, 2009, 6:29 pm
Re: keyconfig 20110522
Maybe if the Display Anchors extension is a Legacy addon.
Legacy addon has an install.rdf file.
WebExtensions addon has a manifest.json file.
Display #Anchors 1.2 is a WebExtensions addon.
Display #Anchors
http://addons.mozilla.org/firefox/addon/779544
WebExtensions are more complex.
You can run WebExtensions API using the browser console.
More info: http://forums.mozillazine.org/viewtopic ... #p14865767
AFAIK... You can't get the background page using the browser console.
WebExtensions browser.runtime.getBackgroundPage()
http://developer.mozilla.org/docs/Mozil ... groundPage
getBackgroundPage doesn't work in private mode
http://bugzilla.mozilla.org/show_bug.cgi?id=1329304
And getBackgroundPage doesn't work using the browser console in normal mode.
Code: Select all
// simulate button click
var button = document.getElementById("whatever");
button.click();
WebExtensions addon has a manifest.json file.
Display #Anchors 1.2 is a WebExtensions addon.
Display #Anchors
http://addons.mozilla.org/firefox/addon/779544
WebExtensions are more complex.
You can run WebExtensions API using the browser console.
More info: http://forums.mozillazine.org/viewtopic ... #p14865767
AFAIK... You can't get the background page using the browser console.
WebExtensions browser.runtime.getBackgroundPage()
http://developer.mozilla.org/docs/Mozil ... groundPage
getBackgroundPage doesn't work in private mode
http://bugzilla.mozilla.org/show_bug.cgi?id=1329304
And getBackgroundPage doesn't work using the browser console in normal mode.
-
- Posts: 203
- Joined: July 10th, 2004, 7:46 pm
- Location: UK
Re: keyconfig 20110522
Thank you for your reply, morat.
What a pity that the extension is not a legacy addon, because that would have been so simple to fix based on your code example.
I'm not sure that I understand the situation with WebExtensions (please excuse my ignorance). Are you saying that it can't be done at all with a WebExtensions (due to not being able to get the background page)? Or is it possible, but just more complicated?
I tried following the instructions on your linked post anyway, but I don't know what is supposed to happen (or what I'm supposed to do) after I've pasted the code into the console as you described. I changed the 'name' value in the code from uBlock to the name that's specified in the Display Anchors manifest.json, but when I tried to execute the code I just got an error message:
Uncaught ReferenceError: Services is not defined
<anonymous> debugger eval code:2
<anonymous> debugger eval code:29
I wish I knew js because I suspect that I could easily fix the issue within the extension itself (which has surprisingly few lines of code) seeing as the hotkey does work without requiring the initial toolbar button press when it's used in Firefox. However, the extension has been coded without taking into consideration compatibility with WebExtension-capable legacy browsers (which is understandable, given how small that target audience is). I'm using Display Anchors in the latest version of Waterfox released last month (2021-03), but when I ran the debug test I did that in the latest version of Firefox (v87.0) just so that I could more closely follow the instructions in your linked post.
What a pity that the extension is not a legacy addon, because that would have been so simple to fix based on your code example.
I'm not sure that I understand the situation with WebExtensions (please excuse my ignorance). Are you saying that it can't be done at all with a WebExtensions (due to not being able to get the background page)? Or is it possible, but just more complicated?
I tried following the instructions on your linked post anyway, but I don't know what is supposed to happen (or what I'm supposed to do) after I've pasted the code into the console as you described. I changed the 'name' value in the code from uBlock to the name that's specified in the Display Anchors manifest.json, but when I tried to execute the code I just got an error message:
Uncaught ReferenceError: Services is not defined
<anonymous> debugger eval code:2
<anonymous> debugger eval code:29
I wish I knew js because I suspect that I could easily fix the issue within the extension itself (which has surprisingly few lines of code) seeing as the hotkey does work without requiring the initial toolbar button press when it's used in Firefox. However, the extension has been coded without taking into consideration compatibility with WebExtension-capable legacy browsers (which is understandable, given how small that target audience is). I'm using Display Anchors in the latest version of Waterfox released last month (2021-03), but when I ran the debug test I did that in the latest version of Firefox (v87.0) just so that I could more closely follow the instructions in your linked post.
-
- Posts: 6437
- Joined: February 3rd, 2009, 6:29 pm
Re: keyconfig 20110522
@Oomingmak
The following code works here with my setup.
Display #Anchors 1.3
Firefox Portable 87.0
Windows 10 Pro 20H2 32-bit
And the Shift+Alt+A shortcut works after restart. (as you said)
Test page
http://www.mozillazine.org/
It's more complex if the button is in a popup like the zapper button for the uBO addon.
P.S.
You don't need to know javascript to get a button id.
How do we get DOM info for userChrome in 57+
http://forums.mozillazine.org/viewtopic ... &t=3034448
The following code works here with my setup.
Code: Select all
document.getElementById("display-anchors_robwu_nl-browser-action").click();
Firefox Portable 87.0
Windows 10 Pro 20H2 32-bit
And the Shift+Alt+A shortcut works after restart. (as you said)
Test page
http://www.mozillazine.org/
It's more complex if the button is in a popup like the zapper button for the uBO addon.
P.S.
You don't need to know javascript to get a button id.
How do we get DOM info for userChrome in 57+
http://forums.mozillazine.org/viewtopic ... &t=3034448
-
- Posts: 203
- Joined: July 10th, 2004, 7:46 pm
- Location: UK
Re: keyconfig 20110522
Hi morat,
Thank you for going through all the trouble of downloading Firefox portable (and copy of the Display Anchors extension) to test it out.
I got a bit confused regarding what the situation was with WebExtensions (especially seeing as I was only getting error messages in the browser console). Getting the DOM info for an item is easy (most of the time); my problem was trying to get the correct command into which to insert the DOM info.
Anyway, I'm delighted to report that the code you provided works perfectly in Waterfox! So, yet again, you have come to my rescue. I really appreciate it.
Thanks.
Thank you for going through all the trouble of downloading Firefox portable (and copy of the Display Anchors extension) to test it out.
I got a bit confused regarding what the situation was with WebExtensions (especially seeing as I was only getting error messages in the browser console). Getting the DOM info for an item is easy (most of the time); my problem was trying to get the correct command into which to insert the DOM info.
Anyway, I'm delighted to report that the code you provided works perfectly in Waterfox! So, yet again, you have come to my rescue. I really appreciate it.
Thanks.
-
- Posts: 6437
- Joined: February 3rd, 2009, 6:29 pm
Re: keyconfig 20110522
You're welcome.
I already had Firefox portable release build installed. I'm using a fake user agent string.Oomingmak wrote:downloading Firefox portable