MozillaZine


Solution to feed text to urlbar or not load when dropping

Talk about add-ons and extension development.
avada
 
Posts: 1884
Joined: February 10th, 2008, 6:30 am
Location: Hungary

Post Posted February 21st, 2021, 1:54 pm

Hi!

Once upon a time you could drop text to the urlbar change it (eg: add keyword) then press enter to load. Bug 1321619 stupidly ruined this.

Which was a lot less of a problem with XUL addons, because I could find one ( caa:addon/simplify-awesome-bar ) that could feed selected text via hotkey to the url bar, which was actually superior to doing it by hand.
But since I let go of old FF and moved to recent versions I constantly miss the functionality and firefox's idiocy of loading everything instantly annoys me to no end.

But of course that's gone. And even though i have set up FF to run XUL addons and userchrome.js scripts, no one fixed it and I have not found a replacement.

So is there any script/addon out there with identical or similar functionality? At least disabling the url bar auto-load nonsense would be nice.

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

Post Posted February 22nd, 2021, 9:27 am

The urlbarBindings.xml file is now the UrlbarInput.jsm file.

Patch for bug 1321619 (see urlbarBindings.xml changes)
http://bug1321619.bmoattachments.org/attachment.cgi?id=8925542

Reference
http://searchfox.org/mozilla-release/search?q=_on_drop&path=UrlbarInput.jsm

I don't know how to change the _on_drop function with a userChrome.js hack.

How to change class prototype
http://stackoverflow.com/questions/37680766

How to set the urlbar...

Code: Select all
gURLBar.value = "test";
gURLBar.focus();

The following code snippets succeed on the about:about page, but fail on the mozillazine.org page.

Code: Select all
(function () {
  var focusedWindow = document.commandDispatcher.focusedWindow;
  var selection = focusedWindow.getSelection();
  if (!selection.isCollapsed) {
    var text = selection.toString();
    console.log(text);
  }
})();

Code: Select all
(function () {
  var selection = window.content.getSelection();
  if (!selection.isCollapsed) {
    var text = selection.toString();
    console.log(text);
  }
})();

Code: Select all
(function () {
  var selectionInfo = BrowserUtils.getSelectionDetails(window);
  if (!selectionInfo.docSelectionIsCollapsed) {
    console.log(selectionInfo.text);
  }
})();

How to get selected text using frame script
http://forums.mozillazine.org/viewtopic.php?p=14839926#p14839926

How to create keyboard shortcut
http://forums.mozillazine.org/viewtopic.php?f=38&t=3069554

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

Post Posted February 22nd, 2021, 10:55 am

@morat
Thanks, I'll check it out.

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

Post Posted Today, 1:47 am

@morat
So I guess there's no readily made solution for this. Can't make much more out of it to be honest. These are past my knowledge.
What I don't see is interaction with the urlbar (or megabar or whatever these days), I wonder if it's possible at all.

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

Post Posted Today, 7:24 am

avada wrote:feed selected text via hotkey to the url bar

It works here when I put all the code snippets together.

Code: Select all
(function () {
  window.__unique_identifier_urlbar = function (event) {
    var script = "data:text/plain," + encodeURIComponent(`
      var data = {};
      data.selection = content.getSelection().toString();
      sendAsyncMessage("foobar", data);
    `);
    gBrowser.selectedBrowser.messageManager.addMessageListener("foobar", function removeMe(message) {
      gBrowser.selectedBrowser.messageManager.removeMessageListener("foobar", removeMe);
      gURLBar.value = message.data.selection;
      gURLBar.focus();
    });
    gBrowser.selectedBrowser.messageManager.loadFrameScript(script, false);
  };
  var keyset = document.getElementById("mainKeyset");
  var key = document.createXULElement("key");
  key.setAttribute("id", "__unique_identifier_key_urlbar");
  key.setAttribute("keycode", "VK_F1");
  key.setAttribute("oncommand", "__unique_identifier_urlbar(event);");
  keyset.appendChild(key);
})();

Instructions:

* open about:config page
* set devtools.chrome.enabled preference to true
* open browser console i.e. tools > web developer > browser console
* copy and paste code into browser console command line
* press enter to run
* focus browser window
* open test page e.g. www.mozillazine.org
* select text
* press f1 to test

Remember to restart the application before running the code because there is an odd bug that if you press f1 before running the code, then pressing f1 after running the code won't work.

If you're already using the f1 shortcut, then you would have to unbind the f1 shortcut or use another shortcut.

Firefox shortcuts
http://support.mozilla.org/kb/keyboard-shortcuts-perform-firefox-tasks-quickly

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 1 guest