Enhanced word highlight

Enhanced keywords highlight for Search Engines and All !

As of 2023-05-23. See the latest version.

Author
hzhbest
Ratings
0 0 0
Version
1.7.4
Created
2014-12-31
Updated
2023-05-23
Size
151 KB
License
GNU GPLv3
Applies to
All sites

A powerful word highlight script that can do not just highlight.

Notice

  • Tested under Firefox with Greasemonkey. Some enhanced functions may not be available in other browsers(see "For Chrome Users" below).
  • If you are a Readability addon user, note that the script will only work when activated AFTER activating Readability. Good solution is not currently available.
  • Since Firefox4 uses Ctrl-/ to toggle Addon bar, I change the shortcut keys to activate the keyword inputbox to Alt-/ , while Alt-. (that is Alt key and Period key) replace the old shortcut Alt-/ to edit keywords.

For Chrome Users

Better install Chrome extension Tampermonkey before installing this script to enable the script's full function in Chrome.

Introduction

Enhanced word highlight is an enhanced version of "word highlight" script, which has the original features below:

  1. Auto-highlight: Automatically highlight search keywords in Google result pages as well as pages opened from Google result pages;
  2. Inherit-highlight: highlighted keywords will also be automatically highlighted in subsequent pages in the same tab/window;
  3. Manually add keywords (support regular expression) to highlight in any pages with "Alt-/" shortcut;
  4. Provide a map and counts of highlighted keywords;
  5. Let you quickly navigate through the keywords on the map or word by word on the panel.

... and my enhanced and additional features:

  1. Auto-highlight also covers search keywords in MORE result pages (e.g. Bing);
  2. A "Lock" button to store one set of keywords and highlight them on whatever pages;
  3. Stylized panel and keyword inputbox with a more usable and slim look;
  4. You can press "Alt-/" shortcut once and input your keywords multiple times (press "Enter" to add while immediately get the highlight), with "Esc" to exit; or input multiple keywords separated by space at once;
  5. Seamless highlight style;
  6. More handy approaches to navigate through highlight occurrences, such as clicking a keyword on the panel, or even just scroll the mouse wheel over it;
  7. Strengthened auto-pager tools support;
  8. And more...

Instruction

  • Auto highlight search keywords: On supported search engines such as Google, search keywords are automatically highlighted.
  • Manual adding words to highlight: Press "Alt-/" key combination to active the keyword inputbox, input a word and press "Enter" key or click the "→" button on the right to highlight the word. You can input a set of keywords separated by space, or input multiple times (see the paragraph for more info). Newly inputted keywords will by default be added to the end of highlight list. Press "Esc" or click the "X" button to close the keyword inputbox. #Tips: regular expression is also supported (see the paragraph for more info).
  • To highlight keywords in selected text: Select the target text, press "Alt-/" key combination and the keywords in the selected text will instantly highlighted.
  • To highlight a whole new set of keywords: After activating the keyword inputbox by "Alt-/", click the checkbox in the left of the keyword inputbox; the label will turn from "Add" to "New", then only the newly inputted keywords will be highlighted and old highlights will be erased.
  • To navigate between occurrences of highlighted keywords: On the panel, LEFT click a keyword button to navigate to this keyword's next occurrence; RIGHT click to navigate to its previous occurrence. Hovering over a keyword button and scroll the mouse wheel will also navigate in similar way. #Tips: You can also use "n" and "Shift-n" shortcut keys to navigate to next / previous keyword occurrence without specifying one.
  • To toggle highlight of a keyword: Click the checkbox at the top-right corner of the keyword button to toggle.
  • To toggle highlight of all keywords: Click the "O" button on the panel to toggle. #Tips: You can also press "Alt-," (Alt key and the comma key) to toggle.
  • To refresh highlight: If some dynamic content wasn't highlighted, you can refresh highlight by pressing "r" key outside of any inputbox.
  • To disable highlight: Click the "X" button on the panel to close the panel and erase all highlights. #IMPORTANT: When highlight is disabled, auto-highlight in the current window / tab will also be disabled. However locked keywords will not be affected.
  • To restore highlights after disabling: When you press "Alt-/" without selecting any text, the previously highlighted keywords will be shown in the keyword inputbox, then you can press "Enter" or click the "→" button to re-highlight them.
  • To check all the occurrences of highlighted keywords: Move the cursor over the panel and a highlight map will appear; click or drag on the map and the page will scroll to the corresponding position.
  • To edit highlighted keywords: Click the "E" button on the panel, the keyword button(s) will turn into keyword editbox. Edit them, leave a space between each, then press "Enter" or click the "E" button (orange) when finish. #Tips: You can also use "Alt-." (Alt key and the period key) to edit keywords.
  • To lock highlighted keywords: Click the green "L" button and the current keyword(s) will be highlighted in all pages hence loaded, while search keywords will not be auto highlighted. #IMPORTANT: No action will erase the locked keywords except "unlock".
  • To unlock highlighted keywords: Click the orange "L" button and the locked highlighted keywords will be unlocked.
  • To minimize the panel: Double click the left handler of the panel. The panel will minimize to the right of the window, only showing the handler. To restore the panel, double click the handler.
  • !About highlight limitation: Because of some limitation of javascript, it is not possible to highlight a short keyword and then highlight its extended word afterward. For example, when you want to highlight "she" when "he" was previously highlighted in the same page without a refresh, you will get no "she" highlighted.
  • !About highlighting Regular Expression: Under default config of the script, you have to uncheck the checkbox on the left of keyword inputbox (thus "New") to enter and highlight a regular expression if there are existing highlighted keywords. If you prefer to add regular expressions to highlight after current highlights, the "Sort keywords" config (see "Advanced Config" below) must be disabled.

