2015-01-06 113 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