I am building a Chrome extension with which I'd like to insert some text between the "link" and the "description" on each Google search result and also write the title of each link to the console. See the screenshot and the code below
Manifest.json
{
"name": "INJECTA",
"version": "0.0.1",
"manifest_version": 2,
"description": "Abcdefgh",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["jquery-3.1.1.min.js","content.js"],
"run_at": "document_end"
}
]
}
content.js
$(document).ready(function() {
$("div.srg").find("h3 > a").each(function (index) {
console.log("Title: " + this.text);
$(this).append("<br><span style='color: orange'>My new line text</span>");
});
});
It works but when I make another search query on the same google page, then it doesn’t work. How can I fix it?