rlr / dotjs-addon

[unmaintained] ~/.js for Firefox
BSD 3-Clause "New" or "Revised" License
144 stars 17 forks source link

Doc suggestion: How to target a path #12

Closed bpierre closed 12 years ago

bpierre commented 12 years ago

Sometimes, you don’t want to target a whole domain, but only a path.

You could add this to the documentation:

How to target a specific path

CSS

You can use the @-moz-document Mozilla Extension:

/* Full path */
@-moz-document url-prefix(http://www.w3.org/Style/) {
  /* CSS here */
}

/* Regex */
@-moz-document regexp("^https?:\/\/www\.w3\.org\/Style\/.*") {
  /* CSS here */
}

Documentation: https://developer.mozilla.org/en/CSS/@-moz-document

JavaScript

You can test the window.location object:

// Search for a string
if (window.location.pathname.indexOf('/Style/') === 0) {
 // JS here
}

// Regex
if (/^\/Style\/.*/.test(window.location.pathname)) {
 // JS here
}

Documentation: https://developer.mozilla.org/en/DOM/window.location

rlr commented 12 years ago

I like!

rlr commented 12 years ago

Landed 7d003c04205b6c1ca51c9c35f7745fd6eeb18280

Thanks!