liorgrossman / darkness

Dark Themes for Popular Websites
https://darkness.app
GNU General Public License v3.0
513 stars 751 forks source link

Matching Regex for Non Root Level Site Match #87

Open sheldonhull opened 5 years ago

sheldonhull commented 5 years ago

I've tried to customize an internal site (doesn't start with www) as well as what other's might use using the middle part of the url that is universal for Team Foundation Server. I can't get it to recognize .*/tfs/$ as the url matching. I've tried a lot of combinations but nothing is showing up. Any recommendations on how to handle this?

liorgrossman commented 5 years ago

Yeah. Currently the code in background.js only compares "hostRegExp" with the current URL "hostname". This doesn't include the path:

var urlParts = parseUrl(url);
...
if (urlParts.hostname.match(CONFIG.sites[siteKey].hostRegExp)) {

You could theoritically add code such as:

if (urlParts.path.match(CONFIG.sites[siteKey].pathRegExp)) {

to test the path.

However, I think skinning any website that contains /tfs/ in the path is a bit too risky. I'm sure few websites that are not Team Foundation Server have /tfs/ in the path, and we would accidentally skin them. Is there any other way of detection TFS websites? (I'm not familiar with the product)

sheldonhull commented 5 years ago

Thanks for the insight. To narrow /tfs/ further could be done by /tfs/DefaultCollection/` as that's unlikely to be used elsewhere.

That's helpful to know.

liorgrossman commented 5 years ago

Yeah, limiting it to run only if path equals /tfs/DefaultCollection/ seems reasonable.

You could start by adding path matching to background.js:

if (CONFIG.sites[siteKey].pathRegExp && urlParts.path.match(CONFIG.sites[siteKey].pathRegExp)) {

This could run even before matching the hostname.

then adding "pathRegExp": "\/tfs\/DefaultCollection\/" to the TFS site (under config.js)