diff options
| author | sameerasw <[email protected]> | 2025-04-14 23:03:03 +0530 | 
|---|---|---|
| committer | sameerasw <[email protected]> | 2025-04-14 23:03:03 +0530 | 
| commit | 21b85381f4185383f6c9f186350f28c8a09bd254 (patch) | |
| tree | 6eb86773872b709e48eef69b26a9b8235615ddf9 /popup | |
| parent | 08477ca5c8a1f58e880e5186773309567a2b5c2a (diff) | |
Fixes for #10, removed the useles inject-css.js in favor of the background.js
Diffstat (limited to 'popup')
| -rw-r--r-- | popup/popup.js | 42 | 
1 files changed, 32 insertions, 10 deletions
diff --git a/popup/popup.js b/popup/popup.js index 37d1ab2..7b00bb5 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -331,12 +331,21 @@ new (class ExtensionPopup {    isCurrentSite(siteName) {      if (logging) console.log("isCurrentSite called with", siteName);      if (!this.currentSiteHostname) return false; + +    // Exact match has priority +    if (this.currentSiteHostname === siteName) return true; +    if (this.currentSiteHostname === `www.${siteName}`) return true; + +    // Wildcard match (with proper domain boundary)      if (siteName.startsWith("+")) {        const baseSiteName = siteName.slice(1); -      return this.currentSiteHostname.endsWith(baseSiteName); +      return ( +        this.currentSiteHostname === baseSiteName || +        this.currentSiteHostname.endsWith(`.${baseSiteName}`) +      );      } -    if (this.currentSiteHostname === siteName) return true; -    if (this.currentSiteHostname === `www.${siteName}`) return true; + +    // Don't match partial domain names      return false;    } @@ -413,25 +422,38 @@ new (class ExtensionPopup {        for (const site of Object.keys(styles)) {          const siteName = site.replace(/\.css$/, ""); + +        // Exact match has highest priority +        if (hostname === siteName || hostname === `www.${siteName}`) { +          bestMatch = site; +          if (logging) console.log("Popup: Found exact match:", site); +          break; +        } + +        // Then check wildcard matches          if (siteName.startsWith("+")) {            const baseSiteName = siteName.slice(1); +          // Ensure we're matching with proper domain boundary            if ( -            hostname.endsWith(baseSiteName) && +            (hostname === baseSiteName || +              hostname.endsWith(`.${baseSiteName}`)) &&              baseSiteName.length > bestMatchLength            ) {              bestMatch = site;              bestMatchLength = baseSiteName.length; +            if (logging) console.log("Popup: Found wildcard match:", site);            } -        } else if (hostname === siteName || hostname === `www.${siteName}`) { -          // Exact match has priority -          bestMatch = site; -          break; -        } else if ( -          hostname.endsWith(siteName) && +        } +        // Last, check subdomain matches with proper domain boundary +        else if ( +          hostname !== siteName && +          hostname !== `www.${siteName}` && +          hostname.endsWith(`.${siteName}`) &&            siteName.length > bestMatchLength          ) {            bestMatch = site;            bestMatchLength = siteName.length; +          if (logging) console.log("Popup: Found subdomain match:", site);          }        }  | 
