Skip to content

Commit

Permalink
Made parseDom much, much faster
Browse files Browse the repository at this point in the history
  • Loading branch information
ijkilchenko committed Dec 26, 2015
1 parent 04f999f commit 56c7906
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 0 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ MIT license */
var vectors;
$.getJSON("./glove_small_dict.json", function(json) {
vectors = json;
console.log('word2vec dictionary loaded!');
});

chrome.runtime.onConnect.addListener(function(port) {
Expand Down
11 changes: 8 additions & 3 deletions content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ function parseDom() {
sanitizedVisibleText, joined across every visible element on the page. We also want to find the vocabulary of the tab,
the unique words on the page, sanitizedUniqueVisibleWords, and use those to order a local word2vec dictionary. */

var visibleWords = sanitize($(document.body).children(":visible").text()).split(' ').filter(function(el) { return el.length != 0 });
sanitizedVisibleText = $(document.body).children(":visible").text();

sanitizedVisibleText = visibleWords.join(' '); // the clean text used for actual matches later
var visibleWords = sanitizedVisibleText.split(' ');

sanitizedUniqueVisibleWords = visibleWords.filter(function(elem, i, array){ return array.indexOf(elem) === i });
var uniqueWords = new Set();
visibleWords.forEach(function(word) {
uniqueWords.add(sanitize(word));
});

sanitizedUniqueVisibleWords = Array.from(uniqueWords);

portB2.postMessage({words: sanitizedUniqueVisibleWords}); // order the vectors via the vectorsLookup port
}
Expand Down

0 comments on commit 56c7906

Please sign in to comment.