-
-
Notifications
You must be signed in to change notification settings - Fork 405
add fuzzy search, copy button, and bulk operations #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
levouinse
wants to merge
4
commits into
Moustachauve:master
Choose a base branch
from
levouinse:pr1722026
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /** | ||
| * Enhanced search functionality with fuzzy matching for cookies. | ||
| */ | ||
| export class CookieSearch { | ||
| /** | ||
| * Performs fuzzy search on cookie name. | ||
| * @param {string} searchTerm The term to search for. | ||
| * @param {string} cookieName The cookie name to match against. | ||
| * @return {number} Score between 0-1, where higher means better match. | ||
| */ | ||
| static fuzzyMatch(searchTerm, cookieName) { | ||
| searchTerm = searchTerm.toLowerCase(); | ||
| cookieName = cookieName.toLowerCase(); | ||
|
|
||
| // Exact match gets highest score | ||
| if (cookieName === searchTerm) { | ||
| return 1; | ||
| } | ||
|
|
||
| // Contains match gets high score | ||
| if (cookieName.includes(searchTerm)) { | ||
| return 0.8; | ||
| } | ||
|
|
||
| // Fuzzy match - check if all characters appear in order | ||
| let score = 0; | ||
| let termIndex = 0; | ||
|
|
||
| for ( | ||
| let i = 0; | ||
| i < cookieName.length && termIndex < searchTerm.length; | ||
| i++ | ||
| ) { | ||
| if (cookieName[i] === searchTerm[termIndex]) { | ||
| score += 1; | ||
| termIndex++; | ||
| } | ||
| } | ||
|
|
||
| // If we matched all characters, return proportional score | ||
| if (termIndex === searchTerm.length) { | ||
| return (score / cookieName.length) * 0.6; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * Search cookies with multiple criteria. | ||
| * @param {Array} cookies Array of cookie objects to search. | ||
| * @param {string} searchTerm The search term. | ||
| * @param {object} options Search options. | ||
| * @return {Array} Filtered and sorted cookies. | ||
| */ | ||
| static search(cookies, searchTerm, options = {}) { | ||
| const { | ||
| searchInValue = false, | ||
| searchInDomain = false, | ||
| minScore = 0.3, | ||
| } = options; | ||
|
|
||
| if (!searchTerm) { | ||
| return cookies; | ||
| } | ||
|
|
||
| const results = []; | ||
|
|
||
| for (const cookie of cookies) { | ||
| let maxScore = this.fuzzyMatch(searchTerm, cookie.name); | ||
|
|
||
| if (searchInValue && cookie.value) { | ||
| maxScore = Math.max( | ||
| maxScore, | ||
| this.fuzzyMatch(searchTerm, cookie.value) * 0.7 | ||
| ); | ||
| } | ||
|
|
||
| if (searchInDomain && cookie.domain) { | ||
| maxScore = Math.max( | ||
| maxScore, | ||
| this.fuzzyMatch(searchTerm, cookie.domain) * 0.5 | ||
| ); | ||
| } | ||
|
|
||
| if (maxScore >= minScore) { | ||
| results.push({ cookie, score: maxScore }); | ||
| } | ||
| } | ||
|
|
||
| return results.sort((a, b) => b.score - a.score).map(r => r.cookie); | ||
| } | ||
|
|
||
| /** | ||
| * Highlight matching parts in text. | ||
| * @param {string} text The text to highlight. | ||
| * @param {string} searchTerm The term to highlight. | ||
| * @return {string} HTML with highlighted matches. | ||
| */ | ||
| static highlight(text, searchTerm) { | ||
| if (!searchTerm) { | ||
| return text; | ||
| } | ||
|
|
||
| const safeText = text | ||
| .toString() | ||
| .replace(/&/g, '&') | ||
| .replace(/</g, '<') | ||
| .replace(/>/g, '>'); | ||
| const regex = new RegExp(`(${this.escapeRegex(searchTerm)})`, 'gi'); | ||
| return safeText.replace(regex, '<mark>$1</mark>'); | ||
| } | ||
|
|
||
| /** | ||
| * Escapes special regex characters. | ||
| * @param {string} string The string to escape. | ||
| * @return {string} Escaped string. | ||
| */ | ||
| static escapeRegex(string) { | ||
| return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.