Use Chrome Extension to Modify Google Search Result Page -
i wanna make chrome extension modify google search result page. know can use content script because has ability this. unfortunately fails. wrote code
$('h3.r').append('<b>a</b>')
or else related dom operations failed. if wrote
alert('aa')
or
document.body.style.backgroundcolor='green'
, works. why? way, want have debug when open development tools can not find extension content script. can see other extensions' content scripts.
did add jquery content_scripts in manifest?
if use jquery, must write manifest.json
this:
"content_scripts":[ { "matches":["http://www.google.com/*"], "js":["jquery-1.9.1.min.js", "contentscripts.js"] } ]
ok, after read page source of google search result page think know problem is:
google loads search result ajax, so, when change query words , search again, page does not refresh, that's why can not dom elements in search result.
that means have add event listener domnodeinserted.
code this:
function fundh3(){ $('h3.r').append('<b>a</b>') } searchresultarea.addeventlistener('domnodeinserted', findh3);
Comments
Post a Comment