0

My problem : How can the news page be manipulated to only show information about messi , non-messenger information will be hidden

My manifest.json looks like this:

{
    "name": "Load-by-keyword",
    "version": "1.2",
    "description": "Build an Extension! Load-by-keyword",
    "manifest_version": 3,
    "action":
        {
            "default_title": "Load-by-keyword"
            
        },

    "content_scripts": [
        {  
            "matches": ["https://vnexpress.net/the-thao"], 
            "css": ["css/style.css"],
            "js": [
                "js/libs/jquery.js",
                "js/content.js"
            ],
            "run_at": "document_end"
        }
    ],
    
    "permissions": ["scripting" , "activeTab"]
    
}    

jQuery

$(document).ready(function() {

    var messiRegex = /messi/ig;

    $("body").each(function() {
        $('article').each(function() {
            if ($(this).find('h3.title-news > a').text().indexOf('Messi') === -1) {
                $(this).addClass("d-none");
            }
        });
    });

});
Guar Dian
  • 57
  • 4
  • There should be no need for `js` if you target only modern browsers that support `:has` selector, so you can do it in your `css` like this: `article:not(:has(h3 a[href*="messi" i])) { display: none }`. Also replace document_end with document_start to apply the style earlier. For older browsers you probably need to use MutationObserver in your js, [example](/a/32537455). – wOxxOm Mar 05 '23 at 16:16

0 Answers0