The use case of my extension is when the user opens up the Gmail, fire an API call and fetch the list of topics(the topics can be more than 500). Then when the user opens up the message, if from that fetched topics any max 6 words match with the word in the opened message, it should be highlighted.
For example
If the fetched topic has following topics
topics: {
hello: 10,
how: 1,
mandy: 12,
google: 90,
extension: 13,
local: 20
}
And I have a Gmail message as following
hello, my name is mandy. I work at google.
then the word hello
, mandy
and google
should get highlighted because, those word from the message matched with the topics object.
For now, I could fetch the topic object and pass that topic object to the function searchPage but does not know the way to match.
Here is what I have done till now
function fetchTopics() {
const apiUrl = `https://baseurl.ngrok.io/useful_topics`;
chrome.storage.sync.get(['user_token'], function(result) {
const decoded = JSON.parse(atob(result.user_token));
const access_token = decoded['access-token'];
const headers = new Headers();
headers.append('Access-Token', access_token);
fetch(apiUrl, {
method: 'GET',
headers
})
.then(function(response) {
return response.json();
})
.then(function(data) {
searchPage(data);
// for (var key in data) {
// if (data.hasOwnProperty(key)) {
// searchPage(key);
// }
// }
});
});
}
function searchPage(topicObj) {
console.log('topicObj', topicObj);
// read all the words in the currently opened gmail messages and highlight any max
// 6 words in the message if there is a match
}
I will have topicObj in following format(hashmap structure)
topics: {
hostname: 4,
cto: 19,
maharjan: 45,
aws: 382,
axosoft: 66,
its: 26,
repo: 15,
anurag: 585,
unsubscribe: 65,
bitbucket: 313,
having: 28,
devops: 414,
}