Chrome extension to analyze Google search results

I am trying to make a small extension that checks google search results for Wikipedia articles, and adds a little extra link later. But I figured out the search results a bit. This is currently very simple.

manifest:

{ "name": "Test", "version": "0.1", "description": "Test Test", "icons":{ "128":"icon_128.png" }, "permissions": [ "tabs", "http://www.google.com/*", "https://www.google.com/*" ], "content_scripts": [ { "matches": ["http://www.google.com/*", "https://www.google.com/*"], "css": ["style.css"], "js": ["jquery-1.7.min.js", "injector.js"], "run_at": "document_end" } ], "manifest_version": 2 } 

And the injector:

 function findWikipediaLinks(){ console.log("here I am!"); console.log($('a')); //.css({'background-color': 'yellow'}); } findWikipediaLinks(); 

The problem is that the code here works before the actual search results are shown. (Results are logged as a in the google header. Is there a way to use this sentence in a timely manner?

+4
source share
1 answer

Google loads the results via AJAX, so you need to use an event listener for DOMNodeInserted events.

 function filterResultInserts(event) { console.log(event); } target.addEventListener('DOMNodeInserted', filterResultInserts); 

Inside filterResultInserts you will have to look for classes or identifiers that match the results and modify them.

+4
source

Source: https://habr.com/ru/post/1395275/


All Articles