-
Notifications
You must be signed in to change notification settings - Fork 13
[CDX-381] Allow using localStorage for humanity check #431
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,15 +17,20 @@ const humanEvents = [ | |||||||
| ]; | ||||||||
|
|
||||||||
| class HumanityCheck { | ||||||||
| constructor() { | ||||||||
| constructor(options = {}) { | ||||||||
| const { humanityCheckLocation } = options; | ||||||||
|
|
||||||||
| // Resolve storage backend: 'local' for localStorage, 'session' (default) for sessionStorage | ||||||||
| this.store = humanityCheckLocation === 'local' ? store.local : store.session; | ||||||||
|
|
||||||||
| // Check if a human event has been performed in the past | ||||||||
| this.hasPerformedHumanEvent = this.getIsHumanFromSessionStorage(); | ||||||||
| this.hasPerformedHumanEvent = this.getIsHumanFromStorage(); | ||||||||
|
|
||||||||
| // Humanity proved, remove handlers | ||||||||
| const remove = () => { | ||||||||
| this.hasPerformedHumanEvent = true; | ||||||||
|
|
||||||||
| store.session.set(storageKey, true); | ||||||||
| this.store.set(storageKey, true); | ||||||||
| humanEvents.forEach((eventType) => { | ||||||||
| helpers.removeEventListener(eventType, remove, true); | ||||||||
| }); | ||||||||
|
|
@@ -39,7 +44,12 @@ class HumanityCheck { | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| // Helper function to grab the human variable from session storage | ||||||||
| // Helper function to grab the human variable from storage | ||||||||
| getIsHumanFromStorage() { | ||||||||
| return !!this.store.get(storageKey) || false; | ||||||||
|
||||||||
| return !!this.store.get(storageKey) || false; | |
| return Boolean(this.store.get(storageKey)); |
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getIsHumanFromSessionStorage() is now an alias for getIsHumanFromStorage() and may read from localStorage when humanityCheckLocation is 'local'. Consider clarifying this in the method comment (or renaming the alias comment) to avoid misleading callers who may expect it to always read sessionStorage.
| // Backward-compatible alias | |
| // Backward-compatible alias for getIsHumanFromStorage(); | |
| // may read from localStorage when humanityCheckLocation is 'local' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JSDoc for
humanityCheckLocationis typed as{string}, but the implementation and TypeScript types only support'session' | 'local'. Consider tightening the JSDoc type (e.g., a string-literal union) so generated docs better reflect the supported values.