-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement one-time code auto-fill and copy
- Loading branch information
Showing
8 changed files
with
310 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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 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,31 @@ | ||
import { fillLoginForm, getLoginForms } from "../utils/dom"; | ||
|
||
declare global { | ||
interface Window { | ||
iCPFillOneTimeCode: ( | ||
username: string, | ||
code: string, | ||
) => Promise<{ success: true; warnings: string[] }>; | ||
} | ||
} | ||
|
||
window.iCPFillOneTimeCode = async (username, code) => { | ||
const warnings: string[] = []; | ||
|
||
const forms = getLoginForms(); | ||
|
||
if (forms.length === 0) { | ||
throw new Error("AutoFill failed: no one-time code field on page"); | ||
} else if (forms.length > 1) { | ||
warnings.push( | ||
"Multiple one-time codes detected on page, only filling the last", | ||
); | ||
} | ||
|
||
warnings.push(...fillLoginForm(forms[forms.length - 1], username, code)); | ||
|
||
return { | ||
success: true, | ||
warnings, | ||
}; | ||
}; |
This file contains 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 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 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 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.