i have created simple jquery script chrome extension suppose change font color of class.
the script working fine if use directly in console. if run extension wont trigger when value higher one.
any suggestion of problem?
script.js
(function(){ $("#id-layout-1435216276773-countervalue").each(function() { var el = $(this); var value = parsefloat(el.text()); if (value > 1) { el .css("font-weight", "bold") .css("color", "red"); } else { el.css("font-weight", "normal"); } }); })(); manifest
{ "update_url": "https://clients2.google.com/service/update2/crx", "name": "live", "version": "0.3", "description": "live", "permissions": [ "tabs","<all_urls>" ], "browser_action": { "default_icon": "icon.png" }, "icons": { "16": "icon.png", "48": "icon.png", "128": "icon_128.png" }, "content_scripts": [ { "matches": [ "https://www.google.com/analytics/web/?hl=en#dashboard/6i8yfvs_tqsq_b1tojyr0q/a8398197w15972131p74378741/*" ], "run_at": "document_end" , "js": ["script.js"] } ], "manifest_version":2 }
you have not included jquery in content script.
because content scripts run in isolation page, not matter whether page has jquery included. script's context not have it.
however, code works console, because code is, default, executed in page's context (see <top frame> selector above console?), may have jquery already. add fact chrome console provides special version of $ use in console, if there no jquery (in case it's alias document.queryselector).
to see what's happening if execute code in extension's context, need switch context (which created after inject something).
you need add jquery extension's files , inject before main script:
"content_scripts": [{ "matches": [ ... ], "run_at": "document_end" , "js": ["jquery.min.js", "script.js"] }],
Comments
Post a Comment