2015-01-06 68 views
0

我正在尝试创建我的第一个Chrome扩展。创建Chrome扩展程序以隐藏DIV显示:无;在特定页面

它基本上是一个特定元素的adblocker,在这种情况下 - Facebook评论部分。

它适用于all_urls,但不适用于该特定域。

清单文件:

{ 
"name": "My extension", 
"version": "1.0", 
"manifest_version": 2, 
"content_scripts": [ 
    { 
     "matches": ["http://visir.is/*"], //where your script should be injected 
     "css": ["style.css"] //the name of the file to be injected 
    } 
    ] 

}

的style.css文件:

.fbcomment { 显示:无; }

任何想法如何更正“匹配”?

我试图*://visir.is/*https://developer.chrome.com/extensions/match_patterns规定,但它仅与all_urls

回答

0

维克托工作,

你是在错误的道路。您的扩展应该在Facebook网站的工作,因此,在清单中的匹配语句必须严格按照以下几点:

“匹配”:“https://www.facebook.com/ *”]

比你需要找到所有的评论时间表(很可能由css类)检测目标站点地址(//visir.is/)的存在,然后隐藏这些注释。

因为时间线动态加载多个帖子,你还需要观察新节点并把它们应用的功能太(请参阅我下面的Chrome扩展的例子):

var obs = new MutationObserver(function (mutations, observer) { 
 
\t for (var i = 0; i < mutations[0].addedNodes.length; i++) { 
 
\t \t if (mutations[0].addedNodes[i].nodeType == 1) { 
 
\t \t \t $(mutations[0].addedNodes[i]).find(".userContentWrapper").each(function() { 
 
\t \t \t \t injectFBMButton($(this)); 
 
\t \t \t }); 
 
\t \t } 
 
\t } 
 
\t injectMainButton(); 
 
}); 
 
obs.observe(document.body, { childList: true, subtree: true, attributes: false, characterData: false });

+0

非常感谢! 您的权利。我指定的div在Facebook里面。 但是,我发现页面内有另一个div,可以用来阻止该元素。 非常感谢。 – Viktor