I'm trying to make a chrome extension that can take an exact phrase, and search google for it. Once I click a page, I want it to highlight that phrase on that page. That's where I'm stuck. For me, window.find() keeps returning false in my main.js file. I'm learning Java as I make this for a practice exercise, so please be kind. You might have to explain what some terms mean. Thank you :)
main.js
var query = JSON.parse(localStorage.getItem("query"));
function search(word) {
query = word.selectionText;
localStorage.setItem("query", JSON.stringify(query));
chrome.tabs.create({ url: 'https://www.google.com/search?q="' + query + '"' });
};
function findIt() {
alert("testing: " + JSON.parse(localStorage.getItem("query")) + ", is it on the page? " + window.find(JSON.parse(localStorage.getItem("query"))))
window.find(JSON.parse(localStorage.getItem("query")))
}
chrome.contextMenus.create({
title: "Google Search",
contexts: ["selection"],
onclick: search
});
chrome.contextMenus.create({
title: "Find Text",
contexts: ["page"],
onclick: findIt
});
manifest.json
{
"manifest_version": 2,
"name": "Genie",
"description": "google searches highllighted text, and then also searches for that text on any page",
"version": "0.0.1",
"minimum_chrome_version": "38",
"permissions": [
"contextMenus",
"tabs",
"activeTab"
],
"icons": {
"16": "assets/genie.png"
},
"background": {
"page": "background.html"
}
}
background.html
<!DOCTYPE html>
<html>
<body>
<script src="main.js"></script>
</body>
</html>
also wasn't sure of the best way to put the code in