Enhance the Find command in Firefox

Source: Internet
Author: User
Article Title: Enhance the Find command in Firefox. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

The Find command in Firefox can locate user-specified text in the body of the Web page. This command is an easy-to-use tool, which can be used by most users. However, the use of more powerful Find-like tools can sometimes make it easier to locate text. This article describes how to build such a tool to isolate related texts on Web pages faster by detecting the display and disappearance of adjacent texts.
The text search function in Firefox provides a practical function to highlight adjacent search words and phrases. The additional Firefox extension can be used to combine regular expression search and other text highlighting functions. This article provides the tools and code required to add a custom text search interface to Firefox. Using the Greasemonkey user script and some custom algorithms, you can add the grep-v function to text search-that is, highlight the first search term when the second search term is not near.

Requirements

Hardware

Text search on a typical Web page using older hardware (before January 1, 2002) can be completed almost instantly. However, the Code provided in this article is not designed for high-speed execution, and it may require fast hardware to be executed on large Web pages at satisfactory speeds.

Software

The code in this article is developed in combination with Firefox V2.0 and Greasemonkey V0.7. Using Versions later than them requires testing and may require modifications to ensure functionality. As a Greasemonkey script, the Code provided in this article can be run in any operating system that supports Firefox and Greasemonkey. We are at Microsoft? Windows? And Linux? Ubuntu V7.10 has been tested.

Greasemonkey and Firefox extension

Executing User Modification on the Web page is a task performed by Greasemonkey. The Code provided in this article uses the Greasemonkey framework to search and highlight relevant text. For Greasemonkey Firefox extensions, see references.

Demonstration of the design purpose of this Greasemonkey script

People familiar with UNIX grep commands and common-v Options know how to use indispensable grep to extract relevant text lines from a file. Text files that comply with the UNIX simplicity principle usually store text in line-by-line format, so that you can easily find the text close together. The-v option will output rows that do not find the specified text.

Unlike text files, Web pages usually use tags to separate text from other tags that are displayed in the row in the browser. Different browser window sizes make it difficult to isolate adjacent text based on the expected row location. Table, link, and other text tags also make it difficult to isolate text in the same row.

The algorithms in this article aim to solve these problems, provide simple functions similar to grep, and use functions similar to grep's-v option. This allows the user to search for a word in the text, and then only highlight entries that do not contain another different word. Figure 1 shows an example of this situation.

Figure 1. DOM and DOM hierarchy search examples

In the upper part of the image, the script highlights the search text "DOM ". In the lower half, note how to highlight only the first three "DOM" entries, because the second search text "hierarchy" is found very close to the third "DOM ".

Consider figure 2.


Figure 2. 2008 and 2008 PM search examples

The first part of the graph shows all the 2008 entries, while the second part only displays the entries before noon because of the-v keyword PM. Continue to read more examples of getting all the information and how to implement this function.

[1] [2] [3] [4] [5] Next page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.