keyconfig 20110522

Announce and Discuss the Latest Theme and Extension Releases.
avada
Posts: 1934
Joined: February 10th, 2008, 6:30 am
Location: Hungary

Re: keyconfig 20110522

Post by avada »

I spoke to soon. It seems like this code runs once for every window. So the tabbar only gets hidden if I have an odd number of windows. With even numbe of windows the tabbar ends up gettings shown.
Also, I often see the tabbar being hidden shown and hidden again while windows are opened on startup.

PS:
I also added the code to the mozilla config as per original instructions: it works the same way.
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: keyconfig 20110522

Post by morat »

@avada

Try something like the following code snippet to run once per session.

Code: Select all

(function () {
  var uid = "__unique_identifier_style_sheet_example";
  if (!(uid in window)) {
    var css = [];
    css.push("#TabsToolbar { visibility: collapse !important; }");
    var ios = Components.classes["@mozilla.org/network/io-service;1"].
      getService(Components.interfaces.nsIIOService);
    var uri = ios.newURI("data:text/css," + encodeURIComponent(css.join("\n")), null, null);
    var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"].
      getService(Components.interfaces.nsIStyleSheetService);
    if (sss.sheetRegistered(uri, sss.USER_SHEET)) {
      sss.unregisterSheet(uri, sss.USER_SHEET);
    } else {
      sss.loadAndRegisterSheet(uri, sss.USER_SHEET);
    }
    window[uid] = true;
  }
})();
You may have to create an about:config preference or use pure javascript to hide the tabs toolbar.
avada
Posts: 1934
Joined: February 10th, 2008, 6:30 am
Location: Hungary

Re: keyconfig 20110522

Post by avada »

How do I get it to run once only?
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: keyconfig 20110522

Post by morat »

@avada

Answer: http://forums.mozillazine.org/viewtopic ... #p14896201

You have a habit of asking the same questions.

:P
avada
Posts: 1934
Joined: February 10th, 2008, 6:30 am
Location: Hungary

Re: keyconfig 20110522

Post by avada »

Hi!

I have this code to download with yt-dlp, and to see the errors if ther are any:

Code: Select all

/*Code*/
var uid = "__unique_identifier_" + this.id;
var script = "data:text/plain," + encodeURIComponent(`
  var data = {};
  data.href = content.location.href;
  sendAsyncMessage("${uid}", data);
`);
gBrowser.selectedBrowser.messageManager.addMessageListener(uid, function listener(message) {
  gBrowser.selectedBrowser.messageManager.removeMessageListener(uid, listener);
  var url = message.data.href;
  var localFile = Components.classes["@mozilla.org/file/local;1"].
    createInstance(Components.interfaces.nsIFile);
  var process = Components.classes["@mozilla.org/process/util;1"].
    createInstance(Components.interfaces.nsIProcess);
  var args = ["/k", "D:\\Programok\\videó\\CLI\\youtube-dl.exe", "--no-playlist", "-o", "D:\\Letöltés\\%(title)s.%(ext)s", url];
  localFile.initWithPath("c:\\Windows\\System32\\cmd.exe");
  process.init(localFile);
  process.run(false, args, args.length);
});
gBrowser.selectedBrowser.messageManager.loadFrameScript(script, false);
And it works fine, unless there are characters in the url that are not handled right. In which case I get errors. For example.

This is the commands that was run:

Code: Select all

 "C:\Windows\System32\cmd.exe" /k D:\Programok\videó\CLI\youtube-dl.exe --no-playlist -o D:\Letöltés\%(title)s.%(ext)s https://www.youtube.com/watch?v=4RhOKdaREK0&list=PLpZox6Cvj7bX9QA-37DQKw9rC8SnDxNUf&index=7
The dowload seems to complete successfully in this case, But I got errors like this at the end:

Code: Select all

