Solution to feed text to urlbar or not load when dropping
-
- Posts: 1934
- Joined: February 10th, 2008, 6:30 am
- Location: Hungary
Solution to feed text to urlbar or not load when dropping
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.
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.
-
- Posts: 6421
- Joined: February 3rd, 2009, 6:29 pm
Re: Solution to feed text to urlbar or not load when droppin
The urlbarBindings.xml file is now the UrlbarInput.jsm file.
Patch for bug 1321619 (see urlbarBindings.xml changes)
http://bug1321619.bmoattachments.org/at ... id=8925542
Reference
http://searchfox.org/mozilla-release/se ... rInput.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...
The following code snippets succeed on the about:about page, but fail on the mozillazine.org page.
How to get selected text using frame script
http://forums.mozillazine.org/viewtopic ... #p14839926
How to create keyboard shortcut
http://forums.mozillazine.org/viewtopic ... &t=3069554
Patch for bug 1321619 (see urlbarBindings.xml changes)
http://bug1321619.bmoattachments.org/at ... id=8925542
Reference
http://searchfox.org/mozilla-release/se ... rInput.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();
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);
}
})();
http://forums.mozillazine.org/viewtopic ... #p14839926
How to create keyboard shortcut
http://forums.mozillazine.org/viewtopic ... &t=3069554
-
- Posts: 1934
- Joined: February 10th, 2008, 6:30 am
- Location: Hungary
Re: Solution to feed text to urlbar or not load when droppin
@morat
Thanks, I'll check it out.
Thanks, I'll check it out.
-
- Posts: 1934
- Joined: February 10th, 2008, 6:30 am
- Location: Hungary
Re: Solution to feed text to urlbar or not load when droppin
@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.
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.
-
- Posts: 6421
- Joined: February 3rd, 2009, 6:29 pm
Re: Solution to feed text to urlbar or not load when droppin
It works here when I put all the code snippets together.avada wrote:feed selected text via hotkey to the url bar
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);
})();
* 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- ... ks-quickly
-
- Posts: 1934
- Joined: February 10th, 2008, 6:30 am
- Location: Hungary
Re: Solution to feed text to urlbar or not load when droppin
Thanks for looking into it.morat wrote:It works here when I put all the code snippets together.avada wrote:feed selected text via hotkey to the url bar
Instructions: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); })();
* 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- ... ks-quickly
I get:
Code: Select all
Uncaught TypeError: document.createXULElement is not a function
<anonymous> debugger eval code:16
<anonymous> debugger eval code:21
debugger eval code:16:22
<névtelen> debugger eval code:16
<névtelen> debugger eval code:21
-
- Posts: 6421
- Joined: February 3rd, 2009, 6:29 pm
Re: Solution to feed text to urlbar or not load when droppin
Those addons are obsolete. What version are you running? Are you using e10s?avada wrote:Can't the code be run from Keyconfig or Custom Buttons?
i.e. Menu Bar > Help > Troubleshooting Information > Multiprocess Windows
I think document.createXULElement is available in Firefox 63.
Bug 1479538
http://bugzilla.mozilla.org/show_bug.cgi?id=1479538
Firefox 68 uses the browser.xul page.
Firefox 69 uses the browser.xhtml page so document.createXULElement should be available.
Fix for older versions...
Code: Select all
- var key = document.createXULElement("key");
+ var XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
+ var key = document.createElementNS(XUL_NS, "key");
-
- Posts: 1934
- Joined: February 10th, 2008, 6:30 am
- Location: Hungary
Re: Solution to feed text to urlbar or not load when droppin
I use FF 86 dev. These updated ones work fine enough, from here: https://github.com/xiaoxiaoflood/firefox-scriptsmorat wrote:Those addons are obsolete. What version are you running? Are you using e10s?avada wrote:Can't the code be run from Keyconfig or Custom Buttons?
i.e. Menu Bar > Help > Troubleshooting Information > Multiprocess Windows
I think document.createXULElement is available in Firefox 63.
Bug 1479538
http://bugzilla.mozilla.org/show_bug.cgi?id=1479538
Firefox 68 uses the browser.xul page.
Firefox 69 uses the browser.xhtml page so document.createXULElement should be available.
Fix for older versions...
Code: Select all
- var key = document.createXULElement("key"); + var XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; + var key = document.createElementNS(XUL_NS, "key");
Yes I have e10s enabled.
-
- Posts: 1934
- Joined: February 10th, 2008, 6:30 am
- Location: Hungary
Re: Solution to feed text to urlbar or not load when droppin
@morat
Okay. So it turns out I can use this part of the code to send text to the urlbar:
(Although it doesn't work in input fields, text fields and such)
Is there an easy way to move caret/cursor to the beginning of the urlbar?
Okay. So it turns out I can use this part of the code to send text to the urlbar:
(Although it doesn't work in input fields, text fields and such)
Code: Select all
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.select()
});
gBrowser.selectedBrowser.messageManager.loadFrameScript(script, false);
-
- Posts: 6421
- Joined: February 3rd, 2009, 6:29 pm
Re: Solution to feed text to urlbar or not load when droppin
Try something like:
Reference
http://searchfox.org/mozilla-release/so ... otAtEnd.js
Code: Select all
// Move the caret to the beginning
gURLBar.selectionStart = 0;
gURLBar.selectionEnd = 0;
http://searchfox.org/mozilla-release/so ... otAtEnd.js
-
- Posts: 1934
- Joined: February 10th, 2008, 6:30 am
- Location: Hungary
Re: Solution to feed text to urlbar or not load when droppin
Thanks! That solved the caret issue.morat wrote:Try something like:
ReferenceCode: Select all
// Move the caret to the beginning gURLBar.selectionStart = 0; gURLBar.selectionEnd = 0;
http://searchfox.org/mozilla-release/so ... otAtEnd.js
Do you know why the code doesn't work for inputs, textfields and such?
-
- Posts: 6421
- Joined: February 3rd, 2009, 6:29 pm
Re: Solution to feed text to urlbar or not load when droppin
It works in the web console.
Knowledge Base textbox example:
Test page
http://forums.mozillazine.org/
Knowledge Base textbox example:
Code: Select all
(function () {
var inputs = document.querySelectorAll("input.inputbox.search.itsy");
inputs[1].focus();
inputs[1].value = "example";
inputs[1].selectionStart = 0;
inputs[1].selectionEnd = 0;
})();
http://forums.mozillazine.org/
-
- Posts: 1934
- Joined: February 10th, 2008, 6:30 am
- Location: Hungary
Re: Solution to feed text to urlbar or not load when droppin
I mean that the code above fails to fetch and feed the selected text to the urlbar when I press the hotkey, when in any input field or text field. The URLbar only gets the focus.morat wrote:It works in the web console.
-
- Posts: 6421
- Joined: February 3rd, 2009, 6:29 pm
Re: Solution to feed text to urlbar or not load when droppin
Textareas and text inputs have a differenct selection API. They have selectionStart and selectionEnd properties that are character offsets within the value property of the textarea or input.
Try something like:
Test page
http://www.mozillazine.org/
More info
http://stackoverflow.com/a/20427804
Text To Speech (similar code)
http://custombuttons.sourceforge.net/fo ... ?f=4&t=293
Try something like:
Code: Select all
(function () {
var script = "data:text/plain," + encodeURIComponent(`
var data = {};
data.selection = null;
var selection = content.getSelection();
if (selection.isCollapsed) {
var element = content.document.activeElement;
if (element instanceof HTMLTextAreaElement ||
element instanceof HTMLInputElement &&
(element.type == "text" ||
element.type == "password" ||
element.type == "email" ||
element.type == "search" ||
element.type == "tel" ||
element.type == "url")) {
var start = element.selectionStart;
var end = element.selectionEnd;
data.selection = element.value.substring(start, end);
}
} else {
data.selection = selection.toString();
}
sendAsyncMessage("foobar", data);
`);
gBrowser.selectedBrowser.messageManager.addMessageListener("foobar", function removeMe(message) {
gBrowser.selectedBrowser.messageManager.removeMessageListener("foobar", removeMe);
if (message.data.selection) {
gURLBar.value = message.data.selection;
// gURLBar.focus();
gURLBar.select();
}
});
gBrowser.selectedBrowser.messageManager.loadFrameScript(script, false);
})();
http://www.mozillazine.org/
More info
http://stackoverflow.com/a/20427804
Text To Speech (similar code)
http://custombuttons.sourceforge.net/fo ... ?f=4&t=293
-
- Posts: 1934
- Joined: February 10th, 2008, 6:30 am
- Location: Hungary
Re: Solution to feed text to urlbar or not load when droppin
@morat
Thanks a lot!
It looks like it works perfectly now.
Thanks a lot!
It looks like it works perfectly now.