How to exclude certain code only on a page from a website?

Hi guys.
I'm stuck with a problem and after 3 hours of searching now I'm here for help.
First of all I'm a complete noob on css and maybe the problem it's that I'm not using the corrects words to find the solution.

I made a facebook style that show the left sidebar on hover but today I realized that if you go to facebook.com/groups the sidebar it's entire collapsed so I was searching how to exlude just a certain code only in that section.

I was looking something like: www.facebook.com/groups/*
then I tried with some examples that I find on internet like:
@-moz-document regexp("^https?://((www)\.)?facebook\.com\groups\*$")
or
@-moz-document regexp("www.facebook.com/groups/*")
But it seems that I doing it wrong.

ex: if I wanna exclude this code
body{color:red;}
only on facebook.com/groups/*
but include that code in the other pages like:
facebook.com/* or facebook.com/etjusticepourtous/ whatever it's ahead .com/*
Is this what the code should look like?

ex:
@-moz-document domain("www.facebook.com"), domain("m.facebook.com"), domain("www.messenger.com"), domain("apps.facebook.com")
{
body{background:blue;}

@-moz-document regexp("^https?://((www)\.)?facebook\.com\groups\*$")
{
body{color:red;}
}
}

Comments

  • If you already included the whole domain, you can't explicitly exlude something afterwards without rewriting the whole include.
    So the easiest way is to just overwrite the first declarations

    Example

    @-moz-document domain ("www.facebook.com") {
      body { background:blue; }
    }
    
    @-moz-document url-prefix("https://www.facebook.com/groups") {
      /* new color instead of blue */
      body { background:red; }
    }
    

    If you want to mess around with regexp, here some tips:
    1. Test your regexp with https://regex101.com/ (javascript flavour), there you can already see errors like using \groups instead of /groups
    2. There you also see that all slashes have to be escaped with backslashes
    3. For use in @-moz-document-format all backslashes have to be escaped with another backslash (so a simple slash will end up as \\/)
    4. Beginning ^ and end $ are not necessary to declare

  • edited March 6 Chrome
    Thanks!
    After meditating for a while, I realized that the example I wrote was not going to work.
    I thought that including the code inside "regexp ...." was to ignore that code only where the regular expression pointed, in this case "fb.com/groups"


    I will use your example as you said it is the easiest way.
    BTW, in your example between "domain" and "(" has a space.
    I'm pretty sure it was just an error, but that helped me today to learn something new for me and maybe help others too, if there's a space between that ["domain" and "("] will not work.

    I always wrote "domain(" (all together, I never realized that if it has a space it will not work)
    @-moz-document domain("www.facebook.com") {
    body { background:blue; }
    }

    @-moz-document url-prefix("https://www.facebook.com/groups") {
    /* new color instead of blue */
    body { background:red; }
    }
    Thanks again!
  • Glad I could help.
    And sorry for the wrong space, you're right. I didn't test it :-/
Sign In or Register to comment.