'list' is not recognized as an internal or external command,
operable program or batch file.
'index' is not recognized as an internal or external command,
operable program or batch file.
I'm guessing it's because the & characters in the url and maybe because the parameters are passed twice. I just have no clue how to prevent this error. And sometimes these parts after the & characters of the url matter. (In this case, if I tried to download the whole playlist)

Any ideas?
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: keyconfig 20110522

Post by morat »

@avada

Try using "process.runw" instead of "process.run".

Try quoting the youtube url.

Similar thread
http://custombuttons.sourceforge.net/fo ... 743#p88743

Maybe you could prune the youtube url. Remove the list and index sections.
avada
Posts: 1934
Joined: February 10th, 2008, 6:30 am
Location: Hungary

Re: keyconfig 20110522

Post by avada »

morat wrote:@avada

Try using "process.runw" instead of "process.run".

Try quoting the youtube url.

Similar thread
http://custombuttons.sourceforge.net/fo ... 743#p88743

Maybe you could prune the youtube url. Remove the list and index sections.
Never could figure out how to append quotes and save it in the url variable.

I also have a button to download playlists, where removing those parts is not possible. Even if I knew how to do it.
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: keyconfig 20110522

Post by morat »

@avada

I got it working with yt-dlp_x86.exe on Windows 10 32-bit.

Test page
http://www.youtube.com/watch?v=7Vy8970q ... n2&index=1

Code: Select all

D:\Applications\Media\YouTube\yt-dlp_x86.exe --no-playlist -o "E:\test\%(title)s.%(ext)s" "https://www.youtube.com/watch?v=7Vy8970q0Xc&list=PLwJ2VKmefmxpUJEGB1ff6yUZ5Zd7Gegn2&index=1"

Code: Select all

(function () {
  var url = "https://www.youtube.com/watch?v=7Vy8970q0Xc&list=PLwJ2VKmefmxpUJEGB1ff6yUZ5Zd7Gegn2&index=1";
  url = url.replace(/&/g, "^&");
  var file = Components.classes["@mozilla.org/file/local;1"].
    createInstance(Components.interfaces.nsIFile);
  var process = Components.classes["@mozilla.org/process/util;1"].
    createInstance(Components.interfaces.nsIProcess);
  var args = ["/k", "D:\\Applications\\Media\\YouTube\\yt-dlp_x86.exe", "--no-playlist", "-o", "E:\\test\\%(title)s.%(ext)s", url];
  file.initWithPath("C:\\Windows\\System32\\cmd.exe");
  process.init(file);
  process.run(false, args, args.length);
})();
The & is used to separate commands in the cmd.exe window. Therefore, you can use the ^ to escape the &.

More info
http://stackoverflow.com/questions/1327431
avada
Posts: 1934
Joined: February 10th, 2008, 6:30 am
Location: Hungary

Re: keyconfig 20110522

Post by avada »

morat wrote:@avada

I got it working with yt-dlp_x86.exe on Windows 10 32-bit.

Test page
http://www.youtube.com/watch?v=7Vy8970q ... n2&index=1

Code: Select all

D:\Applications\Media\YouTube\yt-dlp_x86.exe --no-playlist -o "E:\test\%(title)s.%(ext)s" "https://www.youtube.com/watch?v=7Vy8970q0Xc&list=PLwJ2VKmefmxpUJEGB1ff6yUZ5Zd7Gegn2&index=1"

Code: Select all

(function () {
  var url = "https://www.youtube.com/watch?v=7Vy8970q0Xc&list=PLwJ2VKmefmxpUJEGB1ff6yUZ5Zd7Gegn2&index=1";
  url = url.replace(/&/g, "^&");
  var file = Components.classes["@mozilla.org/file/local;1"].
    createInstance(Components.interfaces.nsIFile);
  var process = Components.classes["@mozilla.org/process/util;1"].
    createInstance(Components.interfaces.nsIProcess);
  var args = ["/k", "D:\\Applications\\Media\\YouTube\\yt-dlp_x86.exe", "--no-playlist", "-o", "E:\\test\\%(title)s.%(ext)s", url];
  file.initWithPath("C:\\Windows\\System32\\cmd.exe");
  process.init(file);
  process.run(false, args, args.length);
})();
The & is used to separate commands in the cmd.exe window. Therefore, you can use the ^ to escape the &.

