📜 ⬆️ ⬇️

Another unnecessary extension for Google Chrome?

Good day, dear habrazhitel. From the name of the publication it becomes clear that under the cut you are waiting for the story of the birth of another unnecessary browser extension from the search giant Google. As you understand, the title is provocative, and the need for an extension for the browser is a rather subjective question. Therefore, I suggest that you independently make a verdict and assess the level of “uselessness” of this product. Or be satisfied with a small amount of time spent in vain and pass by.

fast search screenshot

It all started on an ordinary working day: conducting another text search on a page that is open, as often happens in my favorite browser, Chrome, I wondered: why isn't my dear Chrome looking for text selected with the mouse right away? Every time I have to spend an annoying Pleiades Ctrl + C Ctrl + F Ctrl + V. Maybe there is some other combination: Shift + F or Alt + F? Alas, the lame does not know how - and the point.

I asked colleagues: did they ask a similar question and how do they relate to such an unproductive combination of keyboard shortcuts for a simple search of the selected text? It turned out that no one parses about this. And fox adepts generally grinned so slyly, because the red-haired one can do it. Checked: yes, yes - can. No, well, seriously: doesn’t it bother anyone? After all, the selected text immediately looks for any IDE and even any self-respecting text editor. Why the search giant can not organize a comfortable search on the page in your browser?
')
Checked in Opera 12.15 - can not. Of the lame ones, I checked OperaNext and YaBrowser - they do not know how. Donkey, as it does not progress, in it and after a long Ctrl + C Ctrl + F Ctrl + V nothing is searched without a mouse. Since changing the browser is not an option, with the research in this regard is completed.

Here, once again, I realized that the world is not perfect, and decided: I’ll find an expansion for this business and everything will be settled in a moment. The variant with software for remapping keys, of course, also considered and rejected. As one member of the class said to the other, “this is not our method, buddy.”

You know, chrome extensions are looking for everything and everywhere, except for the selected text on the current page. Well, honestly: you can select any search engine, and search the entire site, both on Wikipedia and in highly specialized areas, and even, probably, among non-open stars, but not what I need. So, after the fifth installed and immediately removed extension, the thought came: why don't I learn to write extensions for, for the present, my favorite browser, using the example of what I need, and not to some customer there?

No sooner said than done. It would be in a fairy tale about Ivanushka-developer, and it took 3 weeks for me, or rather, for us. Well, clean, of course, 30 hours from strength will be typed, for only free time was devoted to this, and even then - not everything. I wanted to scribble over the weekend, on my knee, so to speak, and publish it on Sunday evening. Well, what's the deal then? I planned, without any interfaces to you, to copy the selected text to the clipboard, Ctrl + F for the same, then open the chrome search form and paste the text from the clipboard there. Great solution: save Ctrl + C and Ctrl + V for descendants (do not wear the keyboard). The most silent lamp background expansion for Chrome.

As you know, by this time I was firmly convinced of the imperfection of the mortal world, so the dark side was taking over. I was going to intercept the Ctrl + F event, if there is a selected text to take it to the buffer, emulate the Ctrl + F pressing already for the browser [such non-existent .resumePropagation ()] and into the opened search form, again, emulating pressing Ctrl + V, paste copied text.

For those who started reading the post not from the very beginning, let me remind you: this is my first experience of writing extensions for browsers in general, and for Google Chrome in particular. Yes, this treacherous feint didn’t go away with your ears, security, sandbox and all that ... All because someone eats a lot! Or rather, because event.initKeyboardEvent, as it is not initialized, flies away with zeros. Who does not believe - opens the browser console and inserts the code:

var event = document.createEvent('KeyboardEvent'); event.initKeyboardEvent('keydown', true, true, window, false, false, false, false, 65, 65); event.keyCode = 65; event.which = 65; event.charCode = 65; console.log(event); this.dispatchEvent(event); 


And who knows how to treat, he knows what to do in the comments.

On stackoverflow, they say that this is a webkit bug that has been hanging in the bugtracker since 2012. But a born coder should not teach a good corporation how to fix bugs. Going further ...

Well, I thought nicely. All these dirty methods are not for us, for sure the API for extensions under the browser of the search giant gives access to the search form. I would be immensely happy this time to make a mistake, and let it appear that there is an opportunity to open this field to enter the desired text programmatically from the extension and insert at least a line into it ... Honestly, someone tell me how to finish this functionality and add it to the collaborators if you wish.

Since I did not find such an opportunity, I decided to go to the victorious .crx -> embed my search form on the page and use my search engine. The engine, of course, said very loudly. Since the “Salute” bike loomed, at least I hoped to honestly copy this part from someone on the expanses of these of your Internet sites. And the first options, declared by their authors as a search on the page, did terrible things: they broke the layout of the page, searched all the elements, including script, style, img and others, did not work with UTF-8, and much more than you can frighten the children of programmers.

At this stage, the team has grown, or rather to say: doubled. I asked for help in drawing the search form from a friend of David, who in combination is also a designer. We must pay tribute: the design department did a great job and by the time we left the betting we had a unique custom main expansion menu and 6 themes.

What we have in the end: extensions for chrome with its own search form, with the ability to customize the color to highlight the found text and the current found fragment, text. There is a possibility of intercepting pressing Ctrl + F and F3, this is in case you really like our solution and you get tired of comparing it with Chrome's native search. Especially for comparison with the built-in search, the search form is initially displayed in the upper left corner, you can position it in the upper right corner from the settings in the main menu. On the main settings page, customize the highlight colors and change the UI themes. Also for each topic there is a minimalistic version of the search form: in one line.

The stinginess of the graphics in the post is explained by the fact that all the funny pictures are in the source code on the githaba . Yes, and you can touch the crafts by installing from the store extensions. At the time of this writing, the draft version 1.0.4 has fixed the search bug in hidden elements, i.e. they, of course, were not displayed, but were taken into account when calculating the results of the number of variants found. By hidden means display: none. So if you are lucky and publish 1.0.4 by morning, then you will be happy. And on the githaba , of course, lies fresh.

And of course: I do not PR, and the moral of this story is this: let it happen and this extension will kick Google in improving the usability of its own browser. Thank you all for your attention and, possibly, for quitting read-only. To whom it was completely boring - I give my Scottish Straight:

Source: https://habr.com/ru/post/241199/


All Articles