Skip to content

Instantly share code, notes, and snippets.

@orchid-hybrid
Created June 27, 2015 16:10
Show Gist options
  • Save orchid-hybrid/3edf0f16748a7c17a306 to your computer and use it in GitHub Desktop.
Save orchid-hybrid/3edf0f16748a7c17a306 to your computer and use it in GitHub Desktop.
find word context script.js
System.import("github:contextscript-packages/text-extractor")
.then(({"default": extractText})=>{
var result = extractText({skipSelector:".ctxscript-container"});
var found = 0;
for(i in result.nodeMappings) {
var words = result.nodeMappings[i].node.nodeValue.split(" ");
for(j in words) {
if(words[j] == 'quantum') {
words[j] = "<span style='background-color: yellow';>"+words[j]+"</span>";
found++;
}
else
words[j] = words[j];
}
if(result.nodeMappings[i].node.parentNode) {
result.nodeMappings[i].node.parentNode.innerHTML = words.join(" ");
}
}
cxsAPI.$el.append("Found " + found + " occurences of the word.");
})
.catch((err)=>{
console.log(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment