我正在制作我的第一个Chrome扩展程序。它旨在切换facebook.com
上的元素显示我面临的问题是facebook.com正在使用AJAX,所以我的更改只发生在刷新上。我认为这里的解决方案是使用chrome.tabs.onUpdated.addListener,但控制台返回“未捕获的TypeError:无法读取属性'onUpdated'未定义”
很确定我已经正确宣布了所有内容..这是我的manifest.json和background.js
的manifest.json
{
"name": "Facebook Display Control",
"version": "1.0",
"description": "This extension toggles the display of elements on Facebook.com",
//"background": {"page": "background.html"},
"manifest_version": 2,
"browser_action": {
"name": "Manipulate DOM",
"icons": ["icon.png"],
"default_icon": "icon.png",
"default_popup": "options.html"
},
"options_ui": {
"page": "options.html"
},
"permissions": [
"tabs",
"storage",
"webRequest",
"http://*.facebook.com/*",
"https://*.facebook.com/*"
],
"content_scripts": [ {
"js": [ "jquery-3.1.1.min.js", "background.js" ],
//"css": ["customStylex.css"],
"matches": [ "http://*.facebook.com/*", "https://*.facebook.com/*" ]
}]
}
BACKGROUND.JS
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
$(".home_right_column").css( "min-height", "0px" );
$(".home_right_column").css( "display", "none" );
chrome.storage.sync.get({"hideTrending": true}, function(e){
a = e.hideTrending;
if(a) {
$("#pagelet_trending_tags_and_topics").css( "display", "none" );
} else {
$("#pagelet_trending_tags_and_topics").css( "display", "block" );
}
});
chrome.storage.sync.get({"hideSuggestions": true}, function(e){
a = e.hideSuggestions;
if(a) {
$("#pagelet_ego_pane").css( "display", "none" );
} else {
$("#pagelet_ego_pane").css( "display", "block" );
}
});
});
非常感谢任何帮助!
谢谢!