More info
http://stackoverflow.com/questions/1327431
Thanks!
Didn't think the solution would be as simple as adding a single line that adds ^ characters.
bege
Posts: 153
Joined: January 23rd, 2009, 9:14 pm
Location: Germany

Re: keyconfig 20110522

Post by bege »

Hello,
how must I edit this function to truly delete the messages instead of moving them to (local) trash?

Code: Select all

"alt+shift+p": "(function () { 
var targetUri = 'mailbox://nobody@Local%20Folders/Trash/GMX'; 
var sourceUri = 'imap://myaccount@imap.gmx.net/Gel&APY-scht'; 
var targetFolder = window.MailUtils.getExistingFolder(targetUri); 
var sourceFolder = window.MailUtils.getExistingFolder(sourceUri); 
window.gFolderTreeView.selectFolder(sourceFolder); 
window.goDoCommand('cmd_selectAll'); 
window.MsgMoveMessage(targetFolder); })();",
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: keyconfig 20110522

Post by morat »

@bege

Delete commands:

Code: Select all

goDoCommand('cmd_delete');

Code: Select all

goDoCommand('cmd_shiftDelete');
* Delete - Delete message
* Shift + Delete - Delete message bypassing trash (no undo)

Thunderbird keyboard shortcuts
http://support.mozilla.org/kb/keyboard- ... hunderbird
bege
Posts: 153
Joined: January 23rd, 2009, 9:14 pm
Location: Germany

Re: keyconfig 20110522

Post by bege »

@morat
Thank you very much!
The result:

Code: Select all

"alt+shift+s": "(function () { 
var sourceUri = 'imap://myaccount@imap.gmx.net/Spamverdacht'; 
var sourceFolder = window.MailUtils.getExistingFolder(sourceUri); 
window.gFolderTreeView.selectFolder(sourceFolder); 
window.goDoCommand('cmd_selectAll'); 
window.goDoCommand('cmd_shiftDelete'); })();"
PlodPointer
Posts: 2
Joined: July 6th, 2023, 7:47 am

Re: keyconfig 20110522

Post by PlodPointer »

Hello,

I am trying to redefine some default shortcuts, currently struggling to get the scroll commands (arrow keys), I searched in the browser toolbox but found nothing, it seems hard-coded in the omni.ja file.
Someone asked the same question in the past but it is way outdated.
EDIT: Solved, found this masterpiece

I am also trying to completely clear input focus when pressing Esc key, would be glad to get an answer on this aswell...

Thanks [-o<
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: keyconfig 20110522

Post by morat »

@PlodPointer

Here is how to run the scrollBy method in the content window.

Code: Select all

gBrowser.selectedBrowser.messageManager.loadFrameScript("data:,content.scrollBy(0, 100)", false);
scrollBy
http://developer.mozilla.org/docs/Web/A ... w/scrollBy
PlodPointer wrote:clear input focus
Try these:

Code: Select all

document.activeElement.blur(); // unfocus active element

Code: Select all

document.commandDispatcher.focusedElement.blur(); // unfocus focused element

Code: Select all

goDoCommand("cmd_selectAll"); goDoCommand("cmd_delete"); // clear
PlodPointer
Posts: 2
Joined: July 6th, 2023, 7:47 am

Re: keyconfig 20110522

Post by PlodPointer »

@morat Thank you for your answer!

I successfully removed focus on inputs using document.activeElement.blur(), but it is not working when trying to leave URL bar focus, it seems there is a bug since years about that one.

Do you know how can I manipulate the web page DOM through autoconfig? I am trying to focus inputs with a shortcut, but I can't access elements, only the browser ones.

It currently lacks documentation, or at best outdated most of the time, where can I find some about autoconfig? (I am digging into searchfox.org at the moment).

Thank you for your help.
Post Reply