- Copy the code below:
javascript:(function(){
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/compromise@latest/builds/compromise.min.js';
document.body.appendChild(script);
script.onload = function() {
var textNodes = document.evaluate('//body//text()', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < textNodes.snapshotLength; i++) {
var node = textNodes.snapshotItem(i);
var words = node.nodeValue.split(' ');
for (var j = 0; j < words.length; j++) {
var nlp_word = nlp(words[j]);
if (nlp_word.topics().out("text") || nlp_word.match('#ProperNoun').out("text") || (nlp_word.nouns().out("text") && nlp_word.out("text").match(/^\p{Lu}[\p{Ll}'’]/u) && !nlp_word.pronouns().out("text")) ) {
var span = document.createElement("span");
span.style.color = "orange";
var textnode = document.createTextNode(words[j]);
span.appendChild(textnode);
node.parentNode.insertBefore(span, node);
} else if (nlp_word.nouns().out("text") && !nlp_word.pronouns().out("text")) {
var span = document.createElement("span");
span.style.color = "red";
var textnode = document.createTextNode(words[j]);
span.appendChild(textnode);
node.parentNode.insertBefore(span, node);
} else {
var textnode = document.createTextNode(words[j]);
node.parentNode.insertBefore(textnode, node);
}
if(j !== words.length -1){
var space = document.createTextNode(" ");
node.parentNode.insertBefore(space, node);
}
}
node.parentNode.removeChild(node);
}
};
})();
- Create a new bookmark.
- Set the bookmarklet name and paste the above as the URL.