From 21b85381f4185383f6c9f186350f28c8a09bd254 Mon Sep 17 00:00:00 2001 From: sameerasw Date: Mon, 14 Apr 2025 23:03:03 +0530 Subject: Fixes for #10, removed the useles inject-css.js in favor of the background.js --- popup/popup.js | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'popup') 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); } } -- cgit v1.2.3