Advanced Config

Part I: Basic Settings

By selecting the "Enhanced word highlight Advanced Config" item from the Greasemonkey / Tampermonkey menu, you can change the following configs to your preference. You can also change them in "// #### Config II #### " section in code. Since the code include Chinese characters, an editor with multiple text encoding support is required.

What auto-pager tool do you mostly use?

⚪ Autopagerize GM script

⚪ Autopager extension

⚪ Other (can handle all auto-pager tools but works slow)

The script originally supports Autopagerize GM script. If you use Autopagerize, select the first option (default). With AutoPager Firefox Extension, the new page content will be highlighted instantly; by selecting the second option will enable the script to also refresh the map and keyword count. If you are using other auto-pager tools, such as GoogleMonkeyR GM script, select the last option to let the script detect page change and totally refresh the highlight.

Turn off highlight of short keywords by default?

⚪ Don't turn off

⚪ One-letter/digit word

⚪ One- and two-letter/digit word

Skip highlighting short keywords, i.e. words formed by only one or two letters and numbers. But they are still on the panel.

Disable auto-highlight (auto-capture search keywords for highlight) ?

⚪ Enable

⚪ Completely disable

⚪ Disable on pages opened from supported search results

⚪ Disable on supported search result pages

Stop auto-highlight function, including on search results and subsequent pages. Selecting the third option will only stop auto-highlight function on subsequent pages from search results, while the fourth does the opposite. This config does not affect inherit-highlight and highlight for locked keywords.

☐ Sort keyword for more accurate highlight (Recommended, except for regular expression users)

Sort keywords will arrange longer keyword first, which ensure the highlighting of long words. Nevertheless, there are always circumstances that you prefer "straight-forward" highlighting, or "short word first" rule, or to enable adding regular expressions, under which you would prefer turning this option off.<

☐ Save panel position

Just to save the panel position the last time you move it.

☐ Show indicator bar when navigating

Display a window-wide semi-transparent bar when navigating through keywords, indicating which row the current keyword is in.

Part II: Special Settings

Warning: Changing the advanced configs below requires editing the script source code. You should only change the code according the following instruction within the "// #### Config I ####" section. Since the code include Chinese characters, an editor with multiple text encoding support is required (e.g. Notepad2).

