StartPage Beautifier

This greasemonkey UserScript helps the user to focus on the revelant information in the result page. It basically put the search terms in bold.

当前为 2018-06-13 提交的版本,查看 最新版本

// ==UserScript==
// @name           StartPage Beautifier
// @namespace      https://framagit.org/SecT0uch/StartPage-Beautifier
// @description    This greasemonkey UserScript helps the user to focus on the revelant information in the result page. It basically put the search terms in bold.
// @version        1.4
// @author         SecT0uch <[email protected]>
// @homepageURL    https://framagit.org/SecT0uch/StartPage-Beautifier
// @license        CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/
// @copyright      2018+, Jordan ERNST (https://framagit.org/SecT0uch/StartPage-Beautifier)
// @match          https://*.startpage.com/do/*search*
// ==/UserScript==

window.addEventListener ("load", Greasemonkey_main, false);

function Greasemonkey_main () {
    var toClean = ['title:', 'host:', 'url:', 'link:', ' OR', '"'];     // Special chars to exclude from being bolded
    var query = document.getElementById("query_top").value;             // Search request
  
    for (var x = 0; x < toClean.length; x++) {                         
        query = query.replace(new RegExp(toClean[x], 'g'), '');         // Removing special chars from request
    }

    var re = /\s+/g;                                                    // Matches 1 or mor spaces
    var searchTerms = query.split(re);                                  // Splitting request string in array
    
    var results =  document.querySelectorAll("p.desc.clk");             // Description text (under link)

// We bold every term in every description :

    for (var i = 0; i < results.length; i++) {
        for (var j = 0; j < searchTerms.length; j++) {
            var term = searchTerms[j];
  	        results[i].innerHTML = results[i].innerHTML.replace(new RegExp(term, 'gi'), "<strong>$&</strong>");    // $& = matched value.   <b></b> not supported
        }    
    }
}