function textNodesUnder(el) {
    var n, a = [], walk = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null, false);
    while (n = walk.nextNode()) {
        a.push(n);
        console.log("text node: " + n);
    }
    return a;
}

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    if (request.method && (request.method === "highlightImperial")) {
        // (Note: You can't send back the current '#document',
        //  because it is recognised as a circular object and
        //  cannot be converted to a JSON string.)
        var html = document.all[0];
        //sendResponse({ "htmlContent": html.innerHTML });
        //sendResponse({"text": textNodesUnder(document.body)});
        //textNodesUnder(document.body);
        document.body.innerHTML = highlight(document.body.innerHTML, null);
        sendResponse({"text": "ok"});
    } else if (request.method && (request.method === "convertToSI")) {
        // (Note: You can't send back the current '#document',
        //  because it is recognised as a circular object and
        //  cannot be converted to a JSON string.)
        var html = document.all[0];
        document.body.innerHTML = html.innerHTML.replace("Spanish", "Polish");
        sendResponse({"text": "ok"});
    }
});

function searchImperial(where) {
    var re = /[0-9,]+\s+miles?/i;
    var index = where.search(re);
    if (index >= 0) {
        return index;
    }
    return where.indexOf("mile");
}

function multisearch(where) {
    var re = /[0-9,]+\s+miles?/ig;
    var result;
    var results = [];
    while ((result = re.exec(where)) !== null) {
        results.push({
            index: result.index,
            match: result[0],
            numeral: interpretInt(result[0].split()[0])
        });
    }
    return results;
}

function interpretInt(what) {
    what = what.replace(",", "");
    return parseInt(what);
}

function highlight(where, text) {
    if (text == null) {
        matches = multisearch(where);
        matches.forEach(function(match) {
            where = where.replace(match.match,
                "<span style='background-color: yellow;'>"
                + match.match
                + "</span>")
        });
        return where;
    }
    var index = where.indexOf(text);
    if (index >= 0) {
        return where.substring(0, index)
            + "<span style='background-color: yellow;'>"
            + where.substring(index, index + text.length)
            + "</span>"
            + where.substring(index + text.length);
    }
    return where;
}

@@ -1192,50 +1192,39 @@
 L = 
-html.innerHTML.replace(%22Spanish%22, %22Polish%22
+replace(document.body.innerHTML
 );%0A 
@@ -2544,12 +2544,387 @@
 rn where;%0A%7D%0A
+%0Afunction replace(where) %7B%0A    matches = multisearch(where);%0A    matches.forEach(function(match) %7B%0A        where = where.replace(match.match,%0A            %22%3Cspan style='background-color: yellow;'%3E%22%0A            + milesToKilometers(match.numeral)%0A            + %22 kilometers%3C/span%3E%22)%0A    %7D);%0A    return where;%0A%7D%0A%0Afunction milesToKilometers(miles) %7B%0A    return miles * 1.60934;%0A%7D%0A

Add a simple replace functionality