by wjg · 9y ago · 0 comments
The following script simply highlights the word to make it a bit easier to find. Also works well when combined with kristopolous'. The output is the number of posts matching each input string.
// usage: highlight('react', 'node', 'graphql', '$')
// output: [57, 29, 4, 19]
function highlight(/* args */) {
return Array.prototype.slice.call(arguments).map(function(keyword) {
var matches = 0;
Array.prototype.forEach.call(document.querySelectorAll('tr.athing.comtr div.comment'), function(e) {
if (e.innerText.search(new RegExp(keyword === '$' ? '\\$' : keyword, 'i')) === -1) return;
++matches;
e.innerHTML = e.innerHTML.replace(new RegExp(keyword === '$' ? '\\$' : keyword, 'ig'), '<span style="background-color:#0095ff;color:#fff;">' + keyword.toUpperCase() + '</span>')
});
return matches;
})
}No comments yet.