Developing the Oil monkey script: Coloring the selected text of any page

Source: Internet
Author: User

Overview

To put it simply: just like in a real textbook with the mark pen coloring point, you can use this script on any page to paint the focus.

Development reason: Every time in the Internet to see the information, will silently summed up a few important places, but read the information to write a blog when it is easy to forget the focus, so I developed this script.

Script flaw: (1) cannot refresh the webpage, otherwise the mark is gone. (2) Only the same text can be marked, not hyperlinks, text, references, highlighting together, but can be marked separately.

Demonstrate

Script code

First, you need to install the oil Monkey (Tampermonkey) plugin on the browser. 360 browsers can be found in the extension center. Other Browser installation method please own Baidu.

Finally, open the oil monkey-----Add a new script and copy the code in.

 //==userscript==//@name Mark on web//@namespace http://tampermonkey.net///@version 0.1//@d        Escription try-to-take over the world!//@author you//@match https://developer.mozilla.org/*//@match http://*/*//@match https://*/*//@grant none//@copyright 2018+, yang-zhou//==/userscript== (function ()    {' Use strict ';        var funcgetselecttext = function () {var txt = '; if (document.selection) {txt = Document.selection.createRange (). text;//ie}else{txt = documen        T.getselection ();        } return txt.tostring ();    }; var container = Container | |    Document        Container.onmouseup = function () {var txt = funcgetselecttext (); if (TXT) {Event.target.innerHTML =event.target.innerhtml.replace (txt, ' <span style= "Backgroun            D-color:yellow "> ' +txt+ ' </span> '); }    };}) ();

Note : Make sure that the oil monkey plugin is turned on when you open the Web page, and that the script I wrote is enabled.

Web Effects Demo<textarea id="text_test" rows="10" cols="100"><! DOCTYPE html><ptml> <pead></pead> <body> <p> How to use: With the mouse to select text, the selected text will be automatically painted yellow </ P> <script> var funcgetselecttext = function () {var txt = '; if (document.selection) {txt = Document.selection.createRange (). text;//ie}else{txt = documen T.getselection (); } return txt.tostring (); }; var container = Container | | Document Container.onmouseup = function () {var txt = funcgetselecttext (); if (TXT) {Event.target.innerHTML =event.target.innerhtml.replace (txt, ' <span style= "Backgroun D-color:yellow "> ' +txt+ ' </span> '); }};</script></body></ptml></textarea>

Develop an oil monkey script: Paint the selected text for any 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.