MozillaZine


keyconfig 20110522

Announce and Discuss the Latest Theme and Extension Releases.
bege
 
Posts: 144
Joined: January 23rd, 2009, 9:14 pm
Location: Germany

Post Posted April 8th, 2021, 6:24 pm

morat wrote:@bege

MailUtils.getFolderForUri was renamed to MailUtils.getExistingFolder.

Reference
http://developer.thunderbird.net/?q=getFolderForURI


Thank you, @morat, but tbkeys still does not save it. There must be a formal fault.

morat
 
Posts: 4842
Joined: February 3rd, 2009, 6:29 pm

Post Posted April 8th, 2021, 9:29 pm

@bege

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);
})();

Troubleshooting for tbkeys: viewtopic.php?p=14872763#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

bege
 
Posts: 144
Joined: January 23rd, 2009, 9:14 pm
Location: Germany

Post Posted April 8th, 2021, 10:42 pm

morat wrote:@bege

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);
})();

Troubleshooting for tbkeys: viewtopic.php?p=14872763#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 code you posted here and the one earlier
Code: Select all
alert(GetFirstSelectedMsgFolder().URI);
show the same folder 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); })();",


After validating it looks like this
Code: Select all
"m": "(function () { var targetUri = "
   mailbox: //me%40gmx.de@mail.gmx.net/Trash"; var targetFolder = MailUtils.getExistingFolder(targetUri); MsgMoveMessage(targetFolder); })();",
(spaces before and after mailbox:)
and throws this error
Code: Select all
Error: Parse error on line 14:
... var targetUri = "   mailbox: //me%40gmx.
----------------------^
Expecting 'EOF', '}', ':', ',', ']', got 'undefined'

morat
 
Posts: 4842
Joined: February 3rd, 2009, 6:29 pm

Post Posted April 9th, 2021, 6:43 am

Try the following main key bindings in settings using the tbkey addon.

Code: Select all
{
  "1": "window.alert('foo');",
  "2": "(function () { var text = 'bar'; window.alert(text); })();"
}

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/

bege
 
Posts: 144
Joined: January 23rd, 2009, 9:14 pm
Location: Germany

Post Posted April 9th, 2021, 7:45 am

@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.

Code: Select all
"b": "(function () { var targetUri = 'mailbox://me%40gmx.de@mail.gmx.net/Trash'; var targetFolder = window.MailUtils.getExistingFolder(targetUri); window.MsgMoveMessage(targetFolder); })();"


Edit: What would it look like if I don't want to move the selected files but clear the whole folder?

morat
 
Posts: 4842
Joined: February 3rd, 2009, 6:29 pm

Post Posted April 9th, 2021, 2:00 pm

bege wrote:clear the whole folder

I don't know what you mean by clear the whole folder.

Here is how to select all the messages in the folder.

Code: Select all
window.goDoCommand('cmd_selectAll');

Here is how to delete all the selected messages in the folder.

Code: Select all
window.goDoCommand('cmd_delete');

bege
 
Posts: 144
Joined: January 23rd, 2009, 9:14 pm
Location: Germany

Post Posted April 9th, 2021, 2:42 pm

@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. :-D

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); })();"

Oomingmak
 
Posts: 203
Joined: July 10th, 2004, 7:46 pm
Location: UK

Post Posted April 14th, 2021, 12:07 am

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?

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});
    }

morat
 
Posts: 4842
Joined: February 3rd, 2009, 6:29 pm

Post Posted April 14th, 2021, 5:06 am

@Oomingmak

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);
})();

Oomingmak
 
Posts: 203
Joined: July 10th, 2004, 7:46 pm
Location: UK

Post Posted April 16th, 2021, 8:58 am

@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?

morat
 
Posts: 4842
Joined: February 3rd, 2009, 6:29 pm

Post Posted April 16th, 2021, 10:40 am

Maybe if the Display Anchors extension is a Legacy addon.

Code: Select all
// simulate button click
var button = document.getElementById("whatever");
button.click();

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: viewtopic.php?p=14865767#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.

Oomingmak
 
Posts: 203
Joined: July 10th, 2004, 7:46 pm
Location: UK

Post Posted April 18th, 2021, 7:49 am

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.

morat
 
Posts: 4842
Joined: February 3rd, 2009, 6:29 pm

Post Posted April 18th, 2021, 9:17 am

@Oomingmak

The following code works here with my setup.

Code: Select all
document.getElementById("display-anchors_robwu_nl-browser-action").click();

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.php?f=23&t=3034448

Oomingmak
 
Posts: 203
Joined: July 10th, 2004, 7:46 pm
Location: UK

Post Posted April 19th, 2021, 6:28 am

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.

morat
 
Posts: 4842
Joined: February 3rd, 2009, 6:29 pm

Post Posted April 19th, 2021, 7:49 am

You're welcome.

Oomingmak wrote:downloading Firefox portable

I already had Firefox portable release build installed. I'm using a fake user agent string.

Return to Extension/Theme Releases


Who is online

Users browsing this forum: No registered users and 1 guest