4

I made this to filter results in a case-sensitive manner on Google. Where the issue arises is in the fact that each string is not on its own line despite my inclusion of "\n." (In the picture, periods are absent because I executed the replace function. However, the new line does not surface.)

(function () {
    if (!console) {
        console = {};
    }
    var old = console.log;
    var logger = document.getElementsByClassName('g kno-kp mnr-c g-blk')[0];
    console.log = function (message) {
        if (typeof message == 'object') {
            logger.innerHTML += (JSON && JSON.stringify ? JSON.stringify(message) : String(message)) + '<br />';
        } else {
            logger.innerHTML += message + '<br />';
        }
    }
})();

var p=/Opportunity cost(.*?)\./gm;console.log(document.body.innerText.match(p))

var str = document.getElementsByClassName('g kno-kp mnr-c g-blk')[0];
var inner = str.innerHTML;
var res = inner.replace(/\./gi, "\n");
str.innerHTML = res;

enter image description here

1
  • 2
    Have your element a white-space: pre; style? Commented Jan 25, 2021 at 2:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.