As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label focus. Show all posts

After I published the method using Vimperator, I found out it won’t work if user switch to other tab before the page is loaded. The emulated keypress will be only emulated the currently active tab, and that may not be YouTube or Google Groups. Since Google Groups started the new interface, I removed that part of code from my Vimperator configuration, Google Groups doesn’t steal focus anymore. Instead, I even enable Pass Through mode for Google Groups.

A while earlier, I was seeking if there is a way I could open a link from commandline and Firefox does not raise its window. I haven’t found an answer for that but I accidentally stumbled on an answer on Super User and later I found how to disable form focusing on MozillaZine Knowledge Base.

1   Quick Solution

If you are in a hurry, here is what you should do, create a user.js1 in your Firefox profile directory, if it’s not present, with the following content to change Security Policies aka Configurable Security Policies or CAPS for short:


user_pref("capability.policy.policynames", "NoDamnFocusThieves");
user_pref("capability.policy.NoDamnFocusThieves.sites", "http://www.youtube.com http://www.google.com");
// Won't work on Google Search, only domain level is valid
// user_pref("capability.policy.NoDamnFocusThieves.sites", "http://www.google.com/search");
user_pref("capability.policy.NoDamnFocusThieves.HTMLInputElement.focus", "noAccess");

It will disable pages under www.youtube.com and www.google.com to access HTML DOM element’s focus() function.

[1]not editing on prefs.js, it will get overwritten if Firefox is running. If you insist to have setting in prefs.js, you can use about:config page to add those but they will not show up, however, they are really created.

2   About sites

If you need to disable multiple sites, you can create multiple policy names, or you can just put them all into one policy’s sites separated by space. Note that you can NOT specify path, e.g. http://www.google.com/search, it won’t work.

If you disable on Google, it will cause you some trouble. The current Google Search will add the letters, which you type without having search box focused, into search box. But since you disable on the site, the script can’t use focus(), the cursor won’t be in search box and spaces seem to be added instead of what you type. I don’t know why and I am not interested, because I use Vimperator, I can always use hint to select input box.

There is one site this method doesn’t work, Google Dictionary, it still can make the input box get the focus. No idea how it could still set the focus.

For a long time, YouTube and Google Groups always make me groan. I often ended up with searching something like o gm, I was opening Gmail actually.

Their search boxes steal my precious control. If you are using that slow mouse—point, point, and click, you probably have never noticed that YouTube and Google Groups kindly help you enter the search box, they thought it’s convenient for users. Wrong! When most of sites don’t help users with that—and “why they don’t? Think, YouTube and Google Groups!” you are only creating burden for users.

Luckily, it’s easy to fix with Vimperator:

" Get my damn focus back
autocmd PageLoad (www\\.youtube|groups.google)\\.com :normal <Esc>

I use autocmd to emulate a keypress of Escape to exiting Input mode.

A side note if you are also using Gmail’s and Reader’s shortcut keys a lot, the following command let you enter Pass through mode automatically:

" Enter passthrough mode automatically in Gmail, Reader
autocmd LocationChange .* js modes.passAllKeys = /(mail\.google\.com|www\.google\.com\/reader\/)/.test(buffer.URL)

I was hoping I could find a way to re-map a and A because I usually have to re-add bookmark after I wanted to Mark all as read using A, it’s a removal of bookmark. I couldn’t find any, but the method above is acceptable.