Chrome扩展程序来解析Google搜索结果 [英] Chrome extension to parse google search results

查看:126
本文介绍了Chrome扩展程序来解析Google搜索结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一些扩展,检查wikipedia文章的谷歌搜索结果,然后添加一些额外的链接。但是在解析搜索结果时遇到一些麻烦。目前它非常简单。

清单:

  {
name:Test,
version:0.1,
description:Test Test,
图标:{
128 :icon_128.png
},
权限:[
标签,
http://www.google.com/*,
https://www.google.com/*

content_scripts:[
{
matches:[http:// www .google.com / *,https://www.google.com/*],
css:[style.css],
js:[jquery
run_at:document_end
}
],
manifest_version:2
}



和注入器:

 函数findWikipediaLinks(){
console.log(Here I am!);
console.log($('a'));
//.css({'background-color':'yellow'});
}

findWikipediaLinks();

问题似乎在于此处的代码在显示实际搜索结果之前运行。 (记录的结果是在谷歌标题栏中的a。是否有一种方法可以适时调整这种方式?

解决方案

Google正在加载通过AJAX获得结果,因此您需要为事件侦听器 >事件过滤器(事件){
console.log(event)>事件过滤器(事件){

 ); 
}

target.addEventListener('DOMNodeInserted',filterResultInserts);

filterresultInserts 中,您将不得不寻找匹配结果并修改它们的类或id。


I'm trying to make a little extension that checks the google search results for wikipedia articles, and adds a little extra link afterwards. But am having a little trouble parsing the search results. Its very simple at present.

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 injector:

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

findWikipediaLinks();

The problem seems to be that the code here runs before the actual search results are shown. (the results logged are the a's in the google header bar. Is there a way to time this propperly?

解决方案

Google is loading results via AJAX so you need to use an event listener for DOMNodeInserted events.

function filterResultInserts(event) {
  console.log(event);
}

target.addEventListener('DOMNodeInserted', filterResultInserts);

Within filterResultInserts you will have to look for classes or ids that match results and modify them.

这篇关于Chrome扩展程序来解析Google搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