// List of url patterns; Array(&#39;NAME&#39;, &#39;KEYWORD_PREFIX&#39;, &#39;URL_PATTERN&#39;)
urlArr[0] = [&#39;Google&#39;,   &#39;q=&#39;,   &#39;www.google.&#39;];
......

Identifying search sites with url patterns to get search keywords for highlight.

// List of IDs of query input boxes; Array(&#39;#SEARCHBOX_ID#&#39;, &#39;SEARCHPAGE SPEC_URL&#39;)
query_id[0] = new Array(&#39;query&#39;, &#39;&#39;);// most common
......

Identifying the search box in other websites with url filter to get search keywords for highlight.

// keybinds
var KEY_NEXT = &#39;n&#39;;// &quot;n&quot;Next occurrence
......

Set the shortcut keys to launch certain functions.

// delay of highlighting (ms)
var delay = 500;

Delay set to postpone highlight action, avoid conflict.

// instant highlight selected keywords
var instant = true;</pre>

Set whether pressing Alt-/ instantly add selected text as keywords to highlight.

// restore focus and scroll position after closing keyword inputbox with shortcut key?
// mainly useful for keyboard navigation, not recommend for mouse navigation.
var refocus = false;

Useful for keyboard navigation (such as arrow key scrolling), which retore focus after using "Esc" to exit keyword inputbox. If you don't feel any trouble, don't touch it.

// minimize the panel initially?
var panel_hide = false;

provide initial-minimized-state panel for auto-highlight.

Part III: Calling Functions with Mouse Gesture

For heavy users of mouse gesture, requires a mouse gesture addon that support gesture comand customization. content.window.wrappedJSObject.EWH_iSearch(); Call the keyword inputbox. content.window.wrappedJSObject.EWH_cClose(); Call the disable-highlight command.

Credit

This script cannot be born without the original script (Version 1.0.9) by os0x. Thank grea for code and idea contribution. And many who offer tips, ideas, references and suggestions.

Update Log

2010.08.15: Version 1.5.0: Add support for more search sites other than Google, as well as their subsequent pages; add config option to disable auto-highligh in search result pages; add in-code config for restore focus after using Esc key exiting keyword input; change behavior, pressing Ctrl-/ when focused in keyword inputbox will close the box; fix behavior, now quoted keywords can sustain; code refinement; since I have to add encoding convertion functions to handle Baidu keywords, the size of the script grows significantly.

2010.11.30: Version 1.5.5: Behavior change: pressing Ctrl-./ when text is selected outside of text input area now will instantly add selected text as keywords to highlight; "Add/New" keyword input status will last until web page refresh; when highlight is disabled, existing keywords now will not automatically be added to the new keywords for highlight in the same window / tab, but by pressing Ctrl-/ without selecting text, they will be shown in the keyword inputbox; period dot is no longer a keyword separator; quoted keywords now work properly (finanlly); Add external calling code (for like mouse gesture) "content.window.wrappedJSObject.EWH_iSearch();" to call the keyword inputbox; Other bug fixes and code improvement.

2010.12.02: Version 1.5.5a: Fix a bug that cause an error that halt the script when running in non-GM environment; Fix a bug that cause keyword cleaning-up failure in some circumstances; Add external calling code (for like mouse gesture) "content.window.wrappedJSObject.EWH_cClose();" to call the disable-highlight command.

2010.12.16: Version 1.5.6: Fix and improve the function to toggle all highlight, which makes it work under Opera (11 beta); Add a button to lock highlight map; Behavior change: now on non main-search-engine pages, inherited keywords will have higher priority.

2011.06.19: Version 1.5.7: Add support to new addon.mozilla.org search pages; Refine styles; Behavior change: now you can only move the panel by dragging the left handler; Behavior change: now you cannot drag the panel when it's minimized; Add an option in code to provide initial-minimized-state panel for auto-highlight; Add a line to improve language determination (thanks SoIN); Change the shortcut keys to activate the keyword inputbox: Alt-/ to activate, while Alt-. (that is Alt and Period) to edit keywords.

2011.07.20: Version 1.5.7a: Fix the key shortcut problem, now the shortcut for editing keyword work, and the shortcut for toggling all highlight changed to Alt-, ; Refine style; Enable the script to work in iframes (test); other small fixes.

2011.11.10: Version 1.5.7b: Fix the keyword getting issue for Google's redirection.

2017.09.22: Version 1.5.9: Fix Baidu Charset problem.

2017.09.22: Version 1.6.0: Add exclusion to https Googld Map.

2022.01.15: Version 1.6.2: Thanks to YFdyh000, shortcut keys work again in new versions (36+) of Firefox.

2022.02.03: Version 1.6.3: Fix the problem that highlight map didn't respond to mouse click in new versions (36+) of Firefox.

2022.02.03: Version 1.6.4: Add fade-out effect to the indicator-bar; fix a layout problem of the config dialog in some webpages; add a primitive skip-word-list that store the words the user don't need to highlight.

2023.01.05: Version 1.6.5; Modify panel style; add support to more search sites.

2023.01.11: Version 1.6.6: Fix iframe hide mechanism in Microsoft Rewards; press Alt-/ in an inputbox will also instant highlight the content in the inputbox; style refine; new remove highlight method.

2023.01.29: Version 1.7.0: Fix new remove highlight method conflict with hover dict in Bing International; Fix map viewport position problem when the page viewing width is larger than window view; Add DuckDuckGo support; Fully rebuild the Advanced Config dialog.

2023.01.30: Version 1.7.1: Fix bug that highlighting didn't stop in autopaging after highlight was disabled; Pause highlight renewal when navigating highlight using mousewheel; Navigating highlight using mousewheel works in Chrome-like browsers; Add Greasyfork support; new remove highlight method. E 2023.04.24: Version 1.7.2: Fix highlighting "false" when no search keyword found in some cases; add engine Ecosia; fix running error in some newly installed cases. 2023.05.05: Version 1.7.3: Fix getting keywords from Baidu; update panel design. 2023-05-23: Version 1.7.4: Refine design; pressing "ESC" key in keyword inputbox now can close the keyword inputbox, again.