Skip to content

Instantly share code, notes, and snippets.

@jareha
Created January 26, 2022 21:36
Show Gist options
  • Save jareha/e533659d9215c77d61075e0c4392b716 to your computer and use it in GitHub Desktop.
Save jareha/e533659d9215c77d61075e0c4392b716 to your computer and use it in GitHub Desktop.
Bookmarklet to highlight adverbs and passive verbs
/* jshint esversion: 8 */
(function () {
// List of verbs, for editing convenience
// am
// are
// be
// been
// being
// go
// hasn't
// hasn’t
// haven't
// haven’t
// he's
// he’s
// here's
// here’s
// i'm
// i’m
// is
// it's
// it’s
// she's
// she’s
// that's
// that’s
// there's
// there’s
// they're
// they’re
// was
// we're
// we’re
// were
// what's
// what’s
// who's
// who’s
// you're
// you’re
const regex = {
adverbs: /(\w)(ly)(\b)/gim,
verbs: /(\b)(am|are|be|been|being|go|hasn't|hasn’t|haven't|haven’t|he's|he’s|here's|here’s|i'm|i’m|is|it's|it’s|she's|she’s|that's|that’s|there's|there’s|they're|they’re|was|we're|we’re|were|what's|what’s|who's|who’s|you're|you’re)(\b)/gi,
};
const passivator = (node) => {
if (node.hasChildNodes) {
let index;
for (index = 0; index < node.childNodes.length; index++) {
passivator(node.childNodes[index]);
}
}
if (node.nodeType === 3) {
let newNode;
let parentNode;
let temporaryNodeValue = node.nodeValue;
if (regex.verbs.test(temporaryNodeValue)) {
let newString = "$1<span style=\"background-color: yellow; color: black; border: 1px solid black;\">$2</span>$3";
temporaryNodeValue = temporaryNodeValue.replace(
regex.verbs,
newString,
);
}
if (regex.adverbs.test(temporaryNodeValue)) {
let newString = "$1<span style=\"background-color: aqua; color: black; border: 1px solid black;\">$2</span>$3";
temporaryNodeValue = temporaryNodeValue.replace(
regex.adverbs,
newString,
);
}
newNode = document.createElement("span");
newNode.innerHTML = temporaryNodeValue;
parentNode = node.parentNode;
parentNode.replaceChild(newNode, node);
}
};
passivator(window.document.getElementsByTagName("body")[0]);
})();
// javascript:(function(){const regex={adverbs:/(\w)(ly)(\b)/gim,verbs:/(\b)(am|are|be|been|being|go|hasn't|hasn’t|haven't|haven’t|he's|he’s|here's|here’s|i'm|i’m|is|it's|it’s|she's|she’s|that's|that’s|there's|there’s|they're|they’re|was|we're|we’re|were|what's|what’s|who's|who’s|you're|you’re)(\b)/gi};const passivator=(node)=>{if(node.hasChildNodes){let index;for(index=0;index<node.childNodes.length;index+=1){passivator(node.childNodes[index])}}if(node.nodeType===3){let newNode;let parentNode;let temporaryNodeValue=node.nodeValue;if(regex.verbs.test(temporaryNodeValue)){let newString="$1<span style=\"background-color: yellow; color: black; border: 1px solid black;\">$2</span>$3";temporaryNodeValue=temporaryNodeValue.replace(regex.verbs,newString,)}if(regex.adverbs.test(temporaryNodeValue)){let newString="$1<span style=\"background-color: aqua; color: black; border: 1px solid black;\">$2</span>$3";temporaryNodeValue=temporaryNodeValue.replace(regex.adverbs,newString,)}newNode=document.createElement("span");newNode.innerHTML=temporaryNodeValue;parentNode=node.parentNode;parentNode.replaceChild(newNode,node)}};passivator(window.document.getElementsByTagName("body")[0])})();
// Minified at https://duckduckgo.com/?q=javascript+minifier
@jareha
Copy link
Author

jareha commented Jan 26, 2022

Based on “The Passivator” by Paul Ford, with verbs added and accounting for typesetter apostrophes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment