Created
June 27, 2015 16:10
-
-
Save orchid-hybrid/3edf0f16748a7c17a306 to your computer and use it in GitHub Desktop.
find word context